开发者

entities not saved consistently with google datastore put

I have a very simple bit of code where I add some entities to the datastore.

    public final class storageUtil {

    private static DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();  

    public static Iterable<Entity> getAllEntities(String kind) {
        Query q = new Query(kind);
        PreparedQuery pq = datastore.prepare(q);
        return pq.asIterable();
    }

    public static void putEntity(Entity entity) {
        datastore.put(entity);
    }


}

If I call putEntity(myEntity) and then getAllEntities(myKind), the newly put entity, will only show up in the returned list 2 out of 3 times.

If I call datastore.get(开发者_运维百科myKey) right after put, it will always return the newly put entry.

Can any one give me a clue as to what is going on?


what kind of DataStore are you using? is this a high replication (default) datastore? are you testing against the real server (not the dev?) if so, this behaviour is somewhat expected because of the "eventually consistent" behavior.

Using the High Replication Datastore

is where you should start looking for the ways around this


Put your entities into the datastore using transactions, here you will find an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