use of com.pingcap.tikv.TwoPhaseCommitter 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) {
}
}
Aggregations