Search in sources :

Example 1 with TiSession

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

Example 2 with TiSession

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();
}
Also used : RegionTask(com.pingcap.tikv.util.RangeSplitter.RegionTask) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) ArrayList(java.util.ArrayList) TiSession(com.pingcap.tikv.TiSession) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) NoSuchElementException(java.util.NoSuchElementException) Handle(com.pingcap.tikv.key.Handle)

Aggregations

TiSession (com.pingcap.tikv.TiSession)2 BytePairWrapper (com.pingcap.tikv.BytePairWrapper)1 TwoPhaseCommitter (com.pingcap.tikv.TwoPhaseCommitter)1 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 Handle (com.pingcap.tikv.key.Handle)1 RegionTask (com.pingcap.tikv.util.RangeSplitter.RegionTask)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1