Skip to content

Commit c4cb6a3

Browse files
dongxinEricapkar
authored andcommitted
Resolves #117: Support datacenter_id (#134)
* Support feeding in the datacenter_id option from start up command to the FDB Database created. * Change to use std::string just for safe. * Changes based on review. * Accept suggested change. Co-Authored-By: dongxinEric <jiangzian1987dx@gmail.com>
1 parent 9168603 commit c4cb6a3

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/DocLayer.actor.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ enum {
8282
OPT_BUGGIFY,
8383
OPT_BUGGIFY_INTENSITY,
8484
OPT_METRIC_PLUGIN,
85-
OPT_METRIC_CONFIG
85+
OPT_METRIC_CONFIG,
86+
OPT_FDB_DC_ID
8687
};
8788
CSimpleOpt::SOption g_rgOptions[] = {{OPT_CONNFILE, "-C", SO_REQ_SEP},
8889
{OPT_CONNFILE, "--cluster_file", SO_REQ_SEP},
@@ -116,6 +117,7 @@ CSimpleOpt::SOption g_rgOptions[] = {{OPT_CONNFILE, "-C", SO_REQ_SEP},
116117
{OPT_BUGGIFY_INTENSITY, "--buggify_intensity", SO_REQ_SEP},
117118
{OPT_METRIC_PLUGIN, "--metric_plugin", SO_OPT},
118119
{OPT_METRIC_CONFIG, "--metric_plugin_config", SO_OPT},
120+
{OPT_FDB_DC_ID, "--fdb_datacenter_id", SO_OPT},
119121
#ifndef TLS_DISABLED
120122
TLS_OPTION_FLAGS
121123
#endif
@@ -431,7 +433,8 @@ ACTOR void setup(NetworkAddress na,
431433
const char* rootDirectory,
432434
std::string unitTestPattern,
433435
std::vector<std::pair<std::string, std::string>> client_knobs,
434-
NetworkOptionsT client_network_options) {
436+
NetworkOptionsT client_network_options,
437+
std::string fdbDatacenterID) {
435438
state FDB::API* fdb;
436439
try {
437440
fdb = FDB::API::selectAPIVersion(510);
@@ -461,6 +464,10 @@ ACTOR void setup(NetworkAddress na,
461464
try {
462465
auto cluster = fdb->createCluster(clusterFile);
463466
Reference<DatabaseContext> database = cluster->createDatabase();
467+
if (!fdbDatacenterID.empty()) {
468+
database->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_DATACENTER_ID,
469+
Optional<StringRef>(fdbDatacenterID));
470+
}
464471
db = database;
465472
try {
466473
state Reference<Transaction> tr3(new Transaction(db));
@@ -596,6 +603,9 @@ void printHelp(const char* name) {
596603
--proxy-ports LISTEN_PORT MONGODB_PORT
597604
Runs Document Layer in proxy mode on LISTEN_PORT proxying all commands
598605
to MongoDB server running on MONGODB_PORT.
606+
--fdb_datacenter_id DC_ID
607+
The id of the preferred datacenter to use when connecting to a FoundationDB cluster
608+
that's run in multi-dc mode
599609
)HELPTEXT",
600610
name);
601611
#ifndef TLS_DISABLED
@@ -642,6 +652,7 @@ int main(int argc, char** argv) {
642652
NetworkOptionsT client_network_options;
643653
std::string metricReporterConfig;
644654
char* metricPluginPath = nullptr;
655+
std::string fdbDatacenterID;
645656
#ifndef TLS_DISABLED
646657
Reference<TLSOptions> tlsOptions = Reference<TLSOptions>(new TLSOptions);
647658
#endif
@@ -875,6 +886,10 @@ int main(int argc, char** argv) {
875886
}
876887
break;
877888
}
889+
case OPT_FDB_DC_ID: {
890+
fdbDatacenterID = args.OptionArg();
891+
break;
892+
}
878893
#ifndef TLS_DISABLED
879894
case TLSOptions::OPT_TLS_PLUGIN:
880895
args.OptionArg();
@@ -991,7 +1006,8 @@ int main(int argc, char** argv) {
9911006
setThreadName("fdbdoc-main");
9921007
TraceEvent::setNetworkThread();
9931008
openTraceFile(na, rollsize, maxLogsSize, logFolder, "fdbdoc-trace", logGroup);
994-
setup(na, proxyto, connFile, options, rootDirectory, unitTestPattern, client_knobs, client_network_options);
1009+
setup(na, proxyto, connFile, options, rootDirectory, unitTestPattern, client_knobs, client_network_options,
1010+
fdbDatacenterID);
9951011
systemMonitor();
9961012
uncancellable(recurring(&systemMonitor, 5.0, TaskMaxPriority));
9971013

0 commit comments

Comments
 (0)