Use int64_t for etcd revisions/indexes.

Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
Tao He 2022-04-21 17:57:19 +08:00
parent 767f0b1c65
commit 1ba6f2c4d6
5 changed files with 29 additions and 30 deletions

View File

@ -687,7 +687,7 @@ pplx::task<Response> campaign(std::string const &name, int64_t lease_id,
std::string const &value); std::string const &value);
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 &key, int64_t revision,
std::string const &value); std::string const &value);
pplx::task<Response> leader(std::string const &name); pplx::task<Response> leader(std::string const &name);
@ -697,7 +697,7 @@ std::unique_ptr<Observer> observe(std::string const &name,
const bool once = false); const bool once = false);
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);
``` ```
for more details, please refer to [etcd/Client.hpp](./etcd/Client.hpp). for more details, please refer to [etcd/Client.hpp](./etcd/Client.hpp).

View File

@ -19,20 +19,20 @@ namespace etcd
Watcher(Client const &client, std::string const & key, Watcher(Client const &client, std::string const & key,
std::string const &range_end, std::string const &range_end,
std::function<void(Response)> callback); std::function<void(Response)> callback);
Watcher(Client const &client, std::string const & key, int fromIndex, Watcher(Client const &client, std::string const & key, int64_t fromIndex,
std::function<void(Response)> callback, bool recursive=false); std::function<void(Response)> callback, bool recursive=false);
Watcher(Client const &client, std::string const & key, 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<void(Response)> callback); std::function<void(Response)> callback);
Watcher(std::string const & address, std::string const & key, Watcher(std::string const & address, std::string const & key,
std::function<void(Response)> callback, bool recursive=false); std::function<void(Response)> callback, bool recursive=false);
Watcher(std::string const & address, std::string const & key, Watcher(std::string const & address, std::string const & key,
std::string const &range_end, std::string const &range_end,
std::function<void(Response)> callback); std::function<void(Response)> 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<void(Response)> callback, bool recursive=false); std::function<void(Response)> callback, bool recursive=false);
Watcher(std::string const & address, std::string const & key, 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<void(Response)> callback); std::function<void(Response)> callback);
Watcher(std::string const & address, Watcher(std::string const & address,
std::string const & username, std::string const & password, std::string const & username, std::string const & password,
@ -46,12 +46,12 @@ namespace etcd
int const auth_token_ttl = 300); int const auth_token_ttl = 300);
Watcher(std::string const & address, Watcher(std::string const & address,
std::string const & username, std::string const & password, std::string const & username, std::string const & password,
std::string const & key, int fromIndex, std::string const & key, int64_t fromIndex,
std::function<void(Response)> callback, bool recursive=false, std::function<void(Response)> callback, bool recursive=false,
int const auth_token_ttl = 300); int const auth_token_ttl = 300);
Watcher(std::string const & address, Watcher(std::string const & address,
std::string const & username, std::string const & password, 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<void(Response)> callback, std::function<void(Response)> callback,
int const auth_token_ttl = 300); int const auth_token_ttl = 300);
@ -90,7 +90,6 @@ namespace etcd
std::string const & auth_token, std::string const & auth_token,
std::function<void(Response)> callback); std::function<void(Response)> callback);
int index;
std::function<void(Response)> callback; std::function<void(Response)> callback;
std::function<bool(bool)> wait_callback; std::function<bool(bool)> wait_callback;
@ -105,7 +104,7 @@ namespace etcd
std::unique_ptr<EtcdServerStubs, EtcdServerStubsDeleter> stubs; std::unique_ptr<EtcdServerStubs, EtcdServerStubsDeleter> stubs;
private: private:
int fromIndex; int64_t fromIndex;
bool recursive; bool recursive;
std::atomic_bool cancelled; std::atomic_bool cancelled;
}; };

View File

