Skip to content

Commit

Permalink
RS-550: Add when condition to replication settings (#80)
Browse files Browse the repository at this point in the history
* add ReplicationSettings.when field

* update CHANGELOG

* bump version
  • Loading branch information
atimin authored Dec 31, 2024
1 parent 0d5ccf7 commit 6ce5e17
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/reduct/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ class IClient {
std::string dst_token; // Destination access token
std::vector<std::string>
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<double> each_s; // Replicate a record every S seconds if not empty
std::optional<uint64_t> each_n; // Replicate every Nth record if not empty
std::optional<std::string> when; // Replication condition

auto operator<=>(const ReplicationSettings&) const = default;
};
Expand Down
12 changes: 12 additions & 0 deletions src/reduct/internal/serialisation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -159,6 +167,10 @@ Result<IClient::FullReplicationInfo> 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"),
Expand Down
12 changes: 12 additions & 0 deletions tests/reduct/replication_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 6ce5e17

Please sign in to comment.