[英]How to ensure consistency with concurrent requests on Appengine entities with objectify?
在我的應用程序中,並發寫入發生在單個實體上,我注意到當發生3次以上的寫入/秒時,並非所有請求都被保留。 我正在從事務內部發出請求,但是我也沒有看到並發修改異常,我正在使用Objectify,因此未引發的異常可能是一種對象化的東西。 我知道對於並發寫入,我需要實現分片計數器,但是即使在那兒,我也要絕對確定如果刪除了寫入,則會得到有關它的通知。 在objectify中是否有等同於@version的方法,或者有什么方法可以在我的objectify實現中利用JPA / JDO中的@version機制? 這是保留我的實體的代碼:
while (true) {
try {
ofy().transact(new VoidWork() {
public void vrun() {
Venue_Model tnxVenue = ofy().load()
.type(Venue_Model.class).id(tnxVenueID)
.now();
tnxVenue.doStuff();
ofy().save().entities(tnxVenue).now();
}
});
//There are cases where this part of the code is reached but updates to the entity are not reflected in the data store viewer.
break;
} catch (ConcurrentModificationException e) {
// TODO Auto-generated catch block
if (retries == 0) {
e.printStackTrace();
+ person_ref.getKey() + e.toString());
break;
}
retries--;
} catch (Exception e) {
}
}
}
要檢查實體是否已保留,我只需在appengine儀表板上查看數據存儲查看器。
對於每個保留場地的請求,我還嘗試檢索n檢查該實體是否已保留,並且奇怪的是,在代碼運行期間它正確返回了-數據存儲查看器告訴了一個不同的故事:/代碼,以檢查數據是否正確保留了。
venue = ofy().load().type(Venue_Model.class).id(venue_id).now(); // search if person has checked in
if (!venue.allCheckins.contains(person_ref)) {
log.warning("attempt " + i + " for"
+ person_ref.getKey()); // Never entered :/
venue.doStuff(person_ref, subVenueName);
ofy().save().entities(venue).now();
}
您的代碼實際上不會在事務中執行任何數據存儲操作。 閱讀有關交易的Objectify文檔:
https://code.google.com/p/objectify-appengine/wiki/Transactions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.