From 6ce5e179340199598085b22845cb08e0261d4435 Mon Sep 17 00:00:00 2001 From: Alexey Timin Date: Tue, 31 Dec 2024 07:05:20 +0100 Subject: [PATCH] RS-550: Add when condition to replication settings (#80) * add ReplicationSettings.when field * update CHANGELOG * bump version --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 6 +++++- CMakeLists.txt | 2 +- README.md | 2 +- conanfile.py | 2 +- src/reduct/client.h | 5 +++-- src/reduct/internal/serialisation.cc | 12 ++++++++++++ tests/reduct/replication_api_test.cc | 12 ++++++++++++ 8 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 000ab66..5d50575 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: - reductstore_version: "main" exclude_api_version_tag: "" - reductstore_version: "latest" - exclude_api_version_tag: "~[1_13]" + exclude_api_version_tag: "~[1_14]" - license_file: "" exclude_license_tag: "~[license]" diff --git a/CHANGELOG.md b/CHANGELOG.md index f52fb15..37a8090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- RS-550: Add when condition to replication settings, [PR-80](https://github.com/reductstore/reduct-cpp/pull/80) + ## [1.13.0] - 2024-12-04 -## Added +### Added - RS-543: Support conditional query, [PR-79](https://github.com/reductstore/reduct-cpp/pull/79) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0585097..f345bf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.18) set(MAJOR_VERSION 1) -set(MINOR_VERSION 13) +set(MINOR_VERSION 14) set(PATCH_VERSION 0) set(REDUCT_CPP_FULL_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}) diff --git a/README.md b/README.md index 99e6955..3a35816 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ in C++20. It allows developers to easily interact with the database from their C ## Features * Written in C++20 -* Support ReductStore [HTTP API v1.13](https://www.reduct.store/docs/next/http-api) +* Support ReductStore [HTTP API v1.14](https://www.reduct.store/docs/next/http-api) * Support HTTP and HTTPS protocols * Support Linux AMD64 and Windows diff --git a/conanfile.py b/conanfile.py index 37b7c86..067d289 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ class DriftFrameworkConan(ConanFile): name = "reduct-cpp" - version = "1.13.0" + version = "1.14.0" license = "MIT" author = "Alexey Timin" url = "https://github.com/reduct-storage/reduct-cpp" diff --git a/src/reduct/client.h b/src/reduct/client.h index fa59965..05aeec2 100644 --- a/src/reduct/client.h +++ b/src/reduct/client.h @@ -196,10 +196,11 @@ class IClient { std::string dst_token; // Destination access token std::vector entries; // Entries to replicate. If empty, all entries are replicated. Wildcards are supported. - IBucket::LabelMap include; // Labels to include - IBucket::LabelMap exclude; // Labels to exclude + [[deprecated("Use when instead")]] IBucket::LabelMap include; // Labels to include + [[deprecated("Use when instead")]] IBucket::LabelMap exclude; // Labels to exclude std::optional each_s; // Replicate a record every S seconds if not empty std::optional each_n; // Replicate every Nth record if not empty + std::optional when; // Replication condition auto operator<=>(const ReplicationSettings&) const = default; }; diff --git a/src/reduct/internal/serialisation.cc b/src/reduct/internal/serialisation.cc index 1e86e5d..699c125 100644 --- a/src/reduct/internal/serialisation.cc +++ b/src/reduct/internal/serialisation.cc @@ -127,6 +127,14 @@ nlohmann::json ReplicationSettingsToJsonString(IClient::ReplicationSettings sett json_data["each_n"] = *settings.each_n; } + if (settings.when) { + try { + json_data["when"] = nlohmann::json::parse(*settings.when); + } catch (const std::exception& ex) { + return {{}, Error{.code = -1, .message = ex.what()}}; + } + } + return json_data; } @@ -159,6 +167,10 @@ Result ParseFullReplicationInfo(const nlohmann::js info.settings.each_n = settings.at("each_n"); } + if (settings.contains("when") && !settings.at("when").is_null()) { + info.settings.when = settings.at("when").dump(); + } + auto diagnostics = data.at("diagnostics"); info.diagnostics = Diagnostics{.hourly = DiagnosticsItem{ .ok = diagnostics.at("hourly").at("ok"), diff --git a/tests/reduct/replication_api_test.cc b/tests/reduct/replication_api_test.cc index cb10be3..609099a 100644 --- a/tests/reduct/replication_api_test.cc +++ b/tests/reduct/replication_api_test.cc @@ -109,3 +109,15 @@ TEST_CASE("reduct::Client should set each_s and each_n settings", "[replication_ settings.dst_token = "***"; REQUIRE(replication.settings == settings); } + +TEST_CASE("reduct::Client should set when condition", "[replication_api][1_14]") { + Fixture ctx; + settings.when = R"({"&score":{"$gt":0}})"; + + auto err = ctx.client->CreateReplication("test_replication", settings); + REQUIRE(err == Error::kOk); + + auto [replication, err_2] = ctx.client->GetReplication("test_replication"); + REQUIRE(err_2 == Error::kOk); + REQUIRE(replication.settings.when == settings.when); +}