Skip to content

Snapshots feature refactor#292

Open
AnnaPaolaMusio wants to merge 9 commits into
eclipse-score:mainfrom
etas-contrib:snapshots-feature-refactor
Open

Snapshots feature refactor#292
AnnaPaolaMusio wants to merge 9 commits into
eclipse-score:mainfrom
etas-contrib:snapshots-feature-refactor

Conversation

@AnnaPaolaMusio

Copy link
Copy Markdown
Contributor

The C++ implementation of the KVS module has been modified in terms of snapshot behavior.

  1. Removal of snapshot_rotate
    The snapshot_rotate function has been completely removed from the C++ implementation. Snapshot management is no longer automatic and requires an explicit call to the snapshot_create() function.

  2. The flush() function no longer automatically creates snapshots.
    In the previous behavior (still valid for RUST) flush() persisted the data and called snapshot_rotate() to automatically create a new snapshot. Now flush() now only persists the current state of the KVS to disk.

  3. Implementation of snapshot_create API
    The new snapshot_create() function has been implemented, allowing for the explicit creation of snapshots in the first available slot.

  4. Implementation of snapshot_delete API
    The snapshot_delete() function has been implemented to explicitly remove a specific snapshots by ID.

  5. Update to snapshot_count and snapshot_restore.

  6. A new component requirement has been introduced, according to the new behaviour of the snapshot_create.

@github-actions

github-actions Bot commented May 26, 2026

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.4.2) and connecting to it...
INFO: Invocation ID: 4f4c2791-12c5-4a87-a6e8-c90c5d541fb4
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
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Analyzing: target //:license-check (4 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 (26 packages loaded, 10 targets configured)

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

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

Analyzing: target //:license-check (147 packages loaded, 5573 targets configured)

Analyzing: target //:license-check (150 packages loaded, 7955 targets configured)

Analyzing: target //:license-check (158 packages loaded, 8011 targets configured)

Analyzing: target //:license-check (158 packages loaded, 8011 targets configured)

Analyzing: target //:license-check (158 packages loaded, 8011 targets configured)

Analyzing: target //:license-check (162 packages loaded, 10023 targets configured)

Analyzing: target //:license-check (162 packages loaded, 10023 targets configured)

INFO: Analyzed target //:license-check (163 packages loaded, 10149 targets configured).
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] [Prepa] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar
[16 / 17] Building license.check.license_check.jar (); 0s disk-cache, multiplex-worker
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: 25.852s, Critical Path: 2.56s
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

@AnnaPaolaMusio AnnaPaolaMusio marked this pull request as ready for review May 27, 2026 11:43
Comment thread tests/test_cases/tests/test_cit_snapshots.py Outdated
Comment thread src/cpp/src/kvs.cpp
@@ -593,119 +593,141 @@ score::ResultBlank Kvs::flush()
result = score::MakeUnexpected(ErrorCode::JsonGeneratorError);
}
else

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.

Please use clang-format with config available in the repo for C++ files.

Comment thread src/cpp/src/kvs.cpp
result = write_json_data(buf);
}
{
/* Write JSON Data */

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.

Please add a comment here that it writes to a file with snapshot ID 0.
Add this information to flush method docs.

Comment thread src/cpp/src/kvs.cpp
size_t count = 0;
bool error = false;
for (size_t idx = 0; idx < KVS_MAX_SNAPSHOTS; ++idx)
for (size_t idx = 1; idx <= KVS_MAX_SNAPSHOTS; ++idx)

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.

Okay, so snapshot ID==0 is not considered snapshot? This might be fine, but consider documenting the approach to snapshot ID in score/kvs/docs/requirements/index.rst. It should be written somewhere that 0 is reserved for current storage, and snapshots are in <1; max snapshot> range.

Comment thread src/cpp/src/kvs.cpp
const score::filesystem::Path dst_json{filename_prefix.Native() + "_" + to_string(new_snapshot_id) + ".json"};
const score::filesystem::Path dst_hash{filename_prefix.Native() + "_" + to_string(new_snapshot_id) + ".hash"};

const auto copy_json_res = filesystem->standard->CopyFile(src_json, dst_json);

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.

This approach stores new snapshot based on snapshot 0 file. This can lead to surprising behavior if flush was not done prior to snapshot creation.
I'd consider storing current memory state as less surprising variant, but nonetheless this should be clearly stated.

Comment thread src/cpp/src/kvs.cpp
return count;
}

score::Result<std::size_t> Kvs::snapshot_create()

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.

Please rework the function to return quickly on error. This will reduce if-else pyramids occurring in the code, with easier tracking on what's the method result.

Comment thread src/cpp/src/kvs.cpp
}
else
{
if (snapshot_count_res.value() == 0 || snapshot_id.id >= snapshot_max_count())

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.

From previous methods I inferred that range is <1; max snapshot>, but this condition indicates that restoring for max snapshot is disallowed. Similar issue is observed in other methods.

Comment thread src/cpp/src/kvs.cpp
else if (snapshot_count_res.value() < snapshot_id.id)
else if (!json_exists_res.value())
{
logger->LogError() << "Snapshot JSON file does not exist: '" << json_path << "'";

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.

Please check if it prints correctly, without added whitespaces surrouding path. If so, consider reworking those logs to logger->LogError() << "Snapshot JSON file does not exist:" << json_path;

/* Check if files were created correctly */
EXPECT_TRUE(std::filesystem::exists(kvs_prefix + ".json"));
EXPECT_TRUE(std::filesystem::exists(kvs_prefix + ".hash"));
EXPECT_FALSE(std::filesystem::exists(filename_prefix + "_1.json"));

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.

Add a comment that having a rotated snapshot was previous expected behavior, or remove check for snapshot ID 1.

}


/* Crea snapshot non contigui e verifica che il conteggio sia corretto */

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.

Please replace non-english comments.

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.

3 participants