@ -23,7 +23,7 @@ etcd::Watcher::Watcher(Client const &client, std::string const & key,
Watcher(client, key, range_end, -1, callback) { 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<void(Response)> callback, bool recursive): std::function<void(Response)> callback, bool recursive):
fromIndex(fromIndex), recursive(recursive) { fromIndex(fromIndex), recursive(recursive) {
stubs.reset(new EtcdServerStubs{}); 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, 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<void(Response)> callback): std::function<void(Response)> callback):
fromIndex(fromIndex), recursive(false) { fromIndex(fromIndex), recursive(false) {
stubs.reset(new EtcdServerStubs{}); 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) { 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<void(Response)> callback, bool recursive): std::function<void(Response)> callback, bool recursive):
Watcher(Client(address), key, fromIndex, callback, recursive) { Watcher(Client(address), key, fromIndex, callback, recursive) {
} }
etcd::Watcher::Watcher(std::string const & address, std::string const & key, 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<void(Response)> callback): std::function<void(Response)> callback):
Watcher(Client(address), key, range_end, fromIndex, 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, etcd::Watcher::Watcher(std::string const & address,
std::string const & username, std::string const & password, std::string const & username, std::string const & password,
std::string const & key, int fromIndex, std::string const & key, int64_t fromIndex,
std::function<void(Response)> callback, bool recursive, std::function<void(Response)> callback, bool recursive,
int const auth_token_ttl): int const auth_token_ttl):
Watcher(Client(address, username, password, auth_token_ttl), key, fromIndex, callback, recursive) { 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, etcd::Watcher::Watcher(std::string const & address,
std::string const & username, std::string const & password, 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<void(Response)> callback, std::function<void(Response)> callback,
int const auth_token_ttl): int const auth_token_ttl):
Watcher(Client(address, username, password, auth_token_ttl), key, range_end, fromIndex, callback) { Watcher(Client(address, username, password, auth_token_ttl), key, range_end, fromIndex, callback) {

View File

@ -51,7 +51,7 @@ TEST_CASE("sync operations")
// compare and swap // compare and swap
etcd.set("/test/key1", "42"); 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()); CHECK(etcd::ERROR_COMPARE_FAILED == etcd.modify_if("/test/key1", "44", "42").error_code());
REQUIRE(etcd.modify_if("/test/key1", "44", index).is_ok()); REQUIRE(etcd.modify_if("/test/key1", "44", index).is_ok());
CHECK(etcd::ERROR_COMPARE_FAILED == etcd.modify_if("/test/key1", "45", index).error_code()); 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); 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", "43");
etcd.set("/test/key1", "44"); etcd.set("/test/key1", "44");

View File

@ -115,10 +115,10 @@ TEST_CASE("delete a value")
CHECK(etcd::ERROR_KEY_NOT_FOUND == resp.error_code()); CHECK(etcd::ERROR_KEY_NOT_FOUND == resp.error_code());
CHECK("Key not found" == resp.error_message()); CHECK("Key not found" == resp.error_message());
int index = etcd.get("/test/key1").get().index(); int64_t index = etcd.get("/test/key1").get().index();
int create_index = etcd.get("/test/key1").get().value().created_index(); int64_t create_index = etcd.get("/test/key1").get().value().created_index();
int modify_index = etcd.get("/test/key1").get().value().modified_index(); int64_t modify_index = etcd.get("/test/key1").get().value().modified_index();
int version = etcd.get("/test/key1").get().value().version(); int64_t version = etcd.get("/test/key1").get().value().version();
std::cerr << "index = " << index std::cerr << "index = " << index
<< ", create index = " << create_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") TEST_CASE("atomic compare-and-delete based on prevIndex")
{ {
etcd::Client etcd("http://127.0.0.1:2379"); 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(); etcd::Response res = etcd.rm_if("/test/key1", index - 1).get();
CHECK(!res.is_ok()); CHECK(!res.is_ok());
@ -182,7 +182,7 @@ TEST_CASE("deep atomic compare-and-swap")
// modify success // modify success
etcd::Response res = etcd.modify_if("/test/key1", "43", "42").get(); etcd::Response res = etcd.modify_if("/test/key1", "43", "42").get();
int index = res.index(); int64_t index = res.index();
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
CHECK("compareAndSwap" == res.action()); CHECK("compareAndSwap" == res.action());
CHECK("43" == res.value().as_string()); 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"); 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());
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", "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();
auto head_index = etcd.head().get().index(); int64_t 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();
@ -406,14 +406,14 @@ TEST_CASE("watch range 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(); int64_t index = etcd.set("/test/key1", "42").get().index();
etcd.set("/test/key1", "43").wait(); etcd.set("/test/key1", "43").wait();
etcd.set("/test/key2", "44").wait(); etcd.set("/test/key2", "44").wait();
etcd.set("/test/key3", "45").wait(); etcd.set("/test/key3", "45").wait();
etcd.set("/test/key4", "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); CHECK(index + 4 == head_index);
etcd::Response res; etcd::Response res;
@ -431,7 +431,7 @@ TEST_CASE("watch range changes in the past")
TEST_CASE("watch multiple keys and use promise") { TEST_CASE("watch multiple keys and use promise") {
etcd::Client etcd("http://127.0.0.1:2379"); 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(); etcd.set("/test/key2", "value2").get();
pplx::task<size_t> res = etcd.watch("/test", start_index, true) pplx::task<size_t> res = etcd.watch("/test", start_index, true)
@ -484,7 +484,7 @@ TEST_CASE("lease grant")
CHECK("etcdserver: requested lease not found" == res.error_message()); CHECK("etcdserver: requested lease not found" == res.error_message());
res = etcd.modify_if("/test/key1", "45", "44", leaseid).get(); res = etcd.modify_if("/test/key1", "45", "44", leaseid).get();
int index = res.index(); int64_t index = res.index();
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
CHECK("compareAndSwap" == res.action()); CHECK("compareAndSwap" == res.action());
CHECK("45" == res.value().as_string()); CHECK("45" == res.value().as_string());