gae datastore get , return value is wrong..

326 views
Skip to first unread message

mani

unread,
Apr 22, 2012, 7:51:18 AM4/22/12
to golang-nuts
type FI struct {
Value int
}
var fi FI
const key=1024 // for example number key(this example use 1024)
// Filter[1024] is 32
for {
if e:=datastore.Get(c,datastore.NewKey(c,"Filter",int64(key),
0,nil),&fi);e!=nil{
if e!=datastore.ErrNoSuchEntity{
time.Sleep(300*time.Millisecond)
}else{
break
}
}else{
break
}
}
fmt.Write([]byte(strconv.Itoa(fi.Value)))
----------------------------------------------------------------------------------------------
upper case,, often fi.Value is not 32 ,, return 0... why?
Message has been deleted

Jesse McNelis

unread,
Apr 22, 2012, 8:47:48 AM4/22/12
to mani, golang-nuts
On Sun, Apr 22, 2012 at 9:51 PM, mani <inso...@gmail.com> wrote:
>     if e!=datastore.ErrNoSuchEntity{
>        time.Sleep(300*time.Millisecond)
>     }else{
>        break
>     }

So this will break the loop if e == datastore.ErrNoSuchEntity.
This fi.Value is going to be 0 because it didn't get a value set to it.
also, https://developers.google.com/appengine/docs/go/datastore/reference#Get
There are more error types you should be handling.

--
=====================
http://jessta.id.au

Nigel Tao

unread,
Apr 22, 2012, 8:00:21 PM4/22/12
to mani, golang-nuts
On 22 April 2012 21:51, mani <inso...@gmail.com> wrote:
> often fi.Value is not 32 ,, return 0... why?

You're not printing your error. What value of e do you get?

mani

unread,
Apr 23, 2012, 1:12:07 AM4/23/12
to golang-nuts
for explain, show up more simple source .
google database entity name is "Ent", key name is "Key", has already
32.
///////////////////////// sample.go
type Val struct {
int Value
}
retry:=""
var v Val
for {
v.Value=-1
for {
   if e:=datastore.Get(c,datastore.NewKey(c,"Ent","Key",
0,nil),&v);e==nil{
break
}else{
retry+=e.Error()+","
sleep(10)
}
}
fmt.Printf("%s, %d",retry, v.Value) //if process is true, v.Value
is 32 or include some retry message ,32
}
------
% go build sample.go; sample
32
Canceled, Deadline exceeded 32
-1 <-------- wtf? e is nil??
32
32

Nigel Tao

unread,
Apr 23, 2012, 7:30:02 AM4/23/12
to mani, golang-nuts
On 23 April 2012 15:12, mani <inso...@gmail.com> wrote:
> % go build sample.go; sample
> 32
> Canceled, Deadline exceeded 32
> -1                <-------- wtf? e is nil??
> 32
> 32

I'm confused. Your code looks like you're using Go on App Engine, but
Go on App Engine doesn't use "go build". Instead, you run
dev_appserver.py, which builds your app as necessary, when serving
HTTP requests.

Can you give more detail on how you're running this? It doesn't look
like the standard way of using the Go App Engine SDK (and its
datastore).
Message has been deleted

mani

unread,
Apr 23, 2012, 5:29:43 PM4/23/12
to golang-nuts
sorry Nigel..
for explain, if it run on standalone machine, not on google app
engine, thus show out..
ofcourse on google app engine, must deploy operation.
---
% go build sample.go; sample ~> % appcfg.py update .


On 4月23日, 午後8:30, Nigel Tao <nigel...@golang.org> wrote:

Nigel Tao

unread,
Apr 23, 2012, 7:55:50 PM4/23/12
to mani, golang-nuts
On 24 April 2012 07:29, mani <inso...@gmail.com> wrote:
> for explain, if it run on standalone machine, not on google app
> engine, thus show out..
> ofcourse on google app engine, must deploy operation.

Even before you deploy, the appengine/datastore package is designed
only to be run by dev_appserver.py, if run on your local machine. To
repeat: you should not be using "go build" at all, for Go on App
Engine.

It's not clear to me how you're running your program, but if you're
not using the datastore as intended, then I can't help you on why your
program doesn't work.

mani

unread,
Apr 24, 2012, 12:28:03 AM4/24/12
to golang-nuts
okok,sry, rewrite Question.
it has already google datastore entity is "Ent", key is "Key", and
that Value set to 32.

--- ./sample/sample.go
package sample
import ("appengine",... as so on ... }
const Count=100
type V struct{Value int}
func init(){http.HandleFunc("/",handler)}
func handler(w http.ResponseWriter,r *http.Request){
c:=apppengine.NewContext(r)
for i:=0;i<Count;i++{
for {
v:=new(V)
if e:=datastore.Get(c,datastore.NewKey(c,"Ent","Key",
0,nil),v);e==nil{
w.Write([]byte(v.Value+"\n"))
break
}
time.Sleep(300*Millisecond)
}
}
}

%dev_appserver.py
access http://xxx.appspot.com/ from browser
32
32
32
0 <= often return Value is zero Why? and, in this case, how to
teach true value get from datastore..
32
32
0
32
... continue until 100 times

Nigel Tao

unread,
Apr 24, 2012, 1:34:42 AM4/24/12
to mani, golang-nuts
Three points.

First, you're now ignoring your errors again. Please print any error
(possibly nil) that you get. Do something like

fmt.Fprintf(w, "v=%v, err=%v\n", v, e)


>        w.Write([]byte(v.Value+"\n"))

Second, this won't compile. v.Value is an int, and you can't add a
string to an int. If you're going to paste some code, please paste the
actual code that you use.


> %dev_appserver.py
> access http://xxx.appspot.com/ from browser

Third, when running dev_appserver.py, you need to browse to
http://localhost:8080/, not http://xxx.appspot.com/.

mani

unread,
Apr 24, 2012, 2:24:27 AM4/24/12
to golang-nuts
sorry tao..
i resolved.. i found another code mistake..
Reply all
Reply to author
Forward
Message has been deleted
0 new messages