简体   繁体   English

具有多个服务器实例的AppEngine JDO丢失了通过密钥获取的实体的事务更新

[英]AppEngine JDO with multiple server instances loses transaction updates on entities fetched by key

I have a simple JDO test cases that consistently reproduces the problem: 1. two app engine tasks modify the same entity at about the same time 2. the tasks use a JDO transaction and use getObjectById to load the entity 3. have task A modify attribute A on the entity (assume A runs first) 4. have task B modify attribute B on the entity 我有一个简单的JDO测试用例,可以始终如一地重现该问题:1.两个App Engine任务大约在同一时间修改同一实体2.这些任务使用JDO事务并使用getObjectById加载实体3.具有任务A Modify属性实体上的A(假设A先运行)4.让任务B修改实体上的属性B

The problem arises when each of the two tasks executes on two different app engine instances. 当两个任务中的每个任务在两个不同的App Engine实例上执行时,就会出现问题。 In which case, I can see log messages that say task A has properly set attribute A to a non-null value and the transaction committed successfully. 在这种情况下,我可以看到日志消息,说明任务A已将属性A正确设置为非空值,并且事务已成功提交。 Then when task B runs on a separate instance it prints out that it does not see the changes that were made to attribute A by task A. Then task B logs that it has set attribute B to a non-null value and that its transaction completes successfully. 然后,当任务B在单独的实例上运行时,它打印出它看不到任务A对属性A所做的更改。然后任务B记录其已将属性B设置为非空值,并且其事务已完成成功。

Then, when I look in the datastore, attribute A is still null even though I can see log output that says it was set to non-null and the transaction was successful. 然后,当我查看数据存储区时,属性A仍为null,即使我可以看到日志输出表明该属性设置为非null且事务成功。 I would have expected one of two things: 1) when task B loads the entity the value of attribute A reflects that it has been set to a non-null value, or 2) task B loads stale data, but the commit fails with a "too much contention" error. 我本来期望以下两件事之一:1)当任务B加载实体时,属性A的值反映出它已被设置为非空值,或者2)任务B加载陈旧数据,但是提交失败,并且“争用太多”错误。 Either of those would be fine. 这些都可以。 (Note that occasionally I do see contention errors) (请注意,偶尔我会看到争用错误)

What am I missing? 我想念什么? It seems like there's some weird caching going on each instance. 似乎每个实例上都有一些奇怪的缓存。 I was pretty sure that loading an entity by its key within a transaction should reflect changes made to that entity even when those changes are made on a separate app engine instance. 我非常确定,即使在单独的App Engine实例上进行更改,在事务内通过其键加载实体也应反映对该实体所做的更改。 When writing a test case to reproduce this I created completely new entity classes and tasks to ensure no other code was somehow mucking things up and I reproduced it in production (the devserver gives slightly different behavior). 在编写测试用例以重现此情况时,我创建了全新的实体类和任务,以确保没有其他代码以某种方式破坏事物,并在生产中进行重现(devserver的行为略有不同)。

Any help is greatly appreciated! 任何帮助是极大的赞赏!

Seems like you are having a version issue. 好像您有版本问题。 Use @version this will automatically handle concurrent modification and will throw an optimistic lock exception. 使用@version可以自动处理并发修改,并抛出乐观锁异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM