made prev_values a vector.

This commit is contained in:
Arches 2016-06-15 16:56:08 +02:00 committed by arches
parent 88e5298f86
commit e5eafcf531
4 changed files with 21 additions and 49 deletions

View File

@ -41,7 +41,8 @@ etcd::Response::Response(const etcdv3::V3Response& reply)
_value = Value(reply.values[0]);
}
_prev_value = Value(reply.prev_value);
if(reply.prev_values.size() == 1)
_prev_value = Value(reply.prev_values[0]);
}

View File

@ -9,19 +9,13 @@ namespace etcdv3
class V3Response
{
public:
V3Response(): error_code(0), index(00)
{
prev_value.set_key("");
prev_value.set_create_revision(0);
prev_value.set_mod_revision(0);
prev_value.set_value("");
};
V3Response(): error_code(0), index(0) {};
int error_code;
std::string error_message;
int index;
std::string action;
std::vector<mvccpb::KeyValue> values;
mvccpb::KeyValue prev_value;
std::vector<mvccpb::KeyValue> prev_values;
};
}
#endif

View File

@ -7,10 +7,7 @@ etcdv3::AsyncRangeResponse::AsyncRangeResponse(const etcdv3::AsyncRangeResponse&
index = other.index;
action = other.action;
values = other.values;
prev_value.set_key(other.prev_value.key());
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());
prev_values = other.prev_values;
}
@ -21,10 +18,7 @@ etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::operator=(const etcdv3::
index = other.index;
action = other.action;
values = other.values;
prev_value.set_key(other.prev_value.key());
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());
prev_values = other.prev_values;
return *this;
}
@ -47,8 +41,6 @@ etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::ParseResponse()
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));
}
}

View File

@ -11,10 +11,7 @@ etcdv3::AsyncTxnResponse::AsyncTxnResponse(const etcdv3::AsyncTxnResponse& other
index = other.index;
action = other.action;
values = other.values;
prev_value.set_key(other.prev_value.key());
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());
prev_values = other.prev_values;
}
@ -25,10 +22,7 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::operator=(const etcdv3::Asyn
index = other.index;
action = other.action;
values = other.values;
prev_value.set_key(other.prev_value.key());
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());
prev_values = other.prev_values;
return *this;
}
@ -44,6 +38,7 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
else
{
std::vector<mvccpb::KeyValue> range_kvs;
std::vector<mvccpb::KeyValue> prev_range_kvs;
for(int index=0; index < reply.responses_size(); index++)
{
auto resp = reply.responses(index);
@ -58,7 +53,8 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
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())
@ -81,26 +77,15 @@ etcdv3::AsyncTxnResponse& etcdv3::AsyncTxnResponse::ParseResponse()
}
}
//find previous value of key
//retain only the last value gotten as the final value.
if(action == "set" || action == "create" || action == "compareAndSwap" || action == "update")
{
if(range_kvs.size() > 1)
{
prev_value = range_kvs.front();
values.push_back(range_kvs.back());
}
else
{
prev_values = prev_range_kvs;
values = range_kvs;
}
}
else
if(action == "delete")
{
values = range_kvs;
prev_values = values;
}
}
return *this;
}