GAE:数据存储事务冲突。重试…频繁发生

问题描述 投票:0回答:1

我正在将GAE Python 2.7 Standard与数据存储区一起使用。

问题是数据存储区经常引发事务冲突。

我写了一个简单的测试代码。 (我知道这种代码不存在。它只是一个测试代码。)我只是在一个事务中多次更新一个实体。

我认为任何事情都不会发生冲突,因为我只是在更新同一计划实体。

但是查看记录,“事务冲突。正在重试...”发生了好几次。

数据存储区导致事务冲突的原因是什么?

from google.appengine.ext import db

# get any entity
schedule = Schedule.get('entity_key')

def _txn(schedule):
    schedule.save()
    schedule.save()
    schedule.save()
    schedule.save()
xg_on = db.create_transaction_options(xg=True)
for i in range(0, 100):
    logging.info(i)
    db.run_in_transaction_options(xg_on,
                                  _txn,
                                  schedule)
python-2.7 google-app-engine google-cloud-platform google-cloud-datastore
1个回答
0
投票

当您尝试每秒更新一个实体一次以上时,会发生此错误,这可能会导致延迟问题,超时和其他类型的错误。

您可以查看数据存储区here的最佳做法,并了解将来如何避免这种错误。

© www.soinside.com 2019 - 2024. All rights reserved.