use of org.apache.ignite.internal.processors.query.UpdateSourceIterator in project ignite by apache.
the class IgniteH2Indexing method lockSelectedRows.
/**
* Locks rows from query cursor and returns the select result.
*
* @param cur Query cursor.
* @param cctx Cache context.
* @param pageSize Page size.
* @param timeout Timeout.
* @return Query results cursor.
*/
private Iterable<List<?>> lockSelectedRows(Iterable<List<?>> cur, GridCacheContext cctx, int pageSize, long timeout) {
assert cctx != null && cctx.mvccEnabled();
GridNearTxLocal tx = tx(ctx);
if (tx == null)
throw new IgniteSQLException("Failed to perform SELECT FOR UPDATE operation: transaction has already finished.");
Collection<List<?>> rowsCache = new ArrayList<>();
UpdateSourceIterator srcIt = new UpdateSourceIterator<KeyCacheObject>() {
private Iterator<List<?>> it = cur.iterator();
@Override
public EnlistOperation operation() {
return EnlistOperation.LOCK;
}
@Override
public boolean hasNextX() throws IgniteCheckedException {
return it.hasNext();
}
@Override
public KeyCacheObject nextX() throws IgniteCheckedException {
List<?> res = it.next();
// nextX() can be called from the different threads.
synchronized (rowsCache) {
rowsCache.add(res.subList(0, res.size() - 1));
if (rowsCache.size() > TX_SIZE_THRESHOLD) {
throw new IgniteCheckedException("Too many rows are locked by SELECT FOR UPDATE statement. " + "Consider locking fewer keys or increase the limit by setting a " + IGNITE_MVCC_TX_SIZE_CACHING_THRESHOLD + " system property. Current value is " + TX_SIZE_THRESHOLD + " rows.");
}
}
// The last column is expected to be a _key.
return cctx.toCacheKeyObject(res.get(res.size() - 1));
}
};
IgniteInternalFuture<Long> fut = tx.updateAsync(cctx, srcIt, pageSize, timeout, true);
try {
fut.get();
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
return rowsCache;
}
Aggregations