From 1ba6f2c4d640cc72a8122d9a421a42250e871deb Mon Sep 17 00:00:00 2001 From: Tao He Date: Thu, 21 Apr 2022 17:57:19 +0800 Subject: [PATCH] Use int64_t for etcd revisions/indexes. Signed-off-by: Tao He --- README.md | 4 ++-- etcd/Watcher.hpp | 15 +++++++-------- src/Watcher.cpp | 12 ++++++------ tst/EtcdSyncTest.cpp | 4 ++-- tst/EtcdTest.cpp | 24 ++++++++++++------------ 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index af3b2e0..9b99284 100644 --- a/README.md +++ b/README.md @@ -687,7 +687,7 @@ pplx::task campaign(std::string const &name, int64_t lease_id, std::string const &value); pplx::task proclaim(std::string const &name, int64_t lease_id, - std::string const &key, , int revision, + std::string const &key, int64_t revision, std::string const &value); pplx::task leader(std::string const &name); @@ -697,7 +697,7 @@ std::unique_ptr observe(std::string const &name, const bool once = false); pplx::task resign(std::string const &name, int64_t lease_id, - std::string const &key, int revision); + std::string const &key, int64_t revision); ``` for more details, please refer to [etcd/Client.hpp](./etcd/Client.hpp). diff --git a/etcd/Watcher.hpp b/etcd/Watcher.hpp index 0a7b3e5..9cac839 100644 --- a/etcd/Watcher.hpp +++ b/etcd/Watcher.hpp @@ -19,20 +19,20 @@ namespace etcd Watcher(Client const &client, std::string const & key, std::string const &range_end, std::function callback); - Watcher(Client const &client, std::string const & key, int fromIndex, + Watcher(Client const &client, std::string const & key, int64_t fromIndex, std::function callback, bool recursive=false); Watcher(Client const &client, std::string const & key, - std::string const &range_end, int fromIndex, + std::string const &range_end, int64_t fromIndex, std::function callback); Watcher(std::string const & address, std::string const & key, std::function callback, bool recursive=false); Watcher(std::string const & address, std::string const & key, std::string const &range_end, std::function callback); - Watcher(std::string const & address, std::string const & key, int fromIndex, + Watcher(std::string const & address, std::string const & key, int64_t fromIndex, std::function callback, bool recursive=false); Watcher(std::string const & address, std::string const & key, - std::string const &range_end, int fromIndex, + std::string const &range_end, int64_t fromIndex, std::function callback); Watcher(std::string const & address, std::string const & username, std::string const & password, @@ -46,12 +46,12 @@ namespace etcd int const auth_token_ttl = 300); Watcher(std::string const & address, std::string const & username, std::string const & password, - std::string const & key, int fromIndex, + std::string const & key, int64_t fromIndex, std::function callback, bool recursive=false, int const auth_token_ttl = 300); Watcher(std::string const & address, std::string const & username, std::string const & password, - std::string const & key, std::string const &range_end, int fromIndex, + std::string const & key, std::string const &range_end, int64_t fromIndex, std::function callback, int const auth_token_ttl = 300); @@ -90,7 +90,6 @@ namespace etcd std::string const & auth_token, std::function callback); - int index; std::function callback; std::function wait_callback; @@ -105,7 +104,7 @@ namespace etcd std::unique_ptr stubs; private: - int fromIndex; + int64_t fromIndex; bool recursive; std::atomic_bool cancelled; }; diff --git a/src/Watcher.cpp b/src/Watcher.cpp index c62efda..caf2337 100644 --- a/src/Watcher.cpp +++ b/src/Watcher.cpp @@ -23,7 +23,7 @@ etcd::Watcher::Watcher(Client const &client, std::string const & key, Watcher(client, key, range_end, -1, callback) { } -etcd::Watcher::Watcher(Client const &client, std::string const & key, int fromIndex, +etcd::Watcher::Watcher(Client const &client, std::string const & key, int64_t fromIndex, std::function callback, bool recursive): fromIndex(fromIndex), recursive(recursive) { stubs.reset(new EtcdServerStubs{}); @@ -32,7 +32,7 @@ etcd::Watcher::Watcher(Client const &client, std::string const & key, int fromIn } etcd::Watcher::Watcher(Client const &client, std::string const & key, - std::string const &range_end, int fromIndex, + std::string const &range_end, int64_t fromIndex, std::function callback): fromIndex(fromIndex), recursive(false) { stubs.reset(new EtcdServerStubs{}); @@ -51,13 +51,13 @@ etcd::Watcher::Watcher(std::string const & address, std::string const & key, Watcher(address, key, range_end, -1, callback) { } -etcd::Watcher::Watcher(std::string const & address, std::string const & key, int fromIndex, +etcd::Watcher::Watcher(std::string const & address, std::string const & key, int64_t fromIndex, std::function callback, bool recursive): Watcher(Client(address), key, fromIndex, callback, recursive) { } etcd::Watcher::Watcher(std::string const & address, std::string const & key, - std::string const & range_end, int fromIndex, + std::string const & range_end, int64_t fromIndex, std::function callback): Watcher(Client(address), key, range_end, fromIndex, callback) { } @@ -80,7 +80,7 @@ etcd::Watcher::Watcher(std::string const & address, etcd::Watcher::Watcher(std::string const & address, std::string const & username, std::string const & password, - std::string const & key, int fromIndex, + std::string const & key, int64_t fromIndex, std::function callback, bool recursive, int const auth_token_ttl): Watcher(Client(address, username, password, auth_token_ttl), key, fromIndex, callback, recursive) { @@ -88,7 +88,7 @@ etcd::Watcher::Watcher(std::string const & address, etcd::Watcher::Watcher(std::string const & address, std::string const & username, std::string const & password, - std::string const & key, std::string const & range_end, int fromIndex, + std::string const & key, std::string const & range_end, int64_t fromIndex, std::function callback, int const auth_token_ttl): Watcher(Client(address, username, password, auth_token_ttl), key, range_end, fromIndex, callback) { diff --git a/tst/EtcdSyncTest.cpp b/tst/EtcdSyncTest.cpp index e2787c1..4d6b13b 100644 --- a/tst/EtcdSyncTest.cpp +++ b/tst/EtcdSyncTest.cpp @@ -51,7 +51,7 @@ TEST_CASE("sync operations") // compare and swap etcd.set("/test/key1", "42"); - int index = etcd.modify_if("/test/key1", "43", "42").index(); + int64_t index = etcd.modify_if("/test/key1", "43", "42").index(); CHECK(etcd::ERROR_COMPARE_FAILED == etcd.modify_if("/test/key1", "44", "42").error_code()); REQUIRE(etcd.modify_if("/test/key1", "44", index).is_ok()); CHECK(etcd::ERROR_COMPARE_FAILED == etcd.modify_if("/test/key1", "45", index).error_code()); @@ -158,7 +158,7 @@ TEST_CASE("watch changes in the past") { etcd::SyncClient etcd(etcd_uri); - auto index = etcd.set("/test/key1", "42").index(); + int64_t index = etcd.set("/test/key1", "42").index(); etcd.set("/test/key1", "43"); etcd.set("/test/key1", "44"); diff --git a/tst/EtcdTest.cpp b/tst/EtcdTest.cpp index 84278d4..94b42a2 100644 --- a/tst/EtcdTest.cpp +++ b/tst/EtcdTest.cpp @@ -115,10 +115,10 @@ TEST_CASE("delete a value") CHECK(etcd::ERROR_KEY_NOT_FOUND == resp.error_code()); CHECK("Key not found" == resp.error_message()); - int index = etcd.get("/test/key1").get().index(); - int create_index = etcd.get("/test/key1").get().value().created_index(); - int modify_index = etcd.get("/test/key1").get().value().modified_index(); - int version = etcd.get("/test/key1").get().value().version(); + int64_t index = etcd.get("/test/key1").get().index(); + int64_t create_index = etcd.get("/test/key1").get().value().created_index(); + int64_t modify_index = etcd.get("/test/key1").get().value().modified_index(); + int64_t version = etcd.get("/test/key1").get().value().version(); std::cerr << "index = " << index << ", create index = " << create_index @@ -161,7 +161,7 @@ TEST_CASE("atomic compare-and-delete based on prevValue") TEST_CASE("atomic compare-and-delete based on prevIndex") { etcd::Client etcd("http://127.0.0.1:2379"); - int index = etcd.set("/test/key1", "42").get().index(); + int64_t index = etcd.set("/test/key1", "42").get().index(); etcd::Response res = etcd.rm_if("/test/key1", index - 1).get(); CHECK(!res.is_ok()); @@ -182,7 +182,7 @@ TEST_CASE("deep atomic compare-and-swap") // modify success etcd::Response res = etcd.modify_if("/test/key1", "43", "42").get(); - int index = res.index(); + int64_t index = res.index(); REQUIRE(res.is_ok()); CHECK("compareAndSwap" == res.action()); CHECK("43" == res.value().as_string()); @@ -379,13 +379,13 @@ TEST_CASE("watch changes in the past") { etcd::Client etcd("http://127.0.0.1:2379"); REQUIRE(0 == etcd.rmdir("/test", true).get().error_code()); - auto index = etcd.set("/test/key1", "42").get().index(); + int64_t index = etcd.set("/test/key1", "42").get().index(); etcd.set("/test/key1", "43").wait(); etcd.set("/test/key1", "44").wait(); etcd.set("/test/key1", "45").wait(); - auto head_index = etcd.head().get().index(); + int64_t head_index = etcd.head().get().index(); CHECK(index + 3 == head_index); etcd::Response res = etcd.watch("/test/key1", ++index).get(); @@ -406,14 +406,14 @@ TEST_CASE("watch range changes in the past") { etcd::Client etcd("http://127.0.0.1:2379"); REQUIRE(0 == etcd.rmdir("/test", true).get().error_code()); - int index = etcd.set("/test/key1", "42").get().index(); + int64_t index = etcd.set("/test/key1", "42").get().index(); etcd.set("/test/key1", "43").wait(); etcd.set("/test/key2", "44").wait(); etcd.set("/test/key3", "45").wait(); etcd.set("/test/key4", "45").wait(); - int head_index = etcd.head().get().index(); + int64_t head_index = etcd.head().get().index(); CHECK(index + 4 == head_index); etcd::Response res; @@ -431,7 +431,7 @@ TEST_CASE("watch range changes in the past") TEST_CASE("watch multiple keys and use promise") { etcd::Client etcd("http://127.0.0.1:2379"); - int start_index = etcd.set("/test/key1", "value1").get().index(); + int64_t start_index = etcd.set("/test/key1", "value1").get().index(); etcd.set("/test/key2", "value2").get(); pplx::task res = etcd.watch("/test", start_index, true) @@ -484,7 +484,7 @@ TEST_CASE("lease grant") CHECK("etcdserver: requested lease not found" == res.error_message()); res = etcd.modify_if("/test/key1", "45", "44", leaseid).get(); - int index = res.index(); + int64_t index = res.index(); REQUIRE(res.is_ok()); CHECK("compareAndSwap" == res.action()); CHECK("45" == res.value().as_string());