Merge pull request #483 from alexmiller-apple/multidc_dcvector

MultiDC: Regions JSON should represent datacenters as an array.
This commit is contained in:
Evan Tschannen 2018-06-13 18:33:04 -07:00 committed by GitHub
commit 0059690502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 43 deletions

View File

@ -58,10 +58,27 @@ void parse( std::vector<RegionInfo>* regions, ValueRef const& v ) {
regions->clear();
for (StatusObjectReader dc : regionArray) {
RegionInfo info;
std::string idStr;
dc.get("id", idStr);
info.dcId = idStr;
dc.get("priority", info.priority);
json_spirit::mArray datacenters;
dc.get("datacenters", datacenters);
bool nonSatelliteDatacenters = 0;
for (StatusObjectReader s : datacenters) {
std::string idStr;
if (s.has("satellite") && s.last().get_int() == 1) {
SatelliteInfo satInfo;
s.get("id", idStr);
satInfo.dcId = idStr;
s.get("priority", satInfo.priority);
info.satellites.push_back(satInfo);
} else {
if (nonSatelliteDatacenters > 0) throw invalid_option();
nonSatelliteDatacenters++;
s.get("id", idStr);
info.dcId = idStr;
s.get("priority", info.priority);
}
}
std::sort(info.satellites.begin(), info.satellites.end(), SatelliteInfo::sort_by_priority() );
if (nonSatelliteDatacenters != 1) throw invalid_option();
dc.tryGet("satellite_logs", info.satelliteDesiredTLogCount);
std::string satelliteReplication;
if(dc.tryGet("satellite_redundancy_mode", satelliteReplication)) {
@ -97,18 +114,6 @@ void parse( std::vector<RegionInfo>* regions, ValueRef const& v ) {
dc.tryGet("satellite_log_replicas", info.satelliteTLogReplicationFactor);
dc.tryGet("satellite_usable_dcs", info.satelliteTLogUsableDcs);
dc.tryGet("satellite_anti_quorum", info.satelliteTLogWriteAntiQuorum);
json_spirit::mArray satellites;
if( dc.tryGet("satellites", satellites) ) {
for (StatusObjectReader s : satellites) {
SatelliteInfo satInfo;
std::string sidStr;
s.get("id", sidStr);
satInfo.dcId = sidStr;
s.get("priority", satInfo.priority);
info.satellites.push_back(satInfo);
}
std::sort(info.satellites.begin(), info.satellites.end(), SatelliteInfo::sort_by_priority() );
}
regions->push_back(info);
}
std::sort(regions->begin(), regions->end(), RegionInfo::sort_by_priority() );
@ -242,44 +247,47 @@ StatusObject DatabaseConfiguration::toJSON(bool noPolicies) const {
if(regions.size()) {
StatusArray regionArr;
for(auto& r : regions) {
StatusObject regionObj;
StatusArray dcArr;
StatusObject dcObj;
dcObj["id"] = r.dcId.toString();
dcObj["priority"] = r.priority;
dcArr.push_back(dcObj);
if(r.satelliteTLogReplicationFactor == 1 && r.satelliteTLogUsableDcs == 1 && r.satelliteTLogWriteAntiQuorum == 0) {
dcObj["satellite_redundancy_mode"] = "one_satellite_single";
regionObj["satellite_redundancy_mode"] = "one_satellite_single";
} else if(r.satelliteTLogReplicationFactor == 2 && r.satelliteTLogUsableDcs == 1 && r.satelliteTLogWriteAntiQuorum == 0) {
dcObj["satellite_redundancy_mode"] = "one_satellite_double";
regionObj["satellite_redundancy_mode"] = "one_satellite_double";
} else if(r.satelliteTLogReplicationFactor == 3 && r.satelliteTLogUsableDcs == 1 && r.satelliteTLogWriteAntiQuorum == 0) {
dcObj["satellite_redundancy_mode"] = "one_satellite_triple";
regionObj["satellite_redundancy_mode"] = "one_satellite_triple";
} else if(r.satelliteTLogReplicationFactor == 4 && r.satelliteTLogUsableDcs == 2 && r.satelliteTLogWriteAntiQuorum == 0) {
dcObj["satellite_redundancy_mode"] = "two_satellite_safe";
regionObj["satellite_redundancy_mode"] = "two_satellite_safe";
} else if(r.satelliteTLogReplicationFactor == 4 && r.satelliteTLogUsableDcs == 2 && r.satelliteTLogWriteAntiQuorum == 2) {
dcObj["satellite_redundancy_mode"] = "two_satellite_fast";
regionObj["satellite_redundancy_mode"] = "two_satellite_fast";
} else if(r.satelliteTLogReplicationFactor != 0) {
dcObj["satellite_log_replicas"] = r.satelliteTLogReplicationFactor;
dcObj["satellite_usable_dcs"] = r.satelliteTLogUsableDcs;
dcObj["satellite_anti_quorum"] = r.satelliteTLogWriteAntiQuorum;
if(r.satelliteTLogPolicy) dcObj["satellite_log_policy"] = r.satelliteTLogPolicy->info();
regionObj["satellite_log_replicas"] = r.satelliteTLogReplicationFactor;
regionObj["satellite_usable_dcs"] = r.satelliteTLogUsableDcs;
regionObj["satellite_anti_quorum"] = r.satelliteTLogWriteAntiQuorum;
if(r.satelliteTLogPolicy) regionObj["satellite_log_policy"] = r.satelliteTLogPolicy->info();
}
if( r.satelliteDesiredTLogCount != -1 ) {
dcObj["satellite_logs"] = r.satelliteDesiredTLogCount;
regionObj["satellite_logs"] = r.satelliteDesiredTLogCount;
}
if(r.satellites.size()) {
StatusArray satellitesArr;
for(auto& s : r.satellites) {
StatusObject satObj;
satObj["id"] = s.dcId.toString();
satObj["priority"] = s.priority;
satObj["satellite"] = 1;
satellitesArr.push_back(satObj);
dcArr.push_back(satObj);
}
dcObj["satellites"] = satellitesArr;
}
regionArr.push_back(dcObj);
regionObj["datacenters"] = dcArr;
regionArr.push_back(regionObj);
}
result["regions"] = regionArr;
}

View File

@ -761,28 +761,32 @@ void SimulationConfig::generateNormalConfig(int minimumReplication) {
if(generateFearless || (datacenters == 2 && g_random->random01() < 0.5)) {
StatusObject primaryObj;
primaryObj["id"] = "0";
primaryObj["priority"] = 0;
StatusObject primaryDcObj;
primaryDcObj["id"] = "0";
primaryDcObj["priority"] = 0;
StatusArray primaryDcArr;
primaryDcArr.push_back(primaryDcObj);
StatusObject remoteObj;
remoteObj["id"] = "1";
remoteObj["priority"] = 1;
StatusObject remoteDcObj;
remoteDcObj["id"] = "1";
remoteDcObj["priority"] = 1;
StatusArray remoteDcArr;
remoteDcArr.push_back(remoteDcObj);
bool needsRemote = generateFearless;
if(generateFearless) {
StatusObject primarySatelliteObj;
primarySatelliteObj["id"] = "2";
primarySatelliteObj["priority"] = 1;
StatusArray primarySatellitesArr;
primarySatellitesArr.push_back(primarySatelliteObj);
primaryObj["satellites"] = primarySatellitesArr;
primarySatelliteObj["satellite"] = 1;
primaryDcArr.push_back(primarySatelliteObj);
StatusObject remoteSatelliteObj;
remoteSatelliteObj["id"] = "3";
remoteSatelliteObj["priority"] = 1;
StatusArray remoteSatellitesArr;
remoteSatellitesArr.push_back(remoteSatelliteObj);
remoteObj["satellites"] = remoteSatellitesArr;
remoteSatelliteObj["satellite"] = 1;
remoteDcArr.push_back(remoteSatelliteObj);
int satellite_replication_type = g_random->randomInt(0,5);
switch (satellite_replication_type) {
@ -822,7 +826,7 @@ void SimulationConfig::generateNormalConfig(int minimumReplication) {
primaryObj["satellite_logs"] = logs;
remoteObj["satellite_logs"] = logs;
}
int remote_replication_type = g_random->randomInt(0,5);
switch (remote_replication_type) {
case 0: {
@ -857,6 +861,9 @@ void SimulationConfig::generateNormalConfig(int minimumReplication) {
if (g_random->random01() < 0.25) db.remoteDesiredTLogCount = g_random->randomInt(1,7);
}
primaryObj["datacenters"] = primaryDcArr;
remoteObj["datacenters"] = remoteDcArr;
StatusArray regionArr;
regionArr.push_back(primaryObj);
if(needsRemote || g_random->random01() < 0.5) {
@ -865,8 +872,8 @@ void SimulationConfig::generateNormalConfig(int minimumReplication) {
set_config("regions=" + json_spirit::write_string(json_spirit::mValue(regionArr), json_spirit::Output_options::none));
}
if(generateFearless && minimumReplication > 1) {
if(generateFearless && minimumReplication > 1) {
//low latency tests in fearless configurations need 4 machines per datacenter (3 for triple replication, 1 that is down during failures).
machine_count = 16;
} else if(generateFearless) {