gpt4 book ai didi

java - GAE 数据存储 : Entity deleted only after multiple calls to delete()

转载 作者:行者123 更新时间:2023-12-01 14:39:35 25 4
gpt4 key购买 nike

我正在使用 Eclipse 在本地计算机上处​​理 GAE 数据存储。我创建了两个 servlet - AddMovieDeleteMovie:

添加电影

Entity movie = new Entity("movie",System.currentTimeMillis());
movie.setProperty("name", "Hakeshset Beanan");
movie.setProperty("director", "Godard");
datastore.put(movie);

删除电影

Query q = new Query("movie");
PreparedQuery pq = datastore.prepare(q);
List<Entity> movies = Lists.newArrayList(pq.asIterable());
response.put("numMoviesFound", String.valueOf(movies.size()));

for (Entity movie : movies) {
Key key = movie.getKey();
datastore.delete(key);
}

有趣的是,DeleteMovie servlet 并没有删除所有电影。连续调用返回 {"numMoviesFound":"15"},然后返回 {"numMoviesFound":"9"}{"numMoviesFound":"3"} 最后是 {"numMoviesFound":"3"}

为什么不立即从数据存储中删除所有电影?

更新:问题似乎只发生在本地 Eclipse 上,而不是 GAE 服务器上。

最佳答案

我认为您应该在一次事务中删除所有电影,这样可以确保更好的一致性。

说到一致性,你的问题就在这里:

Google App Engine's High Replication Datastore (HRD) provides high availability for your reads and writes by storing data synchronously in multiple data centers. However, the delay from the time a write is committed until it becomes visible in all data centers means that queries across multiple entity groups (non-ancestor queries) can only guarantee eventually consistent results. Consequently, the results of such queries may sometimes fail to reflect recent changes to the underlying data.

https://developers.google.com/appengine/docs/java/datastore/structuring_for_strong_consistency

关于java - GAE 数据存储 : Entity deleted only after multiple calls to delete(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16114667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com