|
| 1 | +.. Copyright 2026-present Alibaba Inc. |
| 2 | +
|
| 3 | +.. Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +.. you may not use this file except in compliance with the License. |
| 5 | +.. You may obtain a copy of the License at |
| 6 | +
|
| 7 | +.. http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +.. Unless required by applicable law or agreed to in writing, software |
| 10 | +.. distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +.. See the License for the specific language governing permissions and |
| 13 | +.. limitations under the License. |
| 14 | +
|
| 15 | +Manifest Entry Cache |
| 16 | +==================== |
| 17 | + |
| 18 | +Overview |
| 19 | +-------- |
| 20 | + |
| 21 | +Large tables may contain many manifest entries, while a scan may only need a |
| 22 | +small subset after snapshot, partition, bucket, and statistics pruning. The |
| 23 | +snapshot-level manifest entry cache reduces repeated manifest decoding cost for |
| 24 | +successive full scans. |
| 25 | + |
| 26 | +The cache stores decoded and merged live manifest entries by snapshot for |
| 27 | +``ScanMode::ALL``. When a newer snapshot is scanned, paimon-cpp tries to build |
| 28 | +the target snapshot incrementally from the latest cached snapshot by reading |
| 29 | +only intermediate delta manifests. |
| 30 | + |
| 31 | +Request-specific filters are not stored in the cache. Partition, bucket, level, |
| 32 | +and predicate filters are still evaluated for each scan, so cached entries can |
| 33 | +be reused safely across different scan predicates. |
| 34 | + |
| 35 | +Configuration |
| 36 | +------------- |
| 37 | + |
| 38 | +Manifest entry caching reuses the cache instance provided by |
| 39 | +``ScanContextBuilder::WithCache()`` and stores the snapshot bundle under |
| 40 | +``CacheKind::SNAPSHOT_LIVE_MANIFEST``: |
| 41 | + |
| 42 | +.. code-block:: cpp |
| 43 | +
|
| 44 | + auto cache = std::make_shared<LruCache>(128 * 1024 * 1024); |
| 45 | + ScanContextBuilder context_builder(table_path); |
| 46 | + PAIMON_ASSIGN_OR_RAISE( |
| 47 | + std::unique_ptr<ScanContext> scan_context, |
| 48 | + context_builder |
| 49 | + .WithCache(cache) |
| 50 | + .AddOption(Options::SCAN_MANIFEST_ENTRY_CACHE_MAX_SNAPSHOTS, "3") |
| 51 | + .Finish()); |
| 52 | +
|
| 53 | +Cache entries are scoped by table path and branch, so they can be reused across |
| 54 | +newly created ``TableScan`` and ``FileStoreScan`` instances as long as they |
| 55 | +share the same cache object. |
| 56 | + |
| 57 | +``Options::SCAN_MANIFEST_ENTRY_CACHE_MAX_SNAPSHOTS`` controls how many snapshot |
| 58 | +results are retained per table and branch. Older snapshot entries are evicted |
| 59 | +first. The default value is ``0``, which disables the cache path. Set it to a |
| 60 | +positive value to enable the cache when ``ScanContextBuilder::WithCache()`` is |
| 61 | +also configured. |
| 62 | + |
| 63 | +If no cache is provided through ``ScanContextBuilder::WithCache()``, this |
| 64 | +optimization is skipped. The snapshot manifest entry cache shares the same |
| 65 | +``Cache`` interface with raw manifest and data-file footer caches, but it uses a |
| 66 | +dedicated ``CacheKind`` and a table/branch key instead of file byte ranges. |
| 67 | + |
| 68 | +Limitations |
| 69 | +----------- |
| 70 | + |
| 71 | +The cache is currently used only for ``ScanMode::ALL``. It is skipped for |
| 72 | +row-range scans because row-range pruning is applied at manifest-meta level. |
| 73 | + |
| 74 | +Metrics |
| 75 | +------- |
| 76 | + |
| 77 | +The scan metrics expose counters for the last scan: |
| 78 | + |
| 79 | +- ``lastManifestEntryCacheHit``: whether the target snapshot was served |
| 80 | + directly from the cache. |
| 81 | +- ``lastManifestEntryCacheIncrementalSnapshots``: how many intermediate |
| 82 | + snapshots were applied during incremental construction. |
| 83 | +- ``lastManifestEntryCacheLoadedManifests``: how many manifest files were |
| 84 | + loaded for the cache path. |
0 commit comments