(Binary exclusiveStartKey, int proposeLimit, boolean desc, Binary prefix, Action2<Binary, RocksIterator> fill)
| 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 { |
no test coverage detected