Search in sources :

Example 36 with KVEntry

use of com.alipay.sofa.jraft.rhea.storage.KVEntry in project sofa-jraft by sofastack.

the class DefaultRheaIterator method hasNext.

@Override
public synchronized boolean hasNext() {
    if (this.buf.isEmpty()) {
        while (this.endKey == null || BytesUtil.compare(this.cursorKey, this.endKey) < 0) {
            final List<KVEntry> kvEntries = this.rheaKVStore.singleRegionScan(this.cursorKey, this.endKey, this.bufSize, this.readOnlySafe, this.returnValue);
            if (kvEntries.isEmpty()) {
                // cursorKey jump to next region's startKey
                this.cursorKey = this.pdClient.findStartKeyOfNextRegion(this.cursorKey, false);
                if (cursorKey == null) {
                    // current is the last region
                    break;
                }
            } else {
                final KVEntry last = kvEntries.get(kvEntries.size() - 1);
                // cursorKey++
                this.cursorKey = BytesUtil.nextBytes(last.getKey());
                this.buf.addAll(kvEntries);
                break;
            }
        }
        return !this.buf.isEmpty();
    }
    return true;
}
Also used : KVEntry(com.alipay.sofa.jraft.rhea.storage.KVEntry)

Aggregations

KVEntry (com.alipay.sofa.jraft.rhea.storage.KVEntry)36 List (java.util.List)17 Test (org.junit.Test)14 Status (com.alipay.sofa.jraft.Status)8 Region (com.alipay.sofa.jraft.rhea.metadata.Region)8 KVStoreClosure (com.alipay.sofa.jraft.rhea.storage.KVStoreClosure)8 RawKVStore (com.alipay.sofa.jraft.rhea.storage.RawKVStore)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RouteTable (com.alipay.sofa.jraft.RouteTable)6 PeerId (com.alipay.sofa.jraft.entity.PeerId)6 DescriberManager (com.alipay.sofa.jraft.rhea.DescriberManager)6 FollowerStateListener (com.alipay.sofa.jraft.rhea.FollowerStateListener)6 JRaftHelper (com.alipay.sofa.jraft.rhea.JRaftHelper)6 LeaderStateListener (com.alipay.sofa.jraft.rhea.LeaderStateListener)6 RegionEngine (com.alipay.sofa.jraft.rhea.RegionEngine)6 StateListener (com.alipay.sofa.jraft.rhea.StateListener)6 StateListenerContainer (com.alipay.sofa.jraft.rhea.StateListenerContainer)6 StoreEngine (com.alipay.sofa.jraft.rhea.StoreEngine)6 FailoverClosure (com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure)6 ListRetryCallable (com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable)6