Jea*_*ste 5 google-app-engine consistency objectify google-cloud-endpoints
我正在编写一个基于TodoMVC angularjs(http://todomvc.com/)的示例项目和一个带有Google App Engine Cloud Endpoint的后端api,我在从App Engine数据存储区获取todos监听时有一些一致性结果.
Todo对象使用objectify存储在App Engine数据存储区中.
Todo实体的编码如下:
@Entity
public class Todo {
@Id
private Long id;
private String title;
private boolean completed;
private Date lastEdit;
@Index
private Long userId;
public Todo() {
}
public Todo(String title, boolean completed) {
this.title = title;
this.completed = completed;
}
public Todo(Long id, String title, boolean completed) {
this.id = id;
this.title = title;
this.completed = completed;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isCompleted() {
return completed;
}
public void setCompleted(boolean completed) {
this.completed = completed;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Date getLastEdit() {
return lastEdit;
}
public void setLastEdit(Date lastEdit) {
this.lastEdit = lastEdit;
}
@Override
public String toString() {
return "Todo{" +
"id=" + id +
", title='" + title + '\'' +
", completed=" + completed +
", lastEdit=" + lastEdit +
", userId='" + userId + '\'' +
'}';
}
}
Run Code Online (Sandbox Code Playgroud)
在数据存储区中保存Todo的过程如下:
@ApiMethod(name = "create", httpMethod = ApiMethod.HttpMethod.POST)
public Todo create(User user, Todo todo) {
logger.info("creating todo : " + todo.toString());
todo.setUserId(new Long(user.getUserId()));
todo.setLastEdit(new Date());
ofy().save().entity(todo).now();
return todo;
}
@ApiMethod(name = "list", httpMethod = ApiMethod.HttpMethod.GET)
public Collection<Todo> getTodos(User user) {
logger.info("user:" + user);
List<Todo> todos = null;
if (user != null) {
todos = ofy().consistency(ReadPolicy.Consistency.STRONG).load().type(Todo.class).filter("userId", new Long(user.getUserId())).list();
}
logger.info("todos:" + todos);
return todos;
}
Run Code Online (Sandbox Code Playgroud)
假设我的列表中有4个待办事项,我将所有这些都设置为已完成(已完成= true).我在Datastore查看器中检查它们的状态:

然后,如果我在出现奇怪的一致性问题几秒后请求列表:
2014-03-08 13:08:43.326
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[
Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'},
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'},
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'},
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,对于所有待办事项,已完成的值未设置为true,并且它们的lastEdit日期甚至未更新
2分钟后的新请求:
2014-03-08 13:10:20.612
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[
Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'},
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'},
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'},
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]
Run Code Online (Sandbox Code Playgroud)
和17分钟后的新请求,仍然不是很好的价值观......
2014-03-08 13:27:07.918
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'},
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'},
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'},
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]
Run Code Online (Sandbox Code Playgroud)
有人知道为什么他们在使用Objectify查询的内容与使用GAE数据存储区查看器后台查看的内容之间存在这样的差异吗?是一致性问题吗?但如果是这样,为什么数据存储区查看器没有相同的问题?在查询时我是否滥用了客体化(如果我在运行过滤器时设置了ofy().一致性(ReadPolicy.Consistency.STRONG),那么该事件是什么?)
我没有很好地阅读 objectify 设置,并且错过了它告诉人们应该将以下内容添加到 web.xml 的部分
<filter>
<filter-name>ObjectifyFilter</filter-name>
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ObjectifyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
607 次 |
| 最近记录: |