From 1118222b3d3decf649e125900b1e20954d0f7444 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Tue, 26 Oct 2021 22:51:49 -0400 Subject: [PATCH] Make revision numbers 64 bit to match proto spec (#96) * Make Response::index() 64 bit * make compact_revision 64 bit * Make input revision params 64 bit * make Transaction mod revision 64 bit * Make Value created and modified index 64 bit * Fix tests --- etcd/Client.hpp | 14 +++++++------- etcd/Response.hpp | 8 ++++---- etcd/SyncClient.hpp | 14 +++++++------- etcd/Value.hpp | 8 ++++---- etcd/v3/Action.hpp | 4 ++-- etcd/v3/Transaction.hpp | 2 +- etcd/v3/V3Response.hpp | 8 ++++---- src/Client.cpp | 14 +++++++------- src/Response.cpp | 4 ++-- src/SyncClient.cpp | 14 +++++++------- src/Value.cpp | 4 ++-- src/v3/Transaction.cpp | 2 +- src/v3/V3Response.cpp | 4 ++-- tst/EtcdSyncTest.cpp | 2 +- tst/EtcdTest.cpp | 4 ++-- 15 files changed, 53 insertions(+), 53 deletions(-) diff --git a/etcd/Client.hpp b/etcd/Client.hpp index eb5f143..60e4bad 100644 --- a/etcd/Client.hpp +++ b/etcd/Client.hpp @@ -223,7 +223,7 @@ namespace etcd * @param value is the new value to be set * @param old_index is the expected index of the original value */ - pplx::task modify_if(std::string const & key, std::string const & value, int old_index, int ttl = 0); + pplx::task modify_if(std::string const & key, std::string const & value, int64_t old_index, int ttl = 0); /** * Modifies an existing key only if it has a specific modification index value. Fails if the key @@ -233,7 +233,7 @@ namespace etcd * @param old_index is the expected index of the original value * @param leaseId is the lease attached to the key */ - pplx::task modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId); + pplx::task modify_if(std::string const & key, std::string const & value, int64_t old_index, int64_t leaseId); /** * Removes a single key. The key has to point to a plain, non directory entry. @@ -254,7 +254,7 @@ namespace etcd * @param key is the key to be deleted * @param old_index is the expected index of the existing value */ - pplx::task rm_if(std::string const & key, int old_index); + pplx::task rm_if(std::string const & key, int64_t old_index); /** * Gets a directory listing of the directory identified by the key. @@ -333,7 +333,7 @@ namespace etcd * @param fromIndex the first index we are interested in * @param recursive if true watch a whole subtree */ - pplx::task watch(std::string const & key, int fromIndex, bool recursive = false); + pplx::task watch(std::string const & key, int64_t fromIndex, bool recursive = false); /** * Watches for changes of a range of keys inside [key, range_end). @@ -362,7 +362,7 @@ namespace etcd * @param range_end is the end of key range to be removed. * @param fromIndex the first index we are interested in */ - pplx::task watch(std::string const & key, std::string const &range_end, int fromIndex); + pplx::task watch(std::string const & key, std::string const &range_end, int64_t fromIndex); /** * Grants a lease. @@ -450,7 +450,7 @@ namespace etcd * @param value is the new value to set. */ pplx::task proclaim(std::string const &name, int64_t lease_id, - std::string const &key, int revision, std::string const &value); + std::string const &key, int64_t revision, std::string const &value); /** * Get the current leader proclamation. @@ -497,7 +497,7 @@ namespace etcd * @param revision is the created revision of key-value returned by @campaign@ */ pplx::task resign(std::string const &name, int64_t lease_id, - std::string const &key, int revision); + std::string const &key, int64_t revision); private: #if defined(WITH_GRPC_CHANNEL_CLASS) diff --git a/etcd/Response.hpp b/etcd/Response.hpp index ad73262..656851b 100644 --- a/etcd/Response.hpp +++ b/etcd/Response.hpp @@ -98,7 +98,7 @@ namespace etcd /** * Returns the current index value of etcd */ - int index() const; + int64_t index() const; /** * Returns the value object of the response to a get/set/modify operation. @@ -134,7 +134,7 @@ namespace etcd * Returns the compact_revision if the response is a watch-cancelled revision. * `-1` means uninitialized (the response is not watch-cancelled) */ - int compact_revision() const; + int64_t compact_revision() const; /** * Returns the lock key. @@ -162,13 +162,13 @@ namespace etcd int _error_code; std::string _error_message; - int _index; + int64_t _index; std::string _action; Value _value; Value _prev_value; Values _values; Keys _keys; - int _compact_revision = -1; // for watch + int64_t _compact_revision = -1; // for watch std::string _lock_key; // for lock std::string _name; // for campaign (in v3election) std::vector _events; // for watch diff --git a/etcd/SyncClient.hpp b/etcd/SyncClient.hpp index e978464..50b3a1e 100644 --- a/etcd/SyncClient.hpp +++ b/etcd/SyncClient.hpp @@ -51,11 +51,11 @@ namespace etcd Response modify(std::string const & key, std::string const & value, int64_t leaseId); Response modify_if(std::string const & key, std::string const & value, std::string const & old_value, int ttl = 0); Response modify_if(std::string const & key, std::string const & value, std::string const & old_value, int64_t leaseId); - Response modify_if(std::string const & key, std::string const & value, int old_index, int ttl = 0); - Response modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId); + Response modify_if(std::string const & key, std::string const & value, int64_t old_index, int ttl = 0); + Response modify_if(std::string const & key, std::string const & value, int64_t old_index, int64_t leaseId); Response rm(std::string const & key); Response rm_if(std::string const & key, std::string const & old_value); - Response rm_if(std::string const & key, int old_index); + Response rm_if(std::string const & key, int64_t old_index); Response ls(std::string const & key); Response ls(std::string const & key, size_t const limit); Response ls(std::string const & key, std::string const &range_end); @@ -71,13 +71,13 @@ namespace etcd Response campaign(std::string const &name, int64_t lease_id, std::string const &value); Response proclaim(std::string const &name, int64_t lease_id, - std::string const &key, int revision, std::string const &value); + std::string const &key, int64_t revision, std::string const &value); Response leader(std::string const &name); std::unique_ptr observe(std::string const &name, std::function callback, const bool once = false); Response resign(std::string const &name, int64_t lease_id, - std::string const &key, int revision); + std::string const &key, int64_t revision); /** * Watches for changes of a key or a subtree. Please note that if you watch e.g. "/testdir" and @@ -97,8 +97,8 @@ namespace etcd * @param fromIndex the first index we are interested in * @param recursive if true watch a whole subtree */ - Response watch(std::string const & key, int fromIndex, bool recursive = false); - Response watch(std::string const & key, std::string const &range_end, int fromIndex); + Response watch(std::string const & key, int64_t fromIndex, bool recursive = false); + Response watch(std::string const & key, std::string const &range_end, int64_t fromIndex); protected: Client client; diff --git a/etcd/Value.hpp b/etcd/Value.hpp index a6ff6d8..ce13e94 100644 --- a/etcd/Value.hpp +++ b/etcd/Value.hpp @@ -48,12 +48,12 @@ namespace etcd /** * Returns the creation index of this value. */ - int created_index() const; + int64_t created_index() const; /** * Returns the last modification's index of this value. */ - int modified_index() const; + int64_t modified_index() const; /** * Returns the ttl of this value or 0 if ttl is not set @@ -76,8 +76,8 @@ namespace etcd std::string _key; bool dir; std::string value; - int created; - int modified; + int64_t created; + int64_t modified; int _ttl; int64_t leaseId; }; diff --git a/etcd/v3/Action.hpp b/etcd/v3/Action.hpp index 46c1785..9c99e41 100644 --- a/etcd/v3/Action.hpp +++ b/etcd/v3/Action.hpp @@ -30,8 +30,8 @@ namespace etcdv3 { ActionParameters(); bool withPrefix; - int revision; - int old_revision; + int64_t revision; + int64_t old_revision; int64_t lease_id = 0; // no lease int ttl; int limit; diff --git a/etcd/v3/Transaction.hpp b/etcd/v3/Transaction.hpp index 8dd4218..22f6539 100644 --- a/etcd/v3/Transaction.hpp +++ b/etcd/v3/Transaction.hpp @@ -36,7 +36,7 @@ public: void init_compare(CompareResult, CompareTarget); void init_compare(std::string const &old_value, CompareResult, CompareTarget); - void init_compare(int old_value, CompareResult, CompareTarget); + void init_compare(int64_t old_value, CompareResult, CompareTarget); void setup_basic_failure_operation(std::string const &key); void setup_set_failure_operation(std::string const &key, std::string const &value, int64_t leaseid); diff --git a/etcd/v3/V3Response.hpp b/etcd/v3/V3Response.hpp index b722922..58d65fa 100644 --- a/etcd/v3/V3Response.hpp +++ b/etcd/v3/V3Response.hpp @@ -18,14 +18,14 @@ namespace etcdv3 std::string const & get_error_message() const; void set_error_message(std::string msg); void set_action(std::string action); - int get_index() const; + int64_t get_index() const; std::string const & get_action() const; std::vector const & get_values() const; std::vector const & get_prev_values() const; etcdv3::KeyValue const & get_value() const; etcdv3::KeyValue const & get_prev_value() const; bool has_values() const; - int get_compact_revision() const; + int64_t get_compact_revision() const; void set_lock_key(std::string const &key); std::string const &get_lock_key() const; void set_name(std::string const &name); @@ -33,14 +33,14 @@ namespace etcdv3 std::vector const & get_events() const; protected: int error_code; - int index; + int64_t index; std::string error_message; std::string action; etcdv3::KeyValue value; etcdv3::KeyValue prev_value; std::vector values; std::vector prev_values; - int compact_revision = -1; + int64_t compact_revision = -1; std::string lock_key; // for lock std::string name; // for campaign (in v3election) std::vector events; // for watch diff --git a/src/Client.cpp b/src/Client.cpp index 7f5a700..15a20ef 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -472,7 +472,7 @@ pplx::task etcd::Client::modify_if(std::string const & key, std: return Response::create(call); } -pplx::task etcd::Client::modify_if(std::string const & key, std::string const & value, int old_index, int ttl) +pplx::task etcd::Client::modify_if(std::string const & key, std::string const & value, int64_t old_index, int ttl) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); @@ -500,7 +500,7 @@ pplx::task etcd::Client::modify_if(std::string const & key, std: return Response::create(call); } -pplx::task etcd::Client::modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseid) +pplx::task etcd::Client::modify_if(std::string const & key, std::string const & value, int64_t old_index, int64_t leaseid) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); @@ -538,7 +538,7 @@ pplx::task etcd::Client::rm_if(std::string const & key, std::str return Response::create(call); } -pplx::task etcd::Client::rm_if(std::string const & key, int old_index) +pplx::task etcd::Client::rm_if(std::string const & key, int64_t old_index) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); @@ -640,7 +640,7 @@ pplx::task etcd::Client::watch(std::string const & key, bool rec return Response::create(call); } -pplx::task etcd::Client::watch(std::string const & key, int fromIndex, bool recursive) +pplx::task etcd::Client::watch(std::string const & key, int64_t fromIndex, bool recursive) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); @@ -669,7 +669,7 @@ pplx::task etcd::Client::watch(std::string const & key, std::str return Response::create(call); } -pplx::task etcd::Client::watch(std::string const & key, std::string const & range_end, int fromIndex) +pplx::task etcd::Client::watch(std::string const & key, std::string const & range_end, int64_t fromIndex) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); @@ -835,7 +835,7 @@ pplx::task etcd::Client::campaign( pplx::task etcd::Client::proclaim( std::string const &name, int64_t lease_id, - std::string const &key, int revision, std::string const &value) { + std::string const &key, int64_t revision, std::string const &value) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); params.name = name; @@ -871,7 +871,7 @@ std::unique_ptr etcd::Client::observe( } pplx::task etcd::Client::resign( - std::string const &name, int64_t lease_id, std::string const &key, int revision) { + std::string const &name, int64_t lease_id, std::string const &key, int64_t revision) { etcdv3::ActionParameters params; params.auth_token.assign(this->auth_token); params.name = name; diff --git a/src/Response.cpp b/src/Response.cpp index 8b6a996..376d563 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -60,7 +60,7 @@ std::string const & etcd::Response::error_message() const return _error_message; } -int etcd::Response::index() const +int64_t etcd::Response::index() const { return _index; } @@ -110,7 +110,7 @@ std::string const & etcd::Response::key(int index) const return _keys[index]; } -int etcd::Response::compact_revision() const +int64_t etcd::Response::compact_revision() const { return _compact_revision; } diff --git a/src/SyncClient.cpp b/src/SyncClient.cpp index 55c60e3..cd068c3 100644 --- a/src/SyncClient.cpp +++ b/src/SyncClient.cpp @@ -78,12 +78,12 @@ etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string CHECK_EXCEPTIONS(client.modify_if(key, value, old_value, leaseId).get()); } -etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int old_index, int ttl) +etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int64_t old_index, int ttl) { CHECK_EXCEPTIONS(client.modify_if(key, value, old_index, ttl).get()); } -etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId) +etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int64_t old_index, int64_t leaseId) { CHECK_EXCEPTIONS(client.modify_if(key, value, old_index, leaseId).get()); } @@ -98,7 +98,7 @@ etcd::Response etcd::SyncClient::rm_if(std::string const & key, std::string cons CHECK_EXCEPTIONS(client.rm_if(key, old_value).get()); } -etcd::Response etcd::SyncClient::rm_if(std::string const & key, int old_index) +etcd::Response etcd::SyncClient::rm_if(std::string const & key, int64_t old_index) { CHECK_EXCEPTIONS(client.rm_if(key, old_index).get()); } @@ -161,7 +161,7 @@ etcd::Response etcd::SyncClient::campaign(std::string const &name, int64_t lease } etcd::Response etcd::SyncClient::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) { CHECK_EXCEPTIONS(client.proclaim(name, lease_id, key, revision, value).get()); @@ -180,7 +180,7 @@ std::unique_ptr etcd::SyncClient::observe( } etcd::Response etcd::SyncClient::resign(std::string const &name, int64_t lease_id, - std::string const &key, int revision) + std::string const &key, int64_t revision) { CHECK_EXCEPTIONS(client.resign(name, lease_id, key, revision).get()); } @@ -190,7 +190,7 @@ etcd::Response etcd::SyncClient::watch(std::string const & key, bool recursive) CHECK_EXCEPTIONS(client.watch(key, recursive).get()); } -etcd::Response etcd::SyncClient::watch(std::string const & key, int fromIndex, bool recursive) +etcd::Response etcd::SyncClient::watch(std::string const & key, int64_t fromIndex, bool recursive) { CHECK_EXCEPTIONS(client.watch(key, fromIndex, recursive).get()); } @@ -205,7 +205,7 @@ etcd::Response etcd::SyncClient::watch(std::string const & key, std::string cons CHECK_EXCEPTIONS(client.watch(key, range_end).get()); } -etcd::Response etcd::SyncClient::watch(std::string const & key, std::string const &range_end, int fromIndex) +etcd::Response etcd::SyncClient::watch(std::string const & key, std::string const &range_end, int64_t fromIndex) { CHECK_EXCEPTIONS(client.watch(key, range_end, fromIndex).get()); } diff --git a/src/Value.cpp b/src/Value.cpp index 8e58b73..41a5cde 100644 --- a/src/Value.cpp +++ b/src/Value.cpp @@ -50,12 +50,12 @@ std::string const & etcd::Value::as_string() const return value; } -int etcd::Value::created_index() const +int64_t etcd::Value::created_index() const { return created; } -int etcd::Value::modified_index() const +int64_t etcd::Value::modified_index() const { return modified; } diff --git a/src/v3/Transaction.cpp b/src/v3/Transaction.cpp index 7596708..a57eb3b 100644 --- a/src/v3/Transaction.cpp +++ b/src/v3/Transaction.cpp @@ -54,7 +54,7 @@ void etcdv3::Transaction::init_compare(std::string const& old_value, CompareResu compare->set_value(old_value); } -void etcdv3::Transaction::init_compare(int old_index, CompareResult result, CompareTarget target){ +void etcdv3::Transaction::init_compare(int64_t old_index, CompareResult result, CompareTarget target){ Compare* compare = txn_request->add_compare(); compare->set_result(detail::to_compare_result(result)); compare->set_target(detail::to_compare_target(target)); diff --git a/src/v3/V3Response.cpp b/src/v3/V3Response.cpp index 8db5a39..1d9312b 100644 --- a/src/v3/V3Response.cpp +++ b/src/v3/V3Response.cpp @@ -11,7 +11,7 @@ void etcdv3::V3Response::set_error_message(std::string msg) error_message = msg; } -int etcdv3::V3Response::get_index() const +int64_t etcdv3::V3Response::get_index() const { return index; } @@ -61,7 +61,7 @@ bool etcdv3::V3Response::has_values() const return values.size() > 0; } -int etcdv3::V3Response::get_compact_revision() const +int64_t etcdv3::V3Response::get_compact_revision() const { return compact_revision; } diff --git a/tst/EtcdSyncTest.cpp b/tst/EtcdSyncTest.cpp index 0f77d4b..e2787c1 100644 --- a/tst/EtcdSyncTest.cpp +++ b/tst/EtcdSyncTest.cpp @@ -158,7 +158,7 @@ TEST_CASE("watch changes in the past") { etcd::SyncClient etcd(etcd_uri); - int index = etcd.set("/test/key1", "42").index(); + auto 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 7e84f98..5810d51 100644 --- a/tst/EtcdTest.cpp +++ b/tst/EtcdTest.cpp @@ -375,13 +375,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()); - int index = etcd.set("/test/key1", "42").get().index(); + auto 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(); - int head_index = etcd.head().get().index(); + auto head_index = etcd.head().get().index(); CHECK(index + 3 == head_index); etcd::Response res = etcd.watch("/test/key1", ++index).get();