MCPcopy Create free account
hub / github.com/e2wugui/zeze / walk

Method walk

ZezeJava/ZezeJava/src/main/java/Zeze/Dbh2/Dbh2.java:348–387  ·  view source on GitHub ↗
(Binary exclusiveStartKey, int proposeLimit, boolean desc, Binary prefix,
						 Action2<Binary, RocksIterator> fill)

Source from the content-addressed store, hash-verified

346 }
347
348 private boolean walk(Binary exclusiveStartKey, int proposeLimit, boolean desc, Binary prefix,
349 Action2<Binary, RocksIterator> fill) throws Exception {
350 if (desc) {
351 return walkDesc(exclusiveStartKey, proposeLimit, prefix, fill);
352 }
353
354 try (var it = stateMachine.getBucket().getData().iterator()) {
355 if (exclusiveStartKey.size() > 0)
356 it.seek(exclusiveStartKey.copyIf());
357 else
358 it.seekToFirst();
359
360 if (it.isValid()) {
361 var firstKey = it.key();
362 //noinspection EqualsBetweenInconvertibleTypes
363 if (exclusiveStartKey.size() > 0 && exclusiveStartKey.equals(firstKey))
364 it.next(); // skip exclusive key if need.
365 }
366
367 var count = proposeLimit;
368 var bucketEnd = false;
369 var keyLast = stateMachine.getBucket().getBucketMeta().getKeyLast();
370 for (; it.isValid() && count > 0; it.next(), count--) {
371 var key = new Binary(it.key());
372 if (keyLast.size() > 0 && key.compareTo(keyLast) >= 0) {
373 // 分桶中刚完成时,数据可能超过Last,此时应该检查出来并结束walk。
374 bucketEnd = true;
375 break;
376 }
377 // 如果使用了prefix,那么发现了新的prefix时,也表示搜索结束。
378 if (prefix.size() >= 0 && !key.startsWith(prefix)) {
379 bucketEnd = true;
380 break;
381 }
382 fill.run(key, it);
383 }
384
385 return bucketEnd || !it.isValid();
386 }
387 }
388
389 @Override
390 protected long ProcessWalkRequest(Walk r) throws Exception {

Callers 2

ProcessWalkRequestMethod · 0.95
ProcessWalkKeyRequestMethod · 0.95

Calls 15

walkDescMethod · 0.95
compareToMethod · 0.95
startsWithMethod · 0.95
getBucketMethod · 0.80
isValidMethod · 0.80
getBucketMetaMethod · 0.80
getDataMethod · 0.65
sizeMethod · 0.65
keyMethod · 0.65
equalsMethod · 0.65
nextMethod · 0.65
getKeyLastMethod · 0.65

Tested by

no test coverage detected