QueryCursor无需事务模式就可以工作,即使直接声明事务也是如此。
我使用get和put方法并直接声明交易。它可以正常工作,即:
Ignite ignite = ...;
IgniteCache<String, String> cache = ...;
String key = ...;
String val= ...;
try (Transaction tx = ignite.transactions().txStart()) {
//get and put work within transaction
cache.get(key);
cache.put(key, val);
tx.commit();
}
但是当我使用query时,无需交易即可使用,即
Ignite ignite = ...;
IgniteCache<String, String> cache = ...;
ScanQuery<String, String> query = ...;
try (Transaction tx = ignite.transactions().txStart()) {
try (QueryCursor<Cache.Entry<String, String>> cursor = cache.query(query)) {
//query works without transaction
Iterator<Cache.Entry<String, String>> iter = cursor.iterator();
Cache.Entry<String, String> entry = iter.next();
}
tx.commit();
}
如何将 QueryCursor 绑定到事务?
答案 0 :(得分:2)
要使查询具有事务性,应使用TRANSACTIONAL_SNAPSHOT缓存原子性模式。从Ignite 2.7开始可用。
请参阅:https://apacheignite.readme.io/v2.7/docs/multiversion-concurrency-control