How many objects is “too many” for in a single transaction to Google's DataStore (High Replication)?

跟風遠走 提交于 2019-12-08 16:56:53

问题


I have following entity (non-relevant fields/methods are removed).

public class HitsStatsTotalDO
{
    @Id
    transient private Long targetId;

    public Key<HitsStatsTotalDO> createKey()
    {
        return new Key<HitsStatsTotalDO>(HitsStatsTotalDO.class, targetId);
    }
}

So... I'm trying to do batch get for 10 objects for which I construct keys using HitsStatsTotalDO.createKey(). I'm attempting to fetch them in transaction like this:

final List<Key<HitsStatsTotalDO>> keys = ....

// This is being called in transaction..
Map<Key<HitsStatsTotalDO>, HitsStatsTotalDO> result = DAOBase.ofy().get(keys);

which throws following exception:

java.lang.IllegalArgumentException: operating on too many entity groups in a single transaction.

Could you please elaborate how many is too many and how to fix it ? I couldn't find exact number in the documentation.

Thanks!


回答1:


The issue is not the number of entities you're retrieving, it's the fact that they're in multiple entity groups. Either do the fetch outside a transaction, or use an XG (Cross Group) transaction.




回答2:


In a single transaction you can operate entities in the same entity group.

What Can Be Done In a Transaction



来源:https://stackoverflow.com/questions/8251594/how-many-objects-is-too-many-for-in-a-single-transaction-to-googles-datastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!