forked from vitalif/vitastor
Compare commits
1 Commits
master
...
etcd-hide-
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | dc75450f6d |
|
@ -34,26 +34,22 @@ struct alloc_osd_t
|
||||||
json11::Json::object {
|
json11::Json::object {
|
||||||
{ "target", "VERSION" },
|
{ "target", "VERSION" },
|
||||||
{ "version", 0 },
|
{ "version", 0 },
|
||||||
{ "key", base64_encode(
|
{ "key", "/osd/stats/"+std::to_string(new_id) }
|
||||||
parent->cli->st_cli.etcd_prefix+"/osd/stats/"+std::to_string(new_id)
|
|
||||||
) },
|
|
||||||
},
|
},
|
||||||
} },
|
} },
|
||||||
{ "success", json11::Json::array {
|
{ "success", json11::Json::array {
|
||||||
json11::Json::object {
|
json11::Json::object {
|
||||||
{ "request_put", json11::Json::object {
|
{ "request_put", json11::Json::object {
|
||||||
{ "key", base64_encode(
|
{ "key", "/osd/stats/"+std::to_string(new_id) }
|
||||||
parent->cli->st_cli.etcd_prefix+"/osd/stats/"+std::to_string(new_id)
|
{ "value", "{}" },
|
||||||
) },
|
|
||||||
{ "value", base64_encode("{}") },
|
|
||||||
} },
|
} },
|
||||||
},
|
},
|
||||||
} },
|
} },
|
||||||
{ "failure", json11::Json::array {
|
{ "failure", json11::Json::array {
|
||||||
json11::Json::object {
|
json11::Json::object {
|
||||||
{ "request_range", json11::Json::object {
|
{ "request_range", json11::Json::object {
|
||||||
{ "key", base64_encode(parent->cli->st_cli.etcd_prefix+"/osd/stats/") },
|
{ "key", "/osd/stats/" },
|
||||||
{ "range_end", base64_encode(parent->cli->st_cli.etcd_prefix+"/osd/stats0") },
|
{ "range_end", "/osd/stats0" },
|
||||||
{ "keys_only", true },
|
{ "keys_only", true },
|
||||||
} },
|
} },
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,8 +54,55 @@ etcd_kv_t etcd_state_client_t::parse_etcd_kv(const json11::Json & kv_json)
|
||||||
return kv;
|
return kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json11::Json etcd_state_client_t::etcd_encode_actions(const json11::Json & items)
|
||||||
|
{
|
||||||
|
json11::Json::array encoded;
|
||||||
|
for (auto & v: items.array_items())
|
||||||
|
{
|
||||||
|
json11::Json::object act;
|
||||||
|
for (auto & kv: v.object_items())
|
||||||
|
{
|
||||||
|
if (kv.first == "key" || kv.first == "range_end")
|
||||||
|
act[kv.first] = base64_encode(etcd_prefix+kv.second.string_value());
|
||||||
|
else if (kv.first == "value")
|
||||||
|
act[kv.first] = base64_encode(kv.second.is_string() ? kv.second.string_value() : kv.second.dump());
|
||||||
|
else
|
||||||
|
act[kv.first] = kv.second;
|
||||||
|
}
|
||||||
|
encoded.push_back(act);
|
||||||
|
}
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
|
|
||||||
void etcd_state_client_t::etcd_txn(json11::Json txn, int timeout, int retries, int interval, std::function<void(std::string, json11::Json)> callback)
|
void etcd_state_client_t::etcd_txn(json11::Json txn, int timeout, int retries, int interval, std::function<void(std::string, json11::Json)> callback)
|
||||||
{
|
{
|
||||||
|
// FIXME: json11 is immutable which is very inconvenient for such cases
|
||||||
|
json11::Json::object encoded;
|
||||||
|
if (txn["compare"].is_array())
|
||||||
|
{
|
||||||
|
json11::Json::array compare;
|
||||||
|
for (auto & v: txn["compare"].array_items())
|
||||||
|
{
|
||||||
|
json11::Json::object cmp;
|
||||||
|
for (auto & kv: v.object_items())
|
||||||
|
{
|
||||||
|
if (kv.first == "key")
|
||||||
|
cmp[kv.first] = base64_encode(etcd_prefix+kv.second.string_value());
|
||||||
|
else
|
||||||
|
cmp[kv.first] = kv.second;
|
||||||
|
}
|
||||||
|
compare.push_back(cmp);
|
||||||
|
}
|
||||||
|
encoded["compare"] = compare;
|
||||||
|
}
|
||||||
|
if (txn["failure"].is_array())
|
||||||
|
{
|
||||||
|
encoded["failure"] = etcd_encode_actions(txn["failure"]);
|
||||||
|
}
|
||||||
|
if (txn["success"].is_array())
|
||||||
|
{
|
||||||
|
encoded["success"] = etcd_encode_actions(txn["success"]);
|
||||||
|
}
|
||||||
etcd_call("/kv/txn", txn, timeout, retries, interval, callback);
|
etcd_call("/kv/txn", txn, timeout, retries, interval, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ protected:
|
||||||
bool rand_initialized = false;
|
bool rand_initialized = false;
|
||||||
void add_etcd_url(std::string);
|
void add_etcd_url(std::string);
|
||||||
void pick_next_etcd();
|
void pick_next_etcd();
|
||||||
|
json11::Json etcd_encode_actions(const json11::Json & items);
|
||||||
public:
|
public:
|
||||||
int etcd_keepalive_timeout = 30;
|
int etcd_keepalive_timeout = 30;
|
||||||
int etcd_ws_keepalive_interval = 30;
|
int etcd_ws_keepalive_interval = 30;
|
||||||
|
|
Loading…
Reference in New Issue