@@ -64,6 +64,8 @@ LanceSessionManager::Config load_lance_session_config() {
6464 .lance_data_cache_disk_capacity_bytes = config::lance_data_cache_disk_capacity_bytes,
6565 .lance_data_cache_read_block_size_bytes =
6666 config::lance_data_cache_read_block_size_bytes,
67+ .lance_data_cache_memory_capacity_bytes =
68+ config::lance_data_cache_memory_capacity_bytes,
6769 };
6870}
6971
@@ -159,8 +161,8 @@ LanceSessionManager::LanceSessionManager(Config config) : _config(std::move(conf
159161 << " , lance_data_cache_disk_capacity_bytes="
160162 << _config.lance_data_cache_disk_capacity_bytes
161163 << " , lance_data_cache_read_block_size_bytes="
162- << _config.lance_data_cache_read_block_size_bytes
163- << " , foyer_memory_capacity_bytes= " << _config.lance_data_cache_read_block_size_bytes ;
164+ << _config.lance_data_cache_read_block_size_bytes << " , foyer_memory_capacity_bytes= "
165+ << _config.resolved_data_cache_memory_capacity_bytes () ;
164166}
165167
166168LanceSessionManager::~LanceSessionManager () {
@@ -170,17 +172,20 @@ LanceSessionManager::~LanceSessionManager() {
170172
171173Status LanceSessionManager::_initialize () {
172174 if (_config.enable_lance_data_cache ) {
175+ if (_config.lance_data_cache_memory_capacity_bytes < 0 ) {
176+ return Status::InvalidArgument (
177+ " lance_data_cache_memory_capacity_bytes must be non-negative" );
178+ }
173179 // Treat the configured cache mode as a process-level requirement. If an enabled
174180 // data cache cannot initialize, report the failure instead of silently creating a
175181 // session without it. This keeps directory/configuration/device failures visible
176182 // to the operator. Disabling the cache is an explicit configuration change.
177183 const LanceDataCacheOptions data_cache_options {
178184 .directory = _config.lance_data_cache_path .c_str (),
179- // Foyer's HybridCache requires a memory tier. Keep it at the minimum useful
180- // capacity of exactly one range-cache block; WriteOnInsertion enqueues disk
181- // writes on insertion rather than waiting for memory-tier eviction.
185+ // Keep the historical one-block tier when the memory capacity is unset.
186+ // Its capacity is independent of the range-cache block granularity otherwise.
182187 .memory_capacity_bytes =
183- static_cast <uint64_t >(_config.lance_data_cache_read_block_size_bytes ),
188+ static_cast <uint64_t >(_config.resolved_data_cache_memory_capacity_bytes () ),
184189 .disk_capacity_bytes =
185190 static_cast <uint64_t >(_config.lance_data_cache_disk_capacity_bytes ),
186191 .read_block_size_bytes =
@@ -220,19 +225,37 @@ Status LanceSessionManager::open_dataset(const char* uri, const char* const* sto
220225 }
221226 *dataset = nullptr ;
222227
223- // Initialize lazily on the first dataset open, not at BE startup. A failed Status is a
228+ RETURN_IF_ERROR (_ensure_initialized ());
229+
230+ *dataset = lance_dataset_open_with_session (uri, storage_options, version, _session);
231+ if (*dataset == nullptr ) {
232+ return lance_error (" open Lance dataset with shared session" );
233+ }
234+ return Status::OK ();
235+ }
236+
237+ Status LanceSessionManager::_ensure_initialized () {
238+ // Initialize lazily on the first use, not at BE startup. A failed Status is a
224239 // normal return from this lambda, so call_once completes and retains that failure just
225240 // like a successful initialization. All subsequent readers receive the same copied
226241 // error; fixing the cache directory alone does not trigger another attempt. This is
227242 // intentional: repair the cache configuration/storage (or disable the data cache), then
228243 // restart the BE to recreate the process-wide manager and session.
229244 std::call_once (_initialize_once, [this ] { _initialize_status = _initialize (); });
230- RETURN_IF_ERROR (_initialize_status);
245+ return _initialize_status;
246+ }
231247
232- *dataset = lance_dataset_open_with_session (uri, storage_options, version, _session);
233- if (*dataset == nullptr ) {
234- return lance_error (" open Lance dataset with shared session" );
248+ Status LanceSessionManager::get_cache_statistics (CacheStatistics* statistics) {
249+ if (statistics == nullptr ) {
250+ return Status::InvalidArgument (" Lance cache statistics output must not be null" );
251+ }
252+ RETURN_IF_ERROR (_ensure_initialized ());
253+ LanceSessionCacheStats stats {};
254+ if (lance_session_get_cache_stats (_session, &stats) != 0 ) {
255+ return lance_error (" collect Lance session cache statistics" );
235256 }
257+ statistics->index_cache_misses = stats.index_cache_misses ;
258+ statistics->metadata_cache_misses = stats.metadata_cache_misses ;
236259 return Status::OK ();
237260}
238261
0 commit comments