From 167e3189643889c00300fd3e164b5d61a4ee0e24 Mon Sep 17 00:00:00 2001 From: Senthil Nathan Date: Thu, 26 Sep 2019 17:13:48 +0530 Subject: [PATCH] Resolves #133: Modified document layer to listen connection before reading FDB cluster --- src/DocLayer.actor.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/DocLayer.actor.cpp b/src/DocLayer.actor.cpp index 09506cc..e529998 100644 --- a/src/DocLayer.actor.cpp +++ b/src/DocLayer.actor.cpp @@ -266,15 +266,10 @@ ACTOR Future extServerConnection(Reference docLayer, } } -ACTOR void extServer(Reference docLayer, NetworkAddress addr) { +ACTOR void extServer(Reference docLayer, Reference listener) { state ActorCollection connections(false); state int64_t nextConnectionId = 1; try { - state Reference listener = INetworkConnections::net()->listen(addr); - - TraceEvent("BD_server").detail("version", FDB_DOC_VT_PACKAGE_NAME).detail("address", addr.toString()); - fprintf(stdout, "FdbDocServer (%s): listening on %s\n", FDB_DOC_VT_PACKAGE_NAME, addr.toString().c_str()); - loop choose { when(Reference conn = wait(listener->accept())) { Reference bc(new BufferedConnection(conn)); @@ -529,6 +524,22 @@ ACTOR void setup(NetworkAddress na, if (!proxyto.present()) { state Reference docLayer; state Reference db; + + // #133: The Document Layer instances open their listening connection before reading from their FoundationDB + // cluster + try { + state Reference listener = INetworkConnections::net()->listen(na); + TraceEvent("BD_server").detail("version", FDB_DOC_VT_PACKAGE_NAME).detail("address", na.toString()); + fprintf(stdout, "FdbDocServer (%s): listening on %s\n", FDB_DOC_VT_PACKAGE_NAME, na.toString().c_str()); + + } catch (Error& e) { + + TraceEvent(SevError, "BD_server").error(e); + fprintf(stderr, "FdbDocServer: fatal error: %s\n", e.what()); + g_network->stop(); + throw; + } + try { db = fdb->createDatabase(clusterFile); if (!fdbDatacenterID.empty()) { @@ -612,7 +623,7 @@ ACTOR void setup(NetworkAddress na, } } statusUpdateActor(FDB_DOC_VT_PACKAGE_NAME, na.ip.toString(), na.port, docLayer, timer() * 1000); - extServer(docLayer, na); + extServer(docLayer, listener); if (!unitTestPattern.empty()) Tests::g_docLayer = docLayer;