|
82 | 82 | OPT_BUGGIFY, |
83 | 83 | OPT_BUGGIFY_INTENSITY, |
84 | 84 | OPT_METRIC_PLUGIN, |
85 | | - OPT_METRIC_CONFIG |
| 85 | + OPT_METRIC_CONFIG, |
| 86 | + OPT_FDB_DC_ID |
86 | 87 | }; |
87 | 88 | CSimpleOpt::SOption g_rgOptions[] = {{OPT_CONNFILE, "-C", SO_REQ_SEP}, |
88 | 89 | {OPT_CONNFILE, "--cluster_file", SO_REQ_SEP}, |
@@ -116,6 +117,7 @@ CSimpleOpt::SOption g_rgOptions[] = {{OPT_CONNFILE, "-C", SO_REQ_SEP}, |
116 | 117 | {OPT_BUGGIFY_INTENSITY, "--buggify_intensity", SO_REQ_SEP}, |
117 | 118 | {OPT_METRIC_PLUGIN, "--metric_plugin", SO_OPT}, |
118 | 119 | {OPT_METRIC_CONFIG, "--metric_plugin_config", SO_OPT}, |
| 120 | + {OPT_FDB_DC_ID, "--fdb_datacenter_id", SO_OPT}, |
119 | 121 | #ifndef TLS_DISABLED |
120 | 122 | TLS_OPTION_FLAGS |
121 | 123 | #endif |
@@ -431,7 +433,8 @@ ACTOR void setup(NetworkAddress na, |
431 | 433 | const char* rootDirectory, |
432 | 434 | std::string unitTestPattern, |
433 | 435 | std::vector<std::pair<std::string, std::string>> client_knobs, |
434 | | - NetworkOptionsT client_network_options) { |
| 436 | + NetworkOptionsT client_network_options, |
| 437 | + std::string fdbDatacenterID) { |
435 | 438 | state FDB::API* fdb; |
436 | 439 | try { |
437 | 440 | fdb = FDB::API::selectAPIVersion(510); |
@@ -461,6 +464,10 @@ ACTOR void setup(NetworkAddress na, |
461 | 464 | try { |
462 | 465 | auto cluster = fdb->createCluster(clusterFile); |
463 | 466 | Reference<DatabaseContext> database = cluster->createDatabase(); |
| 467 | + if (!fdbDatacenterID.empty()) { |
| 468 | + database->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_DATACENTER_ID, |
| 469 | + Optional<StringRef>(fdbDatacenterID)); |
| 470 | + } |
464 | 471 | db = database; |
465 | 472 | try { |
466 | 473 | state Reference<Transaction> tr3(new Transaction(db)); |
@@ -596,6 +603,9 @@ void printHelp(const char* name) { |
596 | 603 | --proxy-ports LISTEN_PORT MONGODB_PORT |
597 | 604 | Runs Document Layer in proxy mode on LISTEN_PORT proxying all commands |
598 | 605 | 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 |
599 | 609 | )HELPTEXT", |
600 | 610 | name); |
601 | 611 | #ifndef TLS_DISABLED |
@@ -642,6 +652,7 @@ int main(int argc, char** argv) { |
642 | 652 | NetworkOptionsT client_network_options; |
643 | 653 | std::string metricReporterConfig; |
644 | 654 | char* metricPluginPath = nullptr; |
| 655 | + std::string fdbDatacenterID; |
645 | 656 | #ifndef TLS_DISABLED |
646 | 657 | Reference<TLSOptions> tlsOptions = Reference<TLSOptions>(new TLSOptions); |
647 | 658 | #endif |
@@ -875,6 +886,10 @@ int main(int argc, char** argv) { |
875 | 886 | } |
876 | 887 | break; |
877 | 888 | } |
| 889 | + case OPT_FDB_DC_ID: { |
| 890 | + fdbDatacenterID = args.OptionArg(); |
| 891 | + break; |
| 892 | + } |
878 | 893 | #ifndef TLS_DISABLED |
879 | 894 | case TLSOptions::OPT_TLS_PLUGIN: |
880 | 895 | args.OptionArg(); |
@@ -991,7 +1006,8 @@ int main(int argc, char** argv) { |
991 | 1006 | setThreadName("fdbdoc-main"); |
992 | 1007 | TraceEvent::setNetworkThread(); |
993 | 1008 | 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); |
995 | 1011 | systemMonitor(); |
996 | 1012 | uncancellable(recurring(&systemMonitor, 5.0, TaskMaxPriority)); |
997 | 1013 |
|
|
0 commit comments