mirror of https://gitee.com/bigwinds/arangodb
Make _vpack of AgencyCommResult abstract.
This commit is contained in:
parent
cd39a884f9
commit
cae72d0d61
|
@ -67,7 +67,7 @@ void AgencyCallback::refetchAndUpdate() {
|
||||||
kv.erase(std::remove(kv.begin(), kv.end(), ""), kv.end());
|
kv.erase(std::remove(kv.begin(), kv.end(), ""), kv.end());
|
||||||
|
|
||||||
std::shared_ptr<VPackBuilder> newData = std::make_shared<VPackBuilder>();
|
std::shared_ptr<VPackBuilder> newData = std::make_shared<VPackBuilder>();
|
||||||
newData->add(result._vpack->slice()[0].get(kv));
|
newData->add(result.slice()[0].get(kv));
|
||||||
|
|
||||||
checkValue(newData);
|
checkValue(newData);
|
||||||
|
|
||||||
|
|
|
@ -453,6 +453,13 @@ VPackSlice AgencyCommResult::parse(std::string const& path) {
|
||||||
return _vpack->slice()[0].get(pv);
|
return _vpack->slice()[0].get(pv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// get results of query as slice
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
VPackSlice AgencyCommResult::slice() {
|
||||||
|
return _vpack->slice();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief the static global URL prefix
|
/// @brief the static global URL prefix
|
||||||
|
@ -1371,14 +1378,14 @@ AgencyCommResult AgencyComm::getValues2(std::string const& key) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
result._vpack = VPackParser::fromJson(result.body().c_str());
|
result.setVPack(VPackParser::fromJson(result.body().c_str()));
|
||||||
|
|
||||||
if (!result._vpack->slice().isArray()) {
|
if (!result.slice().isArray()) {
|
||||||
result._statusCode = 500;
|
result._statusCode = 500;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result._vpack->slice().length() != 1) {
|
if (result.slice().length() != 1) {
|
||||||
result._statusCode = 500;
|
result._statusCode = 500;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,13 +403,19 @@ struct AgencyCommResult {
|
||||||
bool parse(std::string const&, bool);
|
bool parse(std::string const&, bool);
|
||||||
VPackSlice parse(std::string const&);
|
VPackSlice parse(std::string const&);
|
||||||
|
|
||||||
|
VPackSlice slice();
|
||||||
|
void setVPack(std::shared_ptr<velocypack::Builder> vpack) {
|
||||||
|
_vpack = vpack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<velocypack::Builder> _vpack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string _location;
|
std::string _location;
|
||||||
std::string _message;
|
std::string _message;
|
||||||
std::string _body;
|
std::string _body;
|
||||||
std::string _realBody;
|
std::string _realBody;
|
||||||
std::shared_ptr<velocypack::Builder> _vpack;
|
|
||||||
|
|
||||||
std::map<std::string, AgencyCommResultEntry> _values;
|
std::map<std::string, AgencyCommResultEntry> _values;
|
||||||
uint64_t _index;
|
uint64_t _index;
|
||||||
|
|
|
@ -474,7 +474,7 @@ void ClusterInfo::loadPlan() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
VPackSlice slice = result._vpack->slice()[0].get(
|
VPackSlice slice = result.slice()[0].get(
|
||||||
std::vector<std::string>({AgencyComm::prefixStripped(), "Plan"}));
|
std::vector<std::string>({AgencyComm::prefixStripped(), "Plan"}));
|
||||||
auto planBuilder = std::make_shared<VPackBuilder>();
|
auto planBuilder = std::make_shared<VPackBuilder>();
|
||||||
planBuilder->add(slice);
|
planBuilder->add(slice);
|
||||||
|
@ -568,7 +568,7 @@ void ClusterInfo::loadCurrentDatabases() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice databases =
|
velocypack::Slice databases =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Current", "Databases"}));
|
{AgencyComm::prefixStripped(), "Current", "Databases"}));
|
||||||
|
|
||||||
if (!databases.isNone()) {
|
if (!databases.isNone()) {
|
||||||
|
@ -648,7 +648,7 @@ void ClusterInfo::loadPlannedCollections() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice databases =
|
velocypack::Slice databases =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Plan", "Collections"}));
|
{AgencyComm::prefixStripped(), "Plan", "Collections"}));
|
||||||
|
|
||||||
if (!databases.isNone()) {
|
if (!databases.isNone()) {
|
||||||
|
@ -850,7 +850,7 @@ void ClusterInfo::loadCurrentCollections() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice databases =
|
velocypack::Slice databases =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Current", "Collections"}));
|
{AgencyComm::prefixStripped(), "Current", "Collections"}));
|
||||||
|
|
||||||
if (!databases.isNone()) {
|
if (!databases.isNone()) {
|
||||||
|
@ -1433,7 +1433,7 @@ int ClusterInfo::setCollectionPropertiesCoordinator(
|
||||||
}
|
}
|
||||||
|
|
||||||
velocypack::Slice collection =
|
velocypack::Slice collection =
|
||||||
res._vpack->slice()[0]
|
res.slice()[0]
|
||||||
.get(AgencyComm::prefixStripped())
|
.get(AgencyComm::prefixStripped())
|
||||||
.get("Plan").get("Collections").get(databaseName).get(collectionID);
|
.get("Plan").get("Collections").get(databaseName).get(collectionID);
|
||||||
|
|
||||||
|
@ -1505,7 +1505,7 @@ int ClusterInfo::setCollectionStatusCoordinator(
|
||||||
res = ac.getValues2("Plan/Collections/" + databaseName +"/" + collectionID);
|
res = ac.getValues2("Plan/Collections/" + databaseName +"/" + collectionID);
|
||||||
|
|
||||||
velocypack::Slice col =
|
velocypack::Slice col =
|
||||||
res._vpack->slice()[0]
|
res.slice()[0]
|
||||||
.get(AgencyComm::prefixStripped()).get("Plan").get("Collections")
|
.get(AgencyComm::prefixStripped()).get("Plan").get("Collections")
|
||||||
.get(databaseName).get(collectionID);
|
.get(databaseName).get(collectionID);
|
||||||
|
|
||||||
|
@ -1700,7 +1700,7 @@ int ClusterInfo::ensureIndexCoordinator(
|
||||||
bool usePrevious = true;
|
bool usePrevious = true;
|
||||||
|
|
||||||
velocypack::Slice database =
|
velocypack::Slice database =
|
||||||
previous._vpack->slice()[0].get(std::vector<std::string>(
|
previous.slice()[0].get(std::vector<std::string>(
|
||||||
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName }));
|
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName }));
|
||||||
|
|
||||||
if (!database.isObject()) {
|
if (!database.isObject()) {
|
||||||
|
@ -1850,7 +1850,7 @@ int ClusterInfo::ensureIndexCoordinator(
|
||||||
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
||||||
errorMsg);
|
errorMsg);
|
||||||
}
|
}
|
||||||
VPackSlice versionSlice = res._vpack->slice()[0].get(
|
VPackSlice versionSlice = res.slice()[0].get(
|
||||||
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
|
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
|
||||||
if (!versionSlice.isInteger()) {
|
if (!versionSlice.isInteger()) {
|
||||||
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
||||||
|
@ -1894,7 +1894,7 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName,
|
||||||
AgencyCommResult res = ac.getValues2(key);
|
AgencyCommResult res = ac.getValues2(key);
|
||||||
|
|
||||||
velocypack::Slice previous =
|
velocypack::Slice previous =
|
||||||
res._vpack->slice()[0].get(std::vector<std::string>(
|
res.slice()[0].get(std::vector<std::string>(
|
||||||
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName, collectionID }
|
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName, collectionID }
|
||||||
));
|
));
|
||||||
TRI_ASSERT(VPackObjectIterator(previous).size()>0);
|
TRI_ASSERT(VPackObjectIterator(previous).size()>0);
|
||||||
|
@ -2078,7 +2078,7 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName,
|
||||||
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
||||||
errorMsg);
|
errorMsg);
|
||||||
}
|
}
|
||||||
VPackSlice versionSlice = res._vpack->slice()[0].get(
|
VPackSlice versionSlice = res.slice()[0].get(
|
||||||
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
|
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
|
||||||
if (!versionSlice.isInteger()) {
|
if (!versionSlice.isInteger()) {
|
||||||
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
|
||||||
|
@ -2124,7 +2124,7 @@ void ClusterInfo::loadServers() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice serversRegistered =
|
velocypack::Slice serversRegistered =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Current", "ServersRegistered"}));
|
{AgencyComm::prefixStripped(), "Current", "ServersRegistered"}));
|
||||||
|
|
||||||
if (!serversRegistered.isNone()) {
|
if (!serversRegistered.isNone()) {
|
||||||
|
@ -2256,7 +2256,7 @@ void ClusterInfo::loadCurrentCoordinators() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice currentCoordinators =
|
velocypack::Slice currentCoordinators =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Current", "Coordinators"}));
|
{AgencyComm::prefixStripped(), "Current", "Coordinators"}));
|
||||||
|
|
||||||
if (!currentCoordinators.isNone()) {
|
if (!currentCoordinators.isNone()) {
|
||||||
|
@ -2313,7 +2313,7 @@ void ClusterInfo::loadCurrentDBServers() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice currentDBServers =
|
velocypack::Slice currentDBServers =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Current", "DBServers"}));
|
{AgencyComm::prefixStripped(), "Current", "DBServers"}));
|
||||||
|
|
||||||
if (!currentDBServers.isNone()) {
|
if (!currentDBServers.isNone()) {
|
||||||
|
|
|
@ -193,7 +193,7 @@ void HeartbeatThread::runDBServer() {
|
||||||
LOG(ERR) << "Could not read Current/Version from agency.";
|
LOG(ERR) << "Could not read Current/Version from agency.";
|
||||||
} else {
|
} else {
|
||||||
VPackSlice s
|
VPackSlice s
|
||||||
= res._vpack->slice()[0].get(std::vector<std::string>(
|
= res.slice()[0].get(std::vector<std::string>(
|
||||||
{_agency.prefixStripped(), std::string("Current"),
|
{_agency.prefixStripped(), std::string("Current"),
|
||||||
std::string("Version")}));
|
std::string("Version")}));
|
||||||
if (!s.isInteger()) {
|
if (!s.isInteger()) {
|
||||||
|
@ -326,7 +326,7 @@ void HeartbeatThread::runCoordinator() {
|
||||||
|
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
VPackSlice versionSlice
|
VPackSlice versionSlice
|
||||||
= result._vpack->slice()[0].get(std::vector<std::string>(
|
= result.slice()[0].get(std::vector<std::string>(
|
||||||
{_agency.prefixStripped(), "Plan", "Version"}));
|
{_agency.prefixStripped(), "Plan", "Version"}));
|
||||||
|
|
||||||
if (versionSlice.isInteger()) {
|
if (versionSlice.isInteger()) {
|
||||||
|
@ -354,7 +354,7 @@ void HeartbeatThread::runCoordinator() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
velocypack::Slice slice =
|
velocypack::Slice slice =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{_agency.prefixStripped(), "Sync", "UserVersion"}));
|
{_agency.prefixStripped(), "Sync", "UserVersion"}));
|
||||||
|
|
||||||
if (slice.isInteger()) {
|
if (slice.isInteger()) {
|
||||||
|
@ -401,7 +401,7 @@ void HeartbeatThread::runCoordinator() {
|
||||||
if (result.successful()) {
|
if (result.successful()) {
|
||||||
|
|
||||||
VPackSlice versionSlice
|
VPackSlice versionSlice
|
||||||
= result._vpack->slice()[0].get(std::vector<std::string>(
|
= result.slice()[0].get(std::vector<std::string>(
|
||||||
{_agency.prefixStripped(), "Plan", "Version"}));
|
{_agency.prefixStripped(), "Plan", "Version"}));
|
||||||
if (versionSlice.isInteger()) {
|
if (versionSlice.isInteger()) {
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
|
||||||
|
|
||||||
std::vector<TRI_voc_tick_t> ids;
|
std::vector<TRI_voc_tick_t> ids;
|
||||||
velocypack::Slice databases =
|
velocypack::Slice databases =
|
||||||
result._vpack->slice()[0].get(std::vector<std::string>(
|
result.slice()[0].get(std::vector<std::string>(
|
||||||
{AgencyComm::prefixStripped(), "Plan", "Databases"}));
|
{AgencyComm::prefixStripped(), "Plan", "Databases"}));
|
||||||
|
|
||||||
if (!databases.isObject()) {
|
if (!databases.isObject()) {
|
||||||
|
|
|
@ -239,7 +239,7 @@ static void JS_GetAgency(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
||||||
|
|
||||||
// return just the value for each key
|
// return just the value for each key
|
||||||
|
|
||||||
for (auto const& a : VPackArrayIterator(result._vpack->slice())) {
|
for (auto const& a : VPackArrayIterator(result.slice())) {
|
||||||
for (auto const& o : VPackObjectIterator(a)) {
|
for (auto const& o : VPackObjectIterator(a)) {
|
||||||
|
|
||||||
std::string const key = o.key.copyString();
|
std::string const key = o.key.copyString();
|
||||||
|
|
Loading…
Reference in New Issue