made prev_values a vector.
This commit is contained in:
parent
88e5298f86
commit
e5eafcf531
|
|
@ -41,7 +41,8 @@ etcd::Response::Response(const etcdv3::V3Response& reply)
|
||||||
_value = Value(reply.values[0]);
|
_value = Value(reply.values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_prev_value = Value(reply.prev_value);
|
if(reply.prev_values.size() == 1)
|
||||||
|
_prev_value = Value(reply.prev_values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,13 @@ namespace etcdv3
|
||||||
class V3Response
|
class V3Response
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
V3Response(): error_code(0), index(00)
|
V3Response(): error_code(0), index(0) {};
|
||||||
{
|
|
||||||
prev_value.set_key("");
|
|
||||||
prev_value.set_create_revision(0);
|
|
||||||
prev_value.set_mod_revision(0);
|
|
||||||
prev_value.set_value("");
|
|
||||||
};
|
|
||||||
int error_code;
|
int error_code;
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
int index;
|
int index;
|
||||||
std::string action;
|
std::string action;
|
||||||
std::vector<mvccpb::KeyValue> values;
|
std::vector<mvccpb::KeyValue> values;
|
||||||
mvccpb::KeyValue prev_value;
|
std::vector<mvccpb::KeyValue> prev_values;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ etcdv3::AsyncRangeResponse::AsyncRangeResponse(const etcdv3::AsyncRangeResponse&
|
||||||
index = other.index;
|
index = other.index;
|
||||||
action = other.action;
|
action = other.action;
|
||||||
values = other.values;
|
values = other.values;
|
||||||
prev_value.set_key(other.prev_value.key());
|
prev_values = other.prev_values;
|
||||||
prev_value.set_value(other.prev_value.value());
|
|
||||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
|
||||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,10 +18,7 @@ etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::operator=(const etcdv3::
|
||||||
index = other.index;
|
index = other.index;
|
||||||
action = other.action;
|
action = other.action;
|
||||||
values = other.values;
|
values = other.values;
|
||||||
prev_value.set_key(other.prev_value.key());
|
prev_values = other.prev_values;
|
||||||
prev_value.set_value(other.prev_value.value());
|
|
||||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
|
||||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,8 +41,6 @@ etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::ParseResponse()
|
||||||
|
|
||||||
for(int index=0; index < reply.kvs_size(); index++)
|
for(int index=0; index < reply.kvs_size(); index++)
|
||||||
{
|
{
|
||||||
std::cout << "key: " << reply.kvs(index).key() << std::endl;
|
|
||||||
std::cout << "value: " << reply.kvs(index).value()<< std::endl;
|
|
||||||
values.push_back(reply.kvs(index));
|
values.push_back(reply.kvs(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,7 @@ etcdv3::AsyncTxnResponse::AsyncTxnResponse(const etcdv3::AsyncTxnResponse& other
|
||||||
index = other.index;
|
index = other.index;
|
||||||
action = other.action;
|
action = other.action;
|
||||||
values = other.values;
|
values = other.values;
|
||||||
prev_value.set_key(other.prev_value.key());
|
prev_values = other.prev_values;
|
||||||
prev_value.set_value(other.prev_value.value());
|
|
||||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
|
||||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,10 +22,7 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::operator=(const etcdv3::Asyn
|
||||||
index = other.index;
|
index = other.index;
|
||||||
action = other.action;
|
action = other.action;
|
||||||
values = other.values;
|
values = other.values;
|
||||||
prev_value.set_key(other.prev_value.key());
|
prev_values = other.prev_values;
|
||||||
prev_value.set_value(other.prev_value.value());
|
|
||||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
|
||||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,6 +38,7 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<mvccpb::KeyValue> range_kvs;
|
std::vector<mvccpb::KeyValue> range_kvs;
|
||||||
|
std::vector<mvccpb::KeyValue> prev_range_kvs;
|
||||||
for(int index=0; index < reply.responses_size(); index++)
|
for(int index=0; index < reply.responses_size(); index++)
|
||||||
{
|
{
|
||||||
auto resp = reply.responses(index);
|
auto resp = reply.responses(index);
|
||||||
|
|
@ -58,7 +53,8 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
|
||||||
|
|
||||||
if(!v3resp.values.empty())
|
if(!v3resp.values.empty())
|
||||||
{
|
{
|
||||||
range_kvs.insert(range_kvs.end(), v3resp.values.begin(), v3resp.values.end());
|
prev_range_kvs=range_kvs;
|
||||||
|
range_kvs = v3resp.values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(ResponseOp::ResponseCase::kResponseDeleteRange == resp.response_case())
|
else if(ResponseOp::ResponseCase::kResponseDeleteRange == resp.response_case())
|
||||||
|
|
@ -81,26 +77,15 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//find previous value of key
|
prev_values = prev_range_kvs;
|
||||||
//retain only the last value gotten as the final value.
|
|
||||||
if(action == "set" || action == "create" || action == "compareAndSwap" || action == "update")
|
values = range_kvs;
|
||||||
{
|
|
||||||
if(range_kvs.size() > 1)
|
if(action == "delete")
|
||||||
{
|
{
|
||||||
prev_value = range_kvs.front();
|
prev_values = values;
|
||||||
values.push_back(range_kvs.back());
|
}
|
||||||
}
|
|
||||||
else
|
}
|
||||||
{
|
|
||||||
values = range_kvs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
values = range_kvs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue