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
This commit is contained in:
Matthew Fioravante 2021-10-26 22:51:49 -04:00 committed by GitHub
parent d29e05545d
commit 1118222b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 53 additions and 53 deletions

View File

@ -223,7 +223,7 @@ namespace etcd
* @param value is the new value to be set * @param value is the new value to be set
* @param old_index is the expected index of the original value * @param old_index is the expected index of the original value
*/ */
pplx::task<Response> modify_if(std::string const & key, std::string const & value, int old_index, int ttl = 0); pplx::task<Response> 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 * 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 old_index is the expected index of the original value
* @param leaseId is the lease attached to the key * @param leaseId is the lease attached to the key
*/ */
pplx::task<Response> modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId); pplx::task<Response> 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. * 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 key is the key to be deleted
* @param old_index is the expected index of the existing value * @param old_index is the expected index of the existing value
*/ */
pplx::task<Response> rm_if(std::string const & key, int old_index); pplx::task<Response> rm_if(std::string const & key, int64_t old_index);
/** /**
* Gets a directory listing of the directory identified by the key. * 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 fromIndex the first index we are interested in
* @param recursive if true watch a whole subtree * @param recursive if true watch a whole subtree
*/ */
pplx::task<Response> watch(std::string const & key, int fromIndex, bool recursive = false); pplx::task<Response> watch(std::string const & key, int64_t fromIndex, bool recursive = false);
/** /**
* Watches for changes of a range of keys inside [key, range_end). * 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 range_end is the end of key range to be removed.
* @param fromIndex the first index we are interested in * @param fromIndex the first index we are interested in
*/ */
pplx::task<Response> watch(std::string const & key, std::string const &range_end, int fromIndex); pplx::task<Response> watch(std::string const & key, std::string const &range_end, int64_t fromIndex);
/** /**
* Grants a lease. * Grants a lease.
@ -450,7 +450,7 @@ namespace etcd
* @param value is the new value to set. * @param value is the new value to set.
*/ */
pplx::task<Response> proclaim(std::string const &name, int64_t lease_id, pplx::task<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);
/** /**
* Get the current leader proclamation. * Get the current leader proclamation.
@ -497,7 +497,7 @@ namespace etcd
* @param revision is the created revision of key-value returned by @campaign@ * @param revision is the created revision of key-value returned by @campaign@
*/ */
pplx::task<Response> resign(std::string const &name, int64_t lease_id, pplx::task<Response> resign(std::string const &name, int64_t lease_id,
std::string const &key, int revision); std::string const &key, int64_t revision);
private: private:
#if defined(WITH_GRPC_CHANNEL_CLASS) #if defined(WITH_GRPC_CHANNEL_CLASS)

View File

@ -98,7 +98,7 @@ namespace etcd
/** /**
* Returns the current index value of 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. * 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. * Returns the compact_revision if the response is a watch-cancelled revision.
* `-1` means uninitialized (the response is not watch-cancelled) * `-1` means uninitialized (the response is not watch-cancelled)
*/ */
int compact_revision() const; int64_t compact_revision() const;
/** /**
* Returns the lock key. * Returns the lock key.
@ -162,13 +162,13 @@ namespace etcd
int _error_code; int _error_code;
std::string _error_message; std::string _error_message;
int _index; int64_t _index;
std::string _action; std::string _action;
Value _value; Value _value;
Value _prev_value; Value _prev_value;
Values _values; Values _values;
Keys _keys; Keys _keys;
int _compact_revision = -1; // for watch int64_t _compact_revision = -1; // for watch
std::string _lock_key; // for lock std::string _lock_key; // for lock
std::string _name; // for campaign (in v3election) std::string _name; // for campaign (in v3election)
std::vector<Event> _events; // for watch std::vector<Event> _events; // for watch

View File

@ -51,11 +51,11 @@ namespace etcd
Response modify(std::string const & key, std::string const & value, int64_t leaseId); 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, 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, 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, int64_t 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, int64_t leaseId);
Response rm(std::string const & key); 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, 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);
Response ls(std::string const & key, size_t const limit); Response ls(std::string const & key, size_t const limit);
Response ls(std::string const & key, std::string const &range_end); 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, Response campaign(std::string const &name, int64_t lease_id,
std::string const &value); std::string const &value);
Response proclaim(std::string const &name, int64_t lease_id, 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); Response leader(std::string const &name);
std::unique_ptr<Client::Observer> observe(std::string const &name, std::unique_ptr<Client::Observer> observe(std::string const &name,
std::function<void(Response)> callback, std::function<void(Response)> callback,
const bool once = false); const bool once = false);
Response resign(std::string const &name, int64_t lease_id, 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 * 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 fromIndex the first index we are interested in
* @param recursive if true watch a whole subtree * @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, int64_t fromIndex, bool recursive = false);
Response watch(std::string const & key, std::string const &range_end, int fromIndex); Response watch(std::string const & key, std::string const &range_end, int64_t fromIndex);
protected: protected:
Client client; Client client;

View File

@ -48,12 +48,12 @@ namespace etcd
/** /**
* Returns the creation index of this value. * 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. * 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 * Returns the ttl of this value or 0 if ttl is not set
@ -76,8 +76,8 @@ namespace etcd
std::string _key; std::string _key;
bool dir; bool dir;
std::string value; std::string value;
int created; int64_t created;
int modified; int64_t modified;
int _ttl; int _ttl;
int64_t leaseId; int64_t leaseId;
}; };

View File

@ -30,8 +30,8 @@ namespace etcdv3
{ {
ActionParameters(); ActionParameters();
bool withPrefix; bool withPrefix;
int revision; int64_t revision;
int old_revision; int64_t old_revision;
int64_t lease_id = 0; // no lease int64_t lease_id = 0; // no lease
int ttl; int ttl;
int limit; int limit;

View File

@ -36,7 +36,7 @@ public:
void init_compare(CompareResult, CompareTarget); void init_compare(CompareResult, CompareTarget);
void init_compare(std::string const &old_value, 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_basic_failure_operation(std::string const &key);
void setup_set_failure_operation(std::string const &key, std::string const &value, int64_t leaseid); void setup_set_failure_operation(std::string const &key, std::string const &value, int64_t leaseid);

View File

@ -18,14 +18,14 @@ namespace etcdv3
std::string const & get_error_message() const; std::string const & get_error_message() const;
void set_error_message(std::string msg); void set_error_message(std::string msg);
void set_action(std::string action); void set_action(std::string action);
int get_index() const; int64_t get_index() const;
std::string const & get_action() const; std::string const & get_action() const;
std::vector<etcdv3::KeyValue> const & get_values() const; std::vector<etcdv3::KeyValue> const & get_values() const;
std::vector<etcdv3::KeyValue> const & get_prev_values() const; std::vector<etcdv3::KeyValue> const & get_prev_values() const;
etcdv3::KeyValue const & get_value() const; etcdv3::KeyValue const & get_value() const;
etcdv3::KeyValue const & get_prev_value() const; etcdv3::KeyValue const & get_prev_value() const;
bool has_values() const; bool has_values() const;
int get_compact_revision() const; int64_t get_compact_revision() const;
void set_lock_key(std::string const &key); void set_lock_key(std::string const &key);
std::string const &get_lock_key() const; std::string const &get_lock_key() const;
void set_name(std::string const &name); void set_name(std::string const &name);
@ -33,14 +33,14 @@ namespace etcdv3
std::vector<mvccpb::Event> const & get_events() const; std::vector<mvccpb::Event> const & get_events() const;
protected: protected:
int error_code; int error_code;
int index; int64_t index;
std::string error_message; std::string error_message;
std::string action; std::string action;
etcdv3::KeyValue value; etcdv3::KeyValue value;
etcdv3::KeyValue prev_value; etcdv3::KeyValue prev_value;
std::vector<etcdv3::KeyValue> values; std::vector<etcdv3::KeyValue> values;
std::vector<etcdv3::KeyValue> prev_values; std::vector<etcdv3::KeyValue> prev_values;
int compact_revision = -1; int64_t compact_revision = -1;
std::string lock_key; // for lock std::string lock_key; // for lock
std::string name; // for campaign (in v3election) std::string name; // for campaign (in v3election)
std::vector<mvccpb::Event> events; // for watch std::vector<mvccpb::Event> events; // for watch

View File

@ -472,7 +472,7 @@ pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std:
return Response::create(call); return Response::create(call);
} }
pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std::string const & value, int old_index, int ttl) pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std::string const & value, int64_t old_index, int ttl)
{ {
etcdv3::ActionParameters params; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
@ -500,7 +500,7 @@ pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std:
return Response::create(call); return Response::create(call);
} }
pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseid) pplx::task<etcd::Response> etcd::Client::modify_if(std::string const & key, std::string const & value, int64_t old_index, int64_t leaseid)
{ {
etcdv3::ActionParameters params; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
@ -538,7 +538,7 @@ pplx::task<etcd::Response> etcd::Client::rm_if(std::string const & key, std::str
return Response::create(call); return Response::create(call);
} }
pplx::task<etcd::Response> etcd::Client::rm_if(std::string const & key, int old_index) pplx::task<etcd::Response> etcd::Client::rm_if(std::string const & key, int64_t old_index)
{ {
etcdv3::ActionParameters params; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
@ -640,7 +640,7 @@ pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, bool rec
return Response::create(call); return Response::create(call);
} }
pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, int fromIndex, bool recursive) pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, int64_t fromIndex, bool recursive)
{ {
etcdv3::ActionParameters params; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
@ -669,7 +669,7 @@ pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, std::str
return Response::create(call); return Response::create(call);
} }
pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, std::string const & range_end, int fromIndex) pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, std::string const & range_end, int64_t fromIndex)
{ {
etcdv3::ActionParameters params; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
@ -835,7 +835,7 @@ pplx::task<etcd::Response> etcd::Client::campaign(
pplx::task<etcd::Response> etcd::Client::proclaim( pplx::task<etcd::Response> etcd::Client::proclaim(
std::string const &name, int64_t lease_id, 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; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
params.name = name; params.name = name;
@ -871,7 +871,7 @@ std::unique_ptr<etcd::Client::Observer> etcd::Client::observe(
} }
pplx::task<etcd::Response> etcd::Client::resign( pplx::task<etcd::Response> 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; etcdv3::ActionParameters params;
params.auth_token.assign(this->auth_token); params.auth_token.assign(this->auth_token);
params.name = name; params.name = name;

View File

@ -60,7 +60,7 @@ std::string const & etcd::Response::error_message() const
return _error_message; return _error_message;
} }
int etcd::Response::index() const int64_t etcd::Response::index() const
{ {
return _index; return _index;
} }
@ -110,7 +110,7 @@ std::string const & etcd::Response::key(int index) const
return _keys[index]; return _keys[index];
} }
int etcd::Response::compact_revision() const int64_t etcd::Response::compact_revision() const
{ {
return _compact_revision; return _compact_revision;
} }

View File

@ -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()); 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()); 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()); 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()); 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()); 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, 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) std::string const &value)
{ {
CHECK_EXCEPTIONS(client.proclaim(name, lease_id, key, revision, value).get()); CHECK_EXCEPTIONS(client.proclaim(name, lease_id, key, revision, value).get());
@ -180,7 +180,7 @@ std::unique_ptr<etcd::Client::Observer> etcd::SyncClient::observe(
} }
etcd::Response etcd::SyncClient::resign(std::string const &name, int64_t lease_id, 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()); 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()); 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()); 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()); 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()); CHECK_EXCEPTIONS(client.watch(key, range_end, fromIndex).get());
} }

View File

@ -50,12 +50,12 @@ std::string const & etcd::Value::as_string() const
return value; return value;
} }
int etcd::Value::created_index() const int64_t etcd::Value::created_index() const
{ {
return created; return created;
} }
int etcd::Value::modified_index() const int64_t etcd::Value::modified_index() const
{ {
return modified; return modified;
} }

View File

@ -54,7 +54,7 @@ void etcdv3::Transaction::init_compare(std::string const& old_value, CompareResu
compare->set_value(old_value); 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* compare = txn_request->add_compare();
compare->set_result(detail::to_compare_result(result)); compare->set_result(detail::to_compare_result(result));
compare->set_target(detail::to_compare_target(target)); compare->set_target(detail::to_compare_target(target));

View File

@ -11,7 +11,7 @@ void etcdv3::V3Response::set_error_message(std::string msg)
error_message = msg; error_message = msg;
} }
int etcdv3::V3Response::get_index() const int64_t etcdv3::V3Response::get_index() const
{ {
return index; return index;
} }
@ -61,7 +61,7 @@ bool etcdv3::V3Response::has_values() const
return values.size() > 0; return values.size() > 0;
} }
int etcdv3::V3Response::get_compact_revision() const int64_t etcdv3::V3Response::get_compact_revision() const
{ {
return compact_revision; return compact_revision;
} }

View File

@ -158,7 +158,7 @@ TEST_CASE("watch changes in the past")
{ {
etcd::SyncClient etcd(etcd_uri); 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", "43");
etcd.set("/test/key1", "44"); etcd.set("/test/key1", "44");

View File

@ -375,13 +375,13 @@ TEST_CASE("watch changes in the past")
{ {
etcd::Client etcd("http://127.0.0.1:2379"); etcd::Client etcd("http://127.0.0.1:2379");
REQUIRE(0 == etcd.rmdir("/test", true).get().error_code()); 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", "43").wait();
etcd.set("/test/key1", "44").wait(); etcd.set("/test/key1", "44").wait();
etcd.set("/test/key1", "45").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); CHECK(index + 3 == head_index);
etcd::Response res = etcd.watch("/test/key1", ++index).get(); etcd::Response res = etcd.watch("/test/key1", ++index).get();