Address review comments

This commit is contained in:
Xin Dong 2020-03-30 13:55:59 -07:00
parent 52b6754598
commit 012d41548e
3 changed files with 64 additions and 3 deletions

View File

@ -997,12 +997,52 @@ void printStatus(StatusObjectReader statusObj, StatusClient::StatusLevel level,
outputString += "unknown";
}
Optional<std::string> activePrimaryDC;
if (statusObjConfig.has("active_primary_dc")) {
activePrimaryDC = statusObjConfig["active_primary_dc"].get_str();
}
StatusArray regions;
if (statusObjConfig.has("regions")) {
outputString += "\n Regions: ";
regions = statusObjConfig["regions"].get_array();
bool isFirstRegion = true;
bool isPrimary = false;
std::vector<std::string> regionSatelliteDCs;
std::string regionDC;
for (StatusObjectReader region : regions) {
outputString += "\n -";
// Assumes the `regions` are already sorted by priority in descending order
for (StatusObjectReader dc : region["datacenters"].get_array()) {
if (!dc.has("satellite")) {
regionDC = dc["id"].get_str();
if (activePrimaryDC.present() && dc["id"].get_str() == activePrimaryDC.get()) {
isPrimary = true;
} else if (!activePrimaryDC.present() && isFirstRegion) {
isPrimary = true;
}
} else if (dc["satellite"].get_int() == 1) {
regionSatelliteDCs.push_back(dc["id"].get_str());
}
}
if (isPrimary) {
outputString += "\n Primary -";
} else {
outputString += "\n Remote -";
}
outputString += format("\n Datacenter - %s", regionDC.c_str());
if (regionSatelliteDCs.size() > 0) {
outputString += "\n Satellite datacenters - ";
for (int i = 0; i < regionSatelliteDCs.size(); i++) {
if (i != regionSatelliteDCs.size() - 1) {
outputString += format("%s, ", regionSatelliteDCs[i].c_str());
} else {
outputString += format("%s", regionSatelliteDCs[i].c_str());
}
}
}
isPrimary = false;
isFirstRegion = false;
if (region.get("satellite_redundancy_mode", strVal)) {
outputString += format("\n Satellite Redundancy Mode - %s", strVal.c_str());
}

View File

@ -536,6 +536,7 @@ const KeyRef JSONSchemas::statusSchema = LiteralStringRef(R"statusSchema(
"data_distribution_disabled_for_rebalance":true,
"data_distribution_disabled":true,
"configuration":{
"active_primary_db":"pv",
"log_anti_quorum":0,
"log_replicas":2,
"log_replication_policy":"(zoneid^3x1)",

View File

@ -2150,6 +2150,20 @@ ACTOR Future<JsonBuilderObject> lockedStatusFetcher(Reference<AsyncVar<CachedSer
return statusObj;
}
ACTOR Future<Optional<Value>> getActivePrimaryDC(Database cx) {
state ReadYourWritesTransaction tr(cx);
loop {
try {
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
Optional<Value> res = wait(tr.get(primaryDatacenterKey));
return res;
} catch (Error& e) {
wait(tr.onError(e));
}
}
}
// constructs the cluster section of the json status output
ACTOR Future<StatusReply> clusterGetStatus(
Reference<AsyncVar<CachedSerialization<ServerDBInfo>>> db,
@ -2346,11 +2360,17 @@ ACTOR Future<StatusReply> clusterGetStatus(
statusObj["fault_tolerance"] = faultToleranceStatusFetcher(configuration.get(), coordinators, workers, extraTlogEligibleZones, minReplicasRemaining, loadResult.present() && loadResult.get().healthyZone.present());
}
JsonBuilderObject configObj = configurationFetcher(configuration, coordinators, &status_incomplete_reasons);
state JsonBuilderObject configObj =
configurationFetcher(configuration, coordinators, &status_incomplete_reasons);
// configArr could be empty
if (!configObj.empty())
if (!configObj.empty()) {
Optional<Value> primaryDCO = wait(getActivePrimaryDC(cx));
if (primaryDCO.present()) {
configObj["active_primary_dc"] = primaryDCO.get();
}
statusObj["configuration"] = configObj;
}
// workloadStatusFetcher returns the workload section but also optionally writes the qos section and adds to the data_overlay object
if (!workerStatuses[1].empty())