更新到最新的GAE SDK版本1.9.26后,我的ShardedCounter代码停止工作并开始抛出:
java.lang.IllegalAccessError:尝试访问字段 com.google.appengine.repackaged.com.google.protobuf.AbstractMessage.memoizedSize 来自课堂 com.google.appengine.api.memcache.MemcacheServicePb $ MemcacheIncrementRequest
使用此代码:
public final void increment() {
// Find how many shards are in this counter.
int numShards = getShardCount();
// Choose the shard randomly from the available shards.
long shardNum = generator.nextInt(numShards);
Key shardKey = KeyFactory.createKey(kind, Long.toString(shardNum));
incrementPropertyTx(shardKey, CounterShard.COUNT, 1, 1);
mc.increment(kind, 1); // here
}