Search in sources :

Example 1 with TwoPhaseCommitter

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) {
    }
}
Also used : BytePairWrapper(com.pingcap.tikv.BytePairWrapper) TwoPhaseCommitter(com.pingcap.tikv.TwoPhaseCommitter) TiSession(com.pingcap.tikv.TiSession)

Aggregations

BytePairWrapper (com.pingcap.tikv.BytePairWrapper)1 TiSession (com.pingcap.tikv.TiSession)1 TwoPhaseCommitter (com.pingcap.tikv.TwoPhaseCommitter)1