我在GAE中做了一個分片,只是有時在運行分片代碼後並不總是收到這條消息。Google App Engine數據存儲在Go中分片
(datastore_v3: BAD_REQUEST): Key path element must not be incomplete: [ResumeShard: ]
的代碼:
//Sharding
//Getting shard ID
rand.Seed(time.Now().UnixNano())
shardId := rand.Int63n(5)
resumeShardKey := datastore.NewKey(*pC, "ResumeShard", "", accountKey.IntID()+shardId, nil)
var resumeShard param.ResumeShard
if err = datastore.Get(*pC, resumeShardKey, &resumeShard); err != nil {
if err == datastore.ErrNoSuchEntity {
resumeShard = param.ResumeShard{}
resumeShard.Counter = 1
} else {
log.Println(err.Error())
}
} else {
resumeShard.Counter += 1
}
*pC
是指向從應用服務引擎的上下文。
accountKey
是每個用戶唯一的數據存儲Key
。
此錯誤隨機出現,如10次請求中的3次。我想知道,因爲我必須使用datastore.NewKey(..)
來創建分片密鑰,所以在調用Put(..)
後,如何獲得完整的密鑰,因爲這是分片並且GAE文檔中的示例也使用datastore.NewKey(..)
。
請建議。
你是一個真正的高手!非常感謝你的幫助! – Ook