0

シャードされたカウンターを更新し、現在のカウントを返す必要があります。ここの例に従っています: https://developers.google.com/appengine/articles/sharding_counters

しかし、関数を介してトランザクション クエリを間接的に実行できるかどうかはわかりません。コード例は次のとおりです。

@db.transactional
def updateCounter(name):
    increment(name)
    get_count(name)

updateCounter(TOTAL_USERS)

これは現在のカウントをインクリメントして返しますか? または、データベースクエリが @db.transactional 関数の外にあるため、このアプローチは有効ではありませんか?

4

2 に答える 2

3

It's not possible* to get a transactional count of a sharded counter. The way sharded counters work is that you can update them in a transaction, and sum them up outside the transaction. Generally, this isn't an issue, because sharded counters are used where the count is updated many times a second; any transactional record of the count would be incorrect virtually the moment it was calculated.

* You could do this for up to 5 shards by using XG transactions, but it's a really bad idea. First, because of the reasons above, and second because it would impose the very same scalability issues you're trying to avoid by using sharded counters in the first place.

于 2012-05-22T06:46:29.263 に答える
0

トランザクション内では祖先クエリのみを使用できます。

get_count()非祖先クエリを使用するため、彼のコードはエラーを生成します。

于 2012-05-22T05:15:04.260 に答える