MCPcopy Create free account
hub / github.com/Luce-Org/lucebox-hub / learn_layout

Method learn_layout

server/src/server/disk_prefix_cache.cpp:250–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250void DiskPrefixCache::learn_layout(int slot) {
251 if (disabled()) return;
252 if (layout_known_ && !layout_from_disk_) return; // already verified from live model
253
254 auto ref = backend_.snapshot_ref(slot);
255 if (!ref.ctx) return;
256
257 std::array<uint8_t, 16> prev_id = layout_id_;
258 bool had_disk_layout = layout_from_disk_;
259
260 compute_layout_id(ref.ctx);
261
262 if (had_disk_layout && std::memcmp(prev_id.data(), layout_id_.data(), 16) != 0) {
263 // Model layout differs from what was learned from disk files.
264 std::fprintf(stderr, "[disk-cache] layout mismatch: disk=%s model=%s — switching\n",
265 hex(prev_id.data(), 16).c_str(),
266 hex(layout_id_.data(), 16).c_str());
267 entries_.clear();
268 total_bytes_ = 0;
269 }
270
271 layout_known_ = true;
272 layout_from_disk_ = false;
273 layout_dir_ = config_.cache_dir + "/" + hex(layout_id_.data(), 16);
274 mkdir_p(layout_dir_);
275
276 std::fprintf(stderr, "[disk-cache] layout learned: %s\n",
277 hex(layout_id_.data(), 16).c_str());
278
279 // Scan for previously saved files matching this layout.
280 scan_directory();
281}
282
283// ─── Directory scanning ─────────────────────────────────────────────────
284

Callers 5

shutdownMethod · 0.80
runMethod · 0.80
worker_loopMethod · 0.80

Calls 5

hexFunction · 0.85
mkdir_pFunction · 0.85
clearMethod · 0.80
snapshot_refMethod · 0.45
dataMethod · 0.45