Skip to content

feat: allow KVS initialization from an explicit snapshot - #400

Open
atarekra wants to merge 1 commit into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:kvs-init-from-available-snapshot
Open

atarekra wants to merge 1 commit into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:kvs-init-from-available-snapshot

Conversation

@atarekra

@atarekra atarekra commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #237

The problem

The KVS keeps older snapshots so that a damaged current file isn't fatal, but
Kvs::open() only ever read snapshot 0 — the path was built with a hardcoded
"_0". If that file was missing or corrupt, the KVS refused to initialize even
when _1, _2 and _3 were present and intact. The recovery data existed and
nothing in the API could reach it.

The change

Kvs::open() takes an optional snapshot ID, defaulting to SnapshotId(0), and
KvsBuilder gets a matching snapshot_id() option:

auto kvs = KvsBuilder(InstanceId{1}).snapshot_id(SnapshotId(1)).build();

The default keeps every existing caller working unchanged.

I went with the first option from the issue (explicit builder parameter) rather
than the automatic retry loop, for the reason given in the issue itself: an
implicit fallback means the application starts up on data of unknown age with no
signal that anything went wrong. So a missing snapshot still fails, and
need_kvs_flag() decides whether that's an error or an empty KVS. There's a test
that pins this down deliberately, so the fallback doesn't get added later by
accident.

Tests

7 new tests: the default path still reads snapshot 0; opening from an explicit
snapshot works with _0 deleted; a missing snapshot fails rather than falling
back; Optional semantics apply to the requested ID; and the full recovery story
(open an older generation, flush, confirm it becomes the current KVS).

Notes

  • Rust has the same limitation — kvs_builder.rs also hardcodes SnapshotId(0).

Kvs::open() always read snapshot 0, so a KVS whose current generation
was missing or corrupted could not be initialized even when older
snapshots were present and intact. The redundancy the component pays
for was unreachable through the API.

Add an optional snapshot ID to Kvs::open() and a matching
KvsBuilder::snapshot_id() option, both defaulting to snapshot 0 so
existing callers are unaffected.

No implicit fallback is performed. If the requested snapshot is
unavailable the existing need_kvs flag decides between an error and an
empty KVS, so an application is never silently started on data of
unknown age.

Signed-off-by: atarekra <ahmed.tarek-ramadan@valeo.com>
@atarekra
atarekra deployed to workflow-approval August 31, 2026 07:44 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval August 31, 2026 07:44 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.6.0) and connecting to it...
INFO: Invocation ID: ac32901c-a4bf-48fd-80d2-3aef2e15a200
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 3 packages loaded
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)

Analyzing: target //:license-check (78 packages loaded, 10 targets configured)

Analyzing: target //:license-check (137 packages loaded, 832 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (160 packages loaded, 7490 targets configured)

Analyzing: target //:license-check (172 packages loaded, 9372 targets configured)

Analyzing: target //:license-check (172 packages loaded, 9372 targets configured)

Analyzing: target //:license-check (176 packages loaded, 11384 targets configured)

INFO: Analyzed target //:license-check (177 packages loaded, 11510 targets configured).
[13 / 17] JavaToolchainCompileClasses external/rules_java+/toolchains/platformclasspath_classes; 0s disk-cache, processwrapper-sandbox ... (2 actions running)
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 66 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
[15 / 17] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar; 0s disk-cache, processwrapper-sandbox
INFO: Found 1 target...
Target //:license.check.license_check up-to-date:
  bazel-bin/license.check.license_check
  bazel-bin/license.check.license_check.jar
INFO: Elapsed time: 28.238s, Critical Path: 2.15s
INFO: 17 processes: 12 internal, 4 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 17 total actions
INFO: Running command line: bazel-bin/license.check.license_check ./formatted.txt <args omitted>
usage: org.eclipse.dash.licenses.cli.Main [-batch <int>] [-cd <url>]
       [-confidence <int>] [-ef <url>] [-excludeSources <sources>] [-help] [-lic
       <url>] [-project <shortname>] [-repo <url>] [-review] [-summary <file>]
       [-timeout <seconds>] [-token <token>]

@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

Comment thread score/kvs/kvs.hpp
OpenNeedKvs need_kvs,
const std::string&& dir);
const std::string&& dir,
const SnapshotId& snapshot_id = SnapshotId(0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snapshotId already initialized on builder constructor , why do you reintialize it here again ? most probably to avoid updating testing.

This branch was successfully deployed

1 active deployment
workflow-approval — 3aaa7954 Deployed Aug 31, 2026 by atarekra via qnx-build (per-x86_64-qnx) / approval #249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvement: Make it possible to initialize KVS when snapshot with ID=0 is not available

2 participants