use of com.pingcap.tikv.TiSession in project tispark by pingcap.
the class RowIDAllocator method set.
// set key value pairs to tikv via two phase committer protocol.
private void set(@Nonnull List<BytePairWrapper> pairs, @Nonnull TiTimestamp timestamp) {
Iterator<BytePairWrapper> iterator = pairs.iterator();
if (!iterator.hasNext()) {
return;
}
TiSession session = TiSession.getInstance(conf);
TwoPhaseCommitter twoPhaseCommitter = new TwoPhaseCommitter(conf, timestamp.getVersion());
BytePairWrapper primaryPair = iterator.next();
twoPhaseCommitter.prewritePrimaryKey(ConcreteBackOffer.newCustomBackOff(BackOffer.PREWRITE_MAX_BACKOFF), primaryPair.getKey(), primaryPair.getValue());
if (iterator.hasNext()) {
twoPhaseCommitter.prewriteSecondaryKeys(primaryPair.getKey(), iterator, BackOffer.PREWRITE_MAX_BACKOFF);
}
twoPhaseCommitter.commitPrimaryKey(ConcreteBackOffer.newCustomBackOff(BackOffer.BATCH_COMMIT_BACKOFF), primaryPair.getKey(), session.getTimestamp().getVersion());
try {
twoPhaseCommitter.close();
} catch (Throwable ignored) {
}
}
use of com.pingcap.tikv.TiSession in project tispark by pingcap.
the class IndexScanIterator method hasNext.
@Override
public boolean hasNext() {
try {
if (rowIterator == null) {
TiSession session = snapshot.getSession();
while (handleIterator.hasNext()) {
List<Handle> handles = feedBatch();
batchCount++;
completionService.submit(() -> {
List<RegionTask> tasks = new ArrayList<>();
List<Long> ids = dagReq.getPrunedPhysicalIds();
tasks.addAll(RangeSplitter.newSplitter(session.getRegionManager()).splitAndSortHandlesByRegion(ids, handles));
return CoprocessorIterator.getRowIterator(dagReq, tasks, session);
});
}
while (batchCount > 0) {
rowIterator = completionService.take().get();
batchCount--;
if (rowIterator.hasNext()) {
return true;
}
}
}
if (rowIterator == null) {
return false;
}
} catch (Exception e) {
throw new TiClientInternalException("Error reading rows from handle", e);
}
return rowIterator.hasNext();
}
Aggregations