ccdmain.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <platform.h>
  14. #include <signal.h>
  15. #include <jlib.hpp>
  16. #include <jio.hpp>
  17. #include <jmisc.hpp>
  18. #include <jqueue.tpp>
  19. #include <jsocket.hpp>
  20. #include <jlog.hpp>
  21. #include <jprop.hpp>
  22. #include <jfile.hpp>
  23. #include "jutil.hpp"
  24. #include <build-config.h>
  25. #include "dalienv.hpp"
  26. #include "rmtfile.hpp"
  27. #include "ccd.hpp"
  28. #include "ccdquery.hpp"
  29. #include "ccdstate.hpp"
  30. #include "ccdqueue.ipp"
  31. #include "ccdserver.hpp"
  32. #include "ccdlistener.hpp"
  33. #include "ccdsnmp.hpp"
  34. #include "thorplugin.hpp"
  35. #ifdef _USE_CPPUNIT
  36. #include <cppunit/extensions/TestFactoryRegistry.h>
  37. #include <cppunit/ui/text/TestRunner.h>
  38. #endif
  39. //=================================================================================
  40. bool shuttingDown = false;
  41. unsigned numChannels;
  42. unsigned callbackRetries = 3;
  43. unsigned callbackTimeout = 500;
  44. unsigned lowTimeout = 10000;
  45. unsigned highTimeout = 2000;
  46. unsigned slaTimeout = 2000;
  47. unsigned numServerThreads = 30;
  48. unsigned numSlaveThreads = 30;
  49. unsigned numRequestArrayThreads = 5;
  50. unsigned headRegionSize;
  51. unsigned ccdMulticastPort;
  52. bool enableHeartBeat = true;
  53. unsigned parallelLoopFlowLimit = 100;
  54. unsigned perChannelFlowLimit = 10;
  55. time_t startupTime;
  56. unsigned statsExpiryTime = 3600;
  57. unsigned miscDebugTraceLevel = 0; // separate trace settings purely for debugging specific items (i.e. all possible locations to look for files at startup)
  58. unsigned readTimeout = 300;
  59. unsigned indexReadChunkSize = 60000;
  60. unsigned maxBlockSize = 10000000;
  61. unsigned maxLockAttempts = 5;
  62. bool pretendAllOpt = false;
  63. bool traceStartStop = false;
  64. bool traceServerSideCache = false;
  65. bool timeActivities = true;
  66. unsigned watchActivityId = 0;
  67. unsigned testSlaveFailure = 0;
  68. unsigned restarts = 0;
  69. bool heapSort = false;
  70. bool insertionSort = false;
  71. bool fieldTranslationEnabled = false;
  72. bool useTreeCopy = true;
  73. bool mergeSlaveStatistics = true;
  74. PTreeReaderOptions defaultXmlReadFlags = ptr_ignoreWhiteSpace;
  75. bool runOnce = false;
  76. unsigned udpMulticastBufferSize = 262142;
  77. bool roxieMulticastEnabled = true;
  78. IPropertyTree* topology;
  79. StringBuffer topologyFile;
  80. CriticalSection ccdChannelsCrit;
  81. IPropertyTree* ccdChannels;
  82. StringArray allQuerySetNames;
  83. bool allFilesDynamic;
  84. bool crcResources;
  85. bool useRemoteResources;
  86. bool checkFileDate;
  87. bool lazyOpen;
  88. bool localSlave;
  89. bool ignoreOrphans;
  90. bool doIbytiDelay = true;
  91. unsigned initIbytiDelay; // In MillSec
  92. unsigned minIbytiDelay; // In MillSec
  93. bool copyResources;
  94. bool enableKeyDiff = true;
  95. bool chunkingHeap = true;
  96. bool logFullQueries;
  97. bool blindLogging = false;
  98. bool debugPermitted = true;
  99. bool checkCompleted = true;
  100. unsigned preabortKeyedJoinsThreshold = 100;
  101. unsigned preabortIndexReadsThreshold = 100;
  102. bool preloadOnceData;
  103. unsigned memoryStatsInterval = 0;
  104. memsize_t defaultMemoryLimit;
  105. unsigned defaultTimeLimit[3] = {0, 0, 0};
  106. unsigned defaultWarnTimeLimit[3] = {0, 5000, 5000};
  107. unsigned defaultParallelJoinPreload = 0;
  108. unsigned defaultPrefetchProjectPreload = 10;
  109. unsigned defaultConcatPreload = 0;
  110. unsigned defaultFetchPreload = 0;
  111. unsigned defaultFullKeyedJoinPreload = 0;
  112. unsigned defaultKeyedJoinPreload = 0;
  113. unsigned dafilesrvLookupTimeout = 10000;
  114. bool defaultCheckingHeap = false;
  115. unsigned logQueueLen;
  116. unsigned logQueueDrop;
  117. bool useLogQueue;
  118. bool fastLaneQueue;
  119. unsigned mtu_size = 1400; // upper limit on outbound buffer size - allow some header room too
  120. StringBuffer fileNameServiceDali;
  121. StringBuffer roxieName;
  122. bool trapTooManyActiveQueries;
  123. unsigned maxEmptyLoopIterations;
  124. unsigned maxGraphLoopIterations;
  125. bool probeAllRows;
  126. bool steppingEnabled = true;
  127. bool simpleLocalKeyedJoins = true;
  128. unsigned __int64 minFreeDiskSpace = 1024 * 0x100000; // default to 1 GB
  129. unsigned socketCheckInterval = 5000;
  130. StringBuffer logDirectory;
  131. StringBuffer pluginDirectory;
  132. StringBuffer queryDirectory;
  133. StringBuffer codeDirectory;
  134. StringBuffer tempDirectory;
  135. ClientCertificate clientCert;
  136. bool useHardLink;
  137. unsigned maxFileAge[2] = {0xffffffff, 60*60*1000}; // local files don't expire, remote expire in 1 hour, by default
  138. unsigned minFilesOpen[2] = {2000, 500};
  139. unsigned maxFilesOpen[2] = {4000, 1000};
  140. unsigned myNodeIndex = (unsigned) -1;
  141. SocketEndpoint ownEP;
  142. HardwareInfo hdwInfo;
  143. unsigned parallelAggregate;
  144. bool inMemoryKeysEnabled = true;
  145. unsigned serverSideCacheSize = 0;
  146. bool nodeCachePreload = false;
  147. unsigned nodeCacheMB = 100;
  148. unsigned leafCacheMB = 50;
  149. unsigned blobCacheMB = 0;
  150. unsigned roxiePort = 0;
  151. MODULE_INIT(INIT_PRIORITY_STANDARD)
  152. {
  153. topology = NULL;
  154. ccdChannels = NULL;
  155. return true;
  156. }
  157. MODULE_EXIT()
  158. {
  159. ::Release(topology);
  160. ::Release(ccdChannels);
  161. }
  162. //=========================================================================================
  163. //////////////////////////////////////////////////////////////////////////////////////////////
  164. extern "C" void caughtSIGPIPE(int sig)
  165. {
  166. DBGLOG("Caught sigpipe %d", sig);
  167. }
  168. extern "C" void caughtSIGHUP(int sig)
  169. {
  170. DBGLOG("Caught sighup %d", sig);
  171. }
  172. extern "C" void caughtSIGALRM(int sig)
  173. {
  174. DBGLOG("Caught sigalrm %d", sig);
  175. }
  176. extern "C" void caughtSIGTERM(int sig)
  177. {
  178. DBGLOG("Caught sigterm %d", sig);
  179. }
  180. void init_signals()
  181. {
  182. // signal(SIGTERM, caughtSIGTERM);
  183. #ifndef _WIN32
  184. signal(SIGPIPE, caughtSIGPIPE);
  185. signal(SIGHUP, caughtSIGHUP);
  186. signal(SIGALRM, caughtSIGALRM);
  187. #endif
  188. }
  189. //=========================================================================================
  190. class Waiter : public CInterface, implements IAbortHandler
  191. {
  192. Semaphore aborted;
  193. public:
  194. IMPLEMENT_IINTERFACE;
  195. bool wait(unsigned timeout)
  196. {
  197. return aborted.wait(timeout);
  198. }
  199. void wait()
  200. {
  201. aborted.wait();
  202. }
  203. bool onAbort()
  204. {
  205. aborted.signal();
  206. roxieMetrics.clear();
  207. #ifdef _DEBUG
  208. return false; // we want full leak checking info
  209. #else
  210. return true; // we don't care - just exit as fast as we can
  211. #endif
  212. }
  213. } waiter;
  214. void closedown()
  215. {
  216. Owned<IFile> sentinelFile = createSentinelTarget();
  217. removeSentinelFile(sentinelFile);
  218. waiter.onAbort();
  219. }
  220. void getAccessList(const char *aclName, const IPropertyTree *topology, IPropertyTree *aclInfo)
  221. {
  222. StringBuffer xpath;
  223. xpath.append("ACL[@name='").append(aclName).append("']");
  224. if (aclInfo->queryPropTree(xpath))
  225. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - recursive ACL definition of %s", aclName);
  226. Owned<IPropertyTree> X = createPTree("ACL");
  227. X->setProp("@name", aclName);
  228. aclInfo->addPropTree("ACL", X.getClear());
  229. Owned<IPropertyTree> acl = topology->getPropTree(xpath.str());
  230. if (!acl)
  231. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - acl %s not found", aclName);
  232. Owned<IPropertyTreeIterator> access = acl->getElements("Access");
  233. ForEach(*access)
  234. {
  235. IPropertyTree &child = access->query();
  236. const char *base = child.queryProp("@base");
  237. if (base)
  238. getAccessList(base, topology, aclInfo);
  239. else
  240. aclInfo->addPropTree(child.queryName(), LINK(&child));
  241. }
  242. aclInfo->removeProp(xpath);
  243. }
  244. bool ipMatch(IpAddress &ip)
  245. {
  246. return ip.isLocal();
  247. }
  248. void addSlaveChannel(unsigned channel, unsigned level)
  249. {
  250. StringBuffer xpath;
  251. xpath.appendf("RoxieSlaveProcess[@channel=\"%d\"]", channel);
  252. if (ccdChannels->hasProp(xpath.str()))
  253. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - channel %d repeated", channel);
  254. IPropertyTree *ci = createPTree("RoxieSlaveProcess");
  255. ci->setPropInt("@channel", channel);
  256. ci->setPropInt("@subChannel", numSlaves[channel]);
  257. ccdChannels->addPropTree("RoxieSlaveProcess", ci);
  258. }
  259. void addChannel(unsigned nodeNumber, unsigned channel, unsigned level)
  260. {
  261. numSlaves[channel]++;
  262. if (nodeNumber == myNodeIndex && channel > 0)
  263. {
  264. assertex(channel <= numChannels);
  265. assertex(!replicationLevel[channel]);
  266. replicationLevel[channel] = level;
  267. addSlaveChannel(channel, level);
  268. }
  269. if (!localSlave)
  270. {
  271. addEndpoint(channel, getNodeAddress(nodeNumber), ccdMulticastPort);
  272. }
  273. }
  274. extern void doUNIMPLEMENTED(unsigned line, const char *file)
  275. {
  276. throw MakeStringException(ROXIE_UNIMPLEMENTED_ERROR, "UNIMPLEMENTED at %s:%d", file, line);
  277. }
  278. void FatalError(const char *format, ...)
  279. {
  280. va_list args;
  281. va_start(args, format);
  282. StringBuffer errMsg;
  283. errMsg.valist_appendf(format, args);
  284. va_end(args);
  285. Owned<IException> E = MakeStringException(MSGAUD_operator, ROXIE_INTERNAL_ERROR, "%s", errMsg.str());
  286. EXCLOG(E, "Fatal error");
  287. Sleep(5000);
  288. _exit(1);
  289. }
  290. // If changing these, please change roxie.cpp's roxie_server_usage() as well
  291. static void roxie_common_usage(const char * progName)
  292. {
  293. StringBuffer program;
  294. program.append(progName);
  295. getFileNameOnly(program, false);
  296. // Things that are also relevant to stand-alone executables
  297. printf("Usage: %s [options]\n", program.str());
  298. printf("\nOptions:\n");
  299. printf("\t--daliServers=[host1,...]\t: List of Dali servers to use\n");
  300. printf("\t--tracelevel=[integer]\t: Amount of information to dump on logs\n");
  301. printf("\t--stdlog=[boolean]\t: Standard log format (based on tracelevel)\n");
  302. printf("\t--logfile=[format]\t: Outputs to logfile, rather than stdout\n");
  303. printf("\t--help|-h\t: This message\n");
  304. printf("\n");
  305. }
  306. class MAbortHandler : implements IExceptionHandler
  307. {
  308. unsigned dummy; // to avoid complaints about an empty class...
  309. public:
  310. MAbortHandler() : dummy(0) {};
  311. virtual bool fireException(IException *e)
  312. {
  313. ForEachItemIn(idx, socketListeners)
  314. {
  315. socketListeners.item(idx).stopListening();
  316. }
  317. return false;
  318. }
  319. } abortHandler;
  320. #ifdef _WIN32
  321. int myhook(int alloctype, void *, size_t nSize, int p1, long allocSeq, const unsigned char *file, int line)
  322. {
  323. // Handy place to put breakpoints when tracking down obscure memory leaks...
  324. if (nSize==68 && !file)
  325. {
  326. DBGLOG("memory hook matched");
  327. }
  328. return true;
  329. }
  330. #endif
  331. void saveTopology()
  332. {
  333. // Write back changes that have been made via certain control:xxx changes, so that they survive a roxie restart
  334. // Note that they are overwritten when Roxie is manually stopped/started via hpcc-init service - these changes
  335. // are only intended to be temporary for the current session
  336. try
  337. {
  338. saveXML(topologyFile.str(), topology);
  339. }
  340. catch (IException *E)
  341. {
  342. // If we can't save the topology, then tough. Carry on without it. Changes will not survive an unexpected roxie restart
  343. EXCLOG(E, "Error saving topology file");
  344. E->Release();
  345. }
  346. }
  347. int STARTQUERY_API start_query(int argc, const char *argv[])
  348. {
  349. EnableSEHtoExceptionMapping();
  350. setTerminateOnSEH();
  351. init_signals();
  352. // We need to do the above BEFORE we call InitModuleObjects
  353. InitModuleObjects();
  354. getDaliServixPort();
  355. init_signals();
  356. // stand alone usage only, not server
  357. for (unsigned i=0; i<argc; i++)
  358. {
  359. if (stricmp(argv[i], "--help")==0 ||
  360. stricmp(argv[i], "-h")==0)
  361. {
  362. roxie_common_usage(argv[0]);
  363. return EXIT_SUCCESS;
  364. }
  365. }
  366. #ifdef _USE_CPPUNIT
  367. if (argc>=2 && stricmp(argv[1], "-selftest")==0)
  368. {
  369. queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time | MSGFIELD_prefix);
  370. CppUnit::TextUi::TestRunner runner;
  371. if (argc==2)
  372. {
  373. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
  374. runner.addTest( registry.makeTest() );
  375. }
  376. else
  377. {
  378. // MORE - maybe add a 'list' function here?
  379. for (int name = 2; name < argc; name++)
  380. {
  381. if (stricmp(argv[name], "-q")==0)
  382. {
  383. traceLevel = 0;
  384. roxiemem::memTraceLevel = 0;
  385. removeLog();
  386. }
  387. else
  388. {
  389. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
  390. runner.addTest( registry.makeTest() );
  391. }
  392. }
  393. }
  394. bool wasSucessful = runner.run( "", false );
  395. releaseAtoms();
  396. return wasSucessful;
  397. }
  398. #endif
  399. #ifdef _DEBUG
  400. #ifdef _WIN32
  401. _CrtSetAllocHook(myhook);
  402. #endif
  403. #endif
  404. #ifndef __64BIT__
  405. Thread::setDefaultStackSize(0x10000); // NB under windows requires linker setting (/stack:)
  406. #endif
  407. srand( (unsigned)time( NULL ) );
  408. ccdChannels = createPTree("Channels");
  409. char currentDirectory[_MAX_DIR];
  410. if (!getcwd(currentDirectory, sizeof(currentDirectory)))
  411. throw MakeStringException(ROXIE_INTERNAL_ERROR, "getcwd failed (%d)", errno);
  412. codeDirectory.set(currentDirectory);
  413. addNonEmptyPathSepChar(codeDirectory);
  414. try
  415. {
  416. Owned<IProperties> globals = createProperties(true);
  417. for (int i = 1; i < argc; i++)
  418. globals->loadProp(argv[i], true);
  419. Owned<IFile> sentinelFile = createSentinelTarget();
  420. removeSentinelFile(sentinelFile);
  421. if (globals->hasProp("--topology"))
  422. globals->getProp("--topology", topologyFile);
  423. else
  424. topologyFile.append(codeDirectory).append(PATHSEPCHAR).append("RoxieTopology.xml");
  425. if (checkFileExists(topologyFile.str()))
  426. {
  427. DBGLOG("Loading topology file %s", topologyFile.str());
  428. topology = createPTreeFromXMLFile(topologyFile.str());
  429. }
  430. else
  431. {
  432. if (globals->hasProp("--topology"))
  433. {
  434. // Explicitly-named topology file SHOULD exist...
  435. throw MakeStringException(ROXIE_INVALID_TOPOLOGY, "topology file %s not found", topologyFile.str());
  436. }
  437. topology=createPTreeFromXMLString(
  438. "<RoxieTopology localSlave='1'>"
  439. " <RoxieFarmProcess/>"
  440. " <RoxieServerProcess netAddress='.'/>"
  441. "</RoxieTopology>"
  442. );
  443. int port = globals->getPropInt("--port", 9876);
  444. topology->setPropInt("RoxieFarmProcess/@port", port);
  445. topology->setProp("@daliServers", globals->queryProp("--daliServers"));
  446. topology->setProp("@traceLevel", globals->queryProp("--traceLevel"));
  447. topology->setProp("@memTraceLevel", globals->queryProp("--memTraceLevel"));
  448. }
  449. topology->getProp("@name", roxieName);
  450. Owned<const IQueryDll> standAloneDll;
  451. if (globals->hasProp("--loadWorkunit"))
  452. {
  453. StringBuffer workunitName;
  454. globals->getProp("--loadWorkunit", workunitName);
  455. standAloneDll.setown(createQueryDll(workunitName));
  456. }
  457. else
  458. {
  459. Owned<ILoadedDllEntry> dll = createExeDllEntry(argv[0]);
  460. if (checkEmbeddedWorkUnitXML(dll))
  461. {
  462. standAloneDll.setown(createExeQueryDll(argv[0]));
  463. runOnce = globals->getPropInt("--port", 0) == 0;
  464. }
  465. }
  466. traceLevel = topology->getPropInt("@traceLevel", runOnce ? 0 : 1);
  467. if (traceLevel > MAXTRACELEVEL)
  468. traceLevel = MAXTRACELEVEL;
  469. udpTraceLevel = topology->getPropInt("@udpTraceLevel", runOnce ? 0 : 1);
  470. roxiemem::memTraceLevel = topology->getPropInt("@memTraceLevel", runOnce ? 0 : 1);
  471. soapTraceLevel = topology->getPropInt("@soapTraceLevel", runOnce ? 0 : 1);
  472. miscDebugTraceLevel = topology->getPropInt("@miscDebugTraceLevel", 0);
  473. Linked<IPropertyTree> directoryTree = topology->queryPropTree("Directories");
  474. if (!directoryTree)
  475. {
  476. Owned<IPropertyTree> envFile = getHPCCEnvironment();
  477. if (envFile)
  478. directoryTree.set(envFile->queryPropTree("Software/Directories"));
  479. }
  480. if (directoryTree)
  481. {
  482. getConfigurationDirectory(directoryTree, "query", "roxie", roxieName, queryDirectory);
  483. for (unsigned replicationLevel = 0; replicationLevel < MAX_REPLICATION_LEVELS; replicationLevel++)
  484. {
  485. StringBuffer dataDir;
  486. StringBuffer dirId("data");
  487. if (replicationLevel)
  488. dirId.append(replicationLevel+1);
  489. if (getConfigurationDirectory(directoryTree, dirId, "roxie", roxieName, dataDir))
  490. setBaseDirectory(dataDir, replicationLevel, DFD_OSdefault);
  491. }
  492. }
  493. directoryTree.clear();
  494. //Logging stuff
  495. if (globals->getPropBool("--stdlog", traceLevel != 0) || topology->getPropBool("@forceStdLog", false))
  496. queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time | MSGFIELD_milliTime | MSGFIELD_thread | MSGFIELD_prefix);
  497. else
  498. removeLog();
  499. if (globals->hasProp("--logfile"))
  500. {
  501. Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(topology, "roxie");
  502. lf->setMaxDetail(TopDetail);
  503. lf->beginLogging();
  504. logDirectory.set(lf->queryLogDir());
  505. #ifdef _DEBUG
  506. unsigned useLogQueue = topology->getPropBool("@useLogQueue", false);
  507. #else
  508. unsigned useLogQueue = topology->getPropBool("@useLogQueue", true);
  509. #endif
  510. if (useLogQueue)
  511. {
  512. unsigned logQueueLen = topology->getPropInt("@logQueueLen", 512);
  513. unsigned logQueueDrop = topology->getPropInt("@logQueueDrop", 32);
  514. queryLogMsgManager()->enterQueueingMode();
  515. queryLogMsgManager()->setQueueDroppingLimit(logQueueLen, logQueueDrop);
  516. }
  517. if (globals->getPropBool("--enableSysLog",true))
  518. UseSysLogForOperatorMessages();
  519. }
  520. roxieMetrics.setown(createRoxieMetricsManager());
  521. Owned<IPropertyTreeIterator> userMetrics = topology->getElements("./UserMetric");
  522. ForEach(*userMetrics)
  523. {
  524. IPropertyTree &metric = userMetrics->query();
  525. const char *name = metric.queryProp("@name");
  526. const char *regex= metric.queryProp("@regex");
  527. if (name && regex)
  528. roxieMetrics->addUserMetric(name, regex);
  529. else
  530. throw MakeStringException(ROXIE_INTERNAL_ERROR, "Invalid UserMetric element in topology file - name or regex missing");
  531. }
  532. restarts = globals->getPropInt("--restarts", 0);
  533. const char *preferredSubnet = topology->queryProp("@preferredSubnet");
  534. if (preferredSubnet)
  535. {
  536. const char *preferredSubnetMask = topology->queryProp("@preferredSubnetMask");
  537. if (!preferredSubnetMask) preferredSubnetMask = "255.255.255.0";
  538. if (!setPreferredSubnet(preferredSubnet, preferredSubnetMask))
  539. throw MakeStringException(ROXIE_INTERNAL_ERROR, "Error setting preferred subnet %s mask %s", preferredSubnet, preferredSubnetMask);
  540. }
  541. if (restarts)
  542. {
  543. if (traceLevel)
  544. DBGLOG("Roxie restarting: restarts = %d build = %s", restarts, BUILD_TAG);
  545. setStartRuid(restarts);
  546. }
  547. else
  548. {
  549. if (traceLevel)
  550. {
  551. DBGLOG("Roxie starting, build = %s", BUILD_TAG);
  552. }
  553. }
  554. headRegionSize = topology->getPropInt("@headRegionSize", 50);
  555. ccdMulticastPort = topology->getPropInt("@multicastPort", CCD_MULTICAST_PORT);
  556. statsExpiryTime = topology->getPropInt("@statsExpiryTime", 3600);
  557. roxiemem::memTraceSizeLimit = (memsize_t) topology->getPropInt64("@memTraceSizeLimit", 0);
  558. callbackRetries = topology->getPropInt("@callbackRetries", 3);
  559. callbackTimeout = topology->getPropInt("@callbackTimeout", 5000);
  560. lowTimeout = topology->getPropInt("@lowTimeout", 10000);
  561. highTimeout = topology->getPropInt("@highTimeout", 2000);
  562. slaTimeout = topology->getPropInt("@slaTimeout", 2000);
  563. parallelLoopFlowLimit = topology->getPropInt("@parallelLoopFlowLimit", 100);
  564. perChannelFlowLimit = topology->getPropInt("@perChannelFlowLimit", 10);
  565. copyResources = topology->getPropBool("@copyResources", true);
  566. useRemoteResources = topology->getPropBool("@useRemoteResources", true);
  567. checkFileDate = topology->getPropBool("@checkFileDate", true);
  568. const char *lazyOpenMode = topology->queryProp("@lazyOpen");
  569. if (!lazyOpenMode || stricmp(lazyOpenMode, "smart")==0)
  570. lazyOpen = (restarts > 0);
  571. else
  572. lazyOpen = topology->getPropBool("@lazyOpen", false);
  573. bool useNasTranslation = topology->getPropBool("@useNASTranslation", true);
  574. if (useNasTranslation)
  575. {
  576. Owned<IPropertyTree> nas = envGetNASConfiguration(topology);
  577. envInstallNASHooks(nas);
  578. }
  579. localSlave = topology->getPropBool("@localSlave", false);
  580. doIbytiDelay = topology->getPropBool("@doIbytiDelay", true);
  581. minIbytiDelay = topology->getPropInt("@minIbytiDelay", 2);
  582. initIbytiDelay = topology->getPropInt("@initIbytiDelay", 50);
  583. allFilesDynamic = topology->getPropBool("@allFilesDynamic", false);
  584. crcResources = topology->getPropBool("@crcResources", false);
  585. ignoreOrphans = topology->getPropBool("@ignoreOrphans", true);
  586. chunkingHeap = topology->getPropBool("@chunkingHeap", true);
  587. readTimeout = topology->getPropInt("@readTimeout", 300);
  588. logFullQueries = topology->getPropBool("@logFullQueries", false);
  589. debugPermitted = topology->getPropBool("@debugPermitted", true);
  590. blindLogging = topology->getPropBool("@blindLogging", false);
  591. if (!blindLogging)
  592. logExcessiveSeeks = true;
  593. preloadOnceData = topology->getPropBool("@preloadOnceData", true);
  594. linuxYield = topology->getPropBool("@linuxYield", false);
  595. traceSmartStepping = topology->getPropBool("@traceSmartStepping", false);
  596. useMemoryMappedIndexes = topology->getPropBool("@useMemoryMappedIndexes", false);
  597. traceJHtreeAllocations = topology->getPropBool("@traceJHtreeAllocations", false);
  598. flushJHtreeCacheOnOOM = topology->getPropBool("@flushJHtreeCacheOnOOM", true);
  599. fastLaneQueue = topology->getPropBool("@fastLaneQueue", true);
  600. udpOutQsPriority = topology->getPropInt("@udpOutQsPriority", 0);
  601. udpSnifferEnabled = topology->getPropBool("@udpSnifferEnabled", true);
  602. udpInlineCollation = topology->getPropBool("@udpInlineCollation", false);
  603. udpInlineCollationPacketLimit = topology->getPropInt("@udpInlineCollationPacketLimit", 50);
  604. udpSendCompletedInData = topology->getPropBool("@udpSendCompletedInData", false);
  605. udpRetryBusySenders = topology->getPropInt("@udpRetryBusySenders", 0);
  606. udpMaxRetryTimedoutReqs = topology->getPropInt("@udpMaxRetryTimedoutReqs", 0);
  607. udpRequestToSendTimeout = topology->getPropInt("@udpRequestToSendTimeout", 5);
  608. // MORE: think of a better way/value/check maybe/and/or based on Roxie server timeout
  609. if (udpRequestToSendTimeout == 0)
  610. udpRequestToSendTimeout = 5;
  611. // This is not added to deployment\xmlenv\roxie.xsd on purpose
  612. enableSocketMaxSetting = topology->getPropBool("@enableSocketMaxSetting", false);
  613. // MORE: might want to check socket buffer sizes against sys max here instead of udp threads ?
  614. udpMulticastBufferSize = topology->getPropInt("@udpMulticastBufferSize", 262142);
  615. udpFlowSocketsSize = topology->getPropInt("@udpFlowSocketsSize", 131072);
  616. udpLocalWriteSocketSize = topology->getPropInt("@udpLocalWriteSocketSize", 1024000);
  617. roxieMulticastEnabled = topology->getPropBool("@roxieMulticastEnabled", true); // enable use of multicast for sending requests to slaves
  618. if (udpSnifferEnabled && !roxieMulticastEnabled)
  619. DBGLOG("WARNING: ignoring udpSnifferEnabled setting as multicast not enabled");
  620. indexReadChunkSize = topology->getPropInt("@indexReadChunkSize", 60000);
  621. numSlaveThreads = topology->getPropInt("@slaveThreads", 30);
  622. numServerThreads = topology->getPropInt("@serverThreads", 30);
  623. numRequestArrayThreads = topology->getPropInt("@requestArrayThreads", 5);
  624. maxBlockSize = topology->getPropInt("@maxBlockSize", 10000000);
  625. maxLockAttempts = topology->getPropInt("@maxLockAttempts", 5);
  626. enableHeartBeat = topology->getPropBool("@enableHeartBeat", true);
  627. checkCompleted = topology->getPropBool("@checkCompleted", true);
  628. preabortKeyedJoinsThreshold = topology->getPropInt("@preabortKeyedJoinsThreshold", 100);
  629. preabortIndexReadsThreshold = topology->getPropInt("@preabortIndexReadsThreshold", 100);
  630. defaultMemoryLimit = (memsize_t) topology->getPropInt64("@defaultMemoryLimit", 0);
  631. defaultTimeLimit[0] = (unsigned) topology->getPropInt64("@defaultLowPriorityTimeLimit", 0);
  632. defaultTimeLimit[1] = (unsigned) topology->getPropInt64("@defaultHighPriorityTimeLimit", 0);
  633. defaultTimeLimit[2] = (unsigned) topology->getPropInt64("@defaultSLAPriorityTimeLimit", 0);
  634. defaultWarnTimeLimit[0] = (unsigned) topology->getPropInt64("@defaultLowPriorityTimeWarning", 0);
  635. defaultWarnTimeLimit[1] = (unsigned) topology->getPropInt64("@defaultHighPriorityTimeWarning", 0);
  636. defaultWarnTimeLimit[2] = (unsigned) topology->getPropInt64("@defaultSLAPriorityTimeWarning", 0);
  637. defaultXmlReadFlags = topology->getPropBool("@defaultStripLeadingWhitespace", true) ? ptr_ignoreWhiteSpace : ptr_none;
  638. defaultParallelJoinPreload = topology->getPropInt("@defaultParallelJoinPreload", 0);
  639. defaultConcatPreload = topology->getPropInt("@defaultConcatPreload", 0);
  640. defaultFetchPreload = topology->getPropInt("@defaultFetchPreload", 0);
  641. defaultFullKeyedJoinPreload = topology->getPropInt("@defaultFullKeyedJoinPreload", 0);
  642. defaultKeyedJoinPreload = topology->getPropInt("@defaultKeyedJoinPreload", 0);
  643. defaultPrefetchProjectPreload = topology->getPropInt("@defaultPrefetchProjectPreload", 10);
  644. defaultCheckingHeap = topology->getPropInt("@checkingHeap", false); // NOTE - not in configmgr - too dangerous!
  645. diskReadBufferSize = topology->getPropInt("@diskReadBufferSize", 0x10000);
  646. fieldTranslationEnabled = topology->getPropBool("@fieldTranslationEnabled", false);
  647. pretendAllOpt = topology->getPropBool("@ignoreMissingFiles", false);
  648. memoryStatsInterval = topology->getPropInt("@memoryStatsInterval", 60);
  649. roxiemem::setMemoryStatsInterval(memoryStatsInterval);
  650. pingInterval = topology->getPropInt("@pingInterval", 0);
  651. socketCheckInterval = topology->getPropInt("@socketCheckInterval", 5000);
  652. memsize_t totalMemoryLimit = (memsize_t) topology->getPropInt64("@totalMemoryLimit", 0);
  653. bool allowHugePages = topology->getPropBool("@heapUseHugePages", false);
  654. if (!totalMemoryLimit)
  655. totalMemoryLimit = 1024 * 0x100000; // 1 Gb;
  656. roxiemem::setTotalMemoryLimit(allowHugePages, totalMemoryLimit, 0, NULL);
  657. traceStartStop = topology->getPropBool("@traceStartStop", false);
  658. traceServerSideCache = topology->getPropBool("@traceServerSideCache", false);
  659. timeActivities = topology->getPropBool("@timeActivities", true);
  660. clientCert.certificate.set(topology->queryProp("@certificateFileName"));
  661. clientCert.privateKey.set(topology->queryProp("@privateKeyFileName"));
  662. clientCert.passphrase.set(topology->queryProp("@passphrase"));
  663. useHardLink = topology->getPropBool("@useHardLink", false);
  664. maxFileAge[false] = topology->getPropInt("@localFilesExpire", (unsigned) -1);
  665. maxFileAge[true] = topology->getPropInt("@remoteFilesExpire", 60*60*1000);
  666. minFilesOpen[false] = topology->getPropInt("@minLocalFilesOpen", 2000);
  667. minFilesOpen[true] = topology->getPropInt("@minRemoteFilesOpen", 500);
  668. maxFilesOpen[false] = topology->getPropInt("@maxLocalFilesOpen", 4000);
  669. maxFilesOpen[true] = topology->getPropInt("@maxRemoteFilesOpen", 1000);
  670. dafilesrvLookupTimeout = topology->getPropInt("@dafilesrvLookupTimeout", 10000);
  671. topology->getProp("@daliServers", fileNameServiceDali);
  672. trapTooManyActiveQueries = topology->getPropBool("@trapTooManyActiveQueries", true);
  673. maxEmptyLoopIterations = topology->getPropInt("@maxEmptyLoopIterations", 1000);
  674. maxGraphLoopIterations = topology->getPropInt("@maxGraphLoopIterations", 1000);
  675. useTreeCopy = topology->getPropBool("@useTreeCopy", true);
  676. mergeSlaveStatistics = topology->getPropBool("@mergeSlaveStatistics", true);
  677. enableKeyDiff = topology->getPropBool("@enableKeyDiff", true);
  678. // MORE: Get parms from topology after it is populated from Hardware/computer types section in configenv
  679. // Then if does not match and based on desired action in topolgy, either warn, or fatal exit or .... etc
  680. // Also get prim path and sec from topology
  681. #ifdef _WIN32
  682. getHardwareInfo(hdwInfo, "C:", "D:");
  683. #else // linux
  684. getHardwareInfo(hdwInfo, "/c$", "/d$");
  685. #endif
  686. if (traceLevel)
  687. {
  688. DBGLOG("Current Hardware Info: CPUs=%i, speed=%i MHz, Mem=%i MB , primDisk=%i GB, primFree=%i GB, secDisk=%i GB, secFree=%i GB, NIC=%i",
  689. hdwInfo.numCPUs, hdwInfo.CPUSpeed, hdwInfo.totalMemory,
  690. hdwInfo.primDiskSize, hdwInfo.primFreeSize, hdwInfo.secDiskSize, hdwInfo.secFreeSize, hdwInfo.NICSpeed);
  691. }
  692. parallelAggregate = topology->getPropInt("@parallelAggregate", 0);
  693. if (!parallelAggregate)
  694. parallelAggregate = hdwInfo.numCPUs;
  695. if (!parallelAggregate)
  696. parallelAggregate = 1;
  697. simpleLocalKeyedJoins = topology->getPropBool("@simpleLocalKeyedJoins", true);
  698. inMemoryKeysEnabled = topology->getPropBool("@inMemoryKeysEnabled", true);
  699. serverSideCacheSize = topology->getPropInt("@serverSideCacheSize", 0);
  700. setKeyIndexCacheSize((unsigned)-1); // unbound
  701. nodeCachePreload = topology->getPropBool("@nodeCachePreload", false);
  702. setNodeCachePreload(nodeCachePreload);
  703. nodeCacheMB = topology->getPropInt("@nodeCacheMem", 100);
  704. setNodeCacheMem(nodeCacheMB * 0x100000);
  705. leafCacheMB = topology->getPropInt("@leafCacheMem", 50);
  706. setLeafCacheMem(leafCacheMB * 0x100000);
  707. blobCacheMB = topology->getPropInt("@blobCacheMem", 0);
  708. setBlobCacheMem(blobCacheMB * 0x100000);
  709. minFreeDiskSpace = topology->getPropInt64("@minFreeDiskSpace", (1024 * 0x100000)); // default to 1 GB
  710. if (topology->getPropBool("@jumboFrames", false))
  711. {
  712. mtu_size = 9000; // upper limit on outbound buffer size - allow some header room too
  713. roxiemem::setDataAlignmentSize(0x2000);
  714. }
  715. else
  716. {
  717. mtu_size = 1400; // upper limit on outbound buffer size - allow some header room too
  718. roxiemem::setDataAlignmentSize(0x400);
  719. }
  720. unsigned pinterval = topology->getPropInt("@systemMonitorInterval",1000*60);
  721. if (pinterval)
  722. startPerformanceMonitor(pinterval);
  723. topology->getProp("@pluginDirectory", pluginDirectory);
  724. if (pluginDirectory.length() == 0)
  725. pluginDirectory.append(codeDirectory).append("plugins");
  726. if (queryDirectory.length() == 0)
  727. {
  728. topology->getProp("@queryDir", queryDirectory);
  729. if (queryDirectory.length() == 0)
  730. queryDirectory.append(codeDirectory).append("queries");
  731. }
  732. addNonEmptyPathSepChar(queryDirectory);
  733. queryFileCache().start();
  734. getTempFilePath(tempDirectory, "roxie", topology);
  735. #ifdef _WIN32
  736. topology->addPropBool("@linuxOS", false);
  737. #else
  738. topology->addPropBool("@linuxOS", true);
  739. #endif
  740. allQuerySetNames.appendListUniq(topology->queryProp("@querySets"), ",");
  741. Owned<IPropertyTreeIterator> roxieServers = topology->getElements("./RoxieServerProcess");
  742. ForEach(*roxieServers)
  743. {
  744. IPropertyTree &roxieServer = roxieServers->query();
  745. const char *iptext = roxieServer.queryProp("@netAddress");
  746. unsigned nodeIndex = addRoxieNode(iptext);
  747. if (getNodeAddress(nodeIndex).isLocal())
  748. myNodeIndex = nodeIndex;
  749. if (traceLevel > 3)
  750. DBGLOG("Roxie server %u is at %s", nodeIndex, iptext);
  751. }
  752. if (myNodeIndex == -1)
  753. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - current node is not in server list");
  754. // Set multicast base addresses - must be done before generating slave channels
  755. if (roxieMulticastEnabled && !localSlave)
  756. {
  757. if (topology->queryProp("@multicastBase"))
  758. multicastBase.ipset(topology->queryProp("@multicastBase"));
  759. else
  760. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - multicastBase not set");
  761. if (topology->queryProp("@multicastLast"))
  762. multicastLast.ipset(topology->queryProp("@multicastLast"));
  763. else
  764. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - multicastLast not set");
  765. }
  766. // Generate the slave channels
  767. unsigned numDataCopies = topology->getPropInt("@numDataCopies", 1);
  768. if (!numDataCopies)
  769. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - numDataCopies should be > 0");
  770. unsigned channelsPerNode = topology->getPropInt("@channelsPerNode", 1);
  771. unsigned numNodes = getNumNodes();
  772. const char *slaveConfig = topology->queryProp("@slaveConfig");
  773. if (!slaveConfig)
  774. slaveConfig = "simple";
  775. if (strnicmp(slaveConfig, "cyclic", 6) == 0)
  776. {
  777. numChannels = numNodes;
  778. unsigned cyclicOffset = topology->getPropInt("@cyclicOffset", 1);
  779. for (int i=0; i<numNodes; i++)
  780. {
  781. int channel = i+1;
  782. for (int copy=0; copy<numDataCopies; copy++)
  783. {
  784. if (channel > numNodes)
  785. channel = channel - numNodes;
  786. addChannel(i, channel, copy);
  787. channel = channel + cyclicOffset;
  788. }
  789. }
  790. }
  791. else if (strnicmp(slaveConfig, "overloaded", 10) == 0)
  792. {
  793. if (!channelsPerNode)
  794. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - channelsPerNode should be > 0");
  795. numChannels = numNodes * channelsPerNode;
  796. for (int i=0; i<numNodes; i++)
  797. {
  798. int channel = i+1;
  799. for (int copy=0; copy<channelsPerNode; copy++)
  800. {
  801. channel = channel + copy*numNodes;
  802. addChannel(i, channel, copy);
  803. }
  804. }
  805. }
  806. else // 'Full redundancy' or 'simple' mode
  807. {
  808. if (numNodes % numDataCopies)
  809. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - numChannels not an integer");
  810. numChannels = numNodes / numDataCopies;
  811. int channel = 1;
  812. for (int i=0; i<numNodes; i++)
  813. {
  814. addChannel(i, channel, 0);
  815. channel++;
  816. if (channel > numChannels)
  817. channel = 1;
  818. }
  819. }
  820. if (!numChannels)
  821. throw MakeStringException(MSGAUD_operator, ROXIE_INVALID_TOPOLOGY, "Invalid topology file - numChannels calculated at 0");
  822. // Now we know all the channels, we can open and subscribe the multicast channels
  823. if (!localSlave)
  824. openMulticastSocket();
  825. setDaliServixSocketCaching(true); // enable daliservix caching
  826. loadPlugins();
  827. globalPackageSetManager = createRoxiePackageSetManager(standAloneDll.getClear());
  828. globalPackageSetManager->load();
  829. unsigned snifferChannel = numChannels+2; // MORE - why +2 not +1 ??
  830. ROQ = createOutputQueueManager(snifferChannel, numSlaveThreads);
  831. ROQ->setHeadRegionSize(headRegionSize);
  832. ROQ->start();
  833. Owned<IPacketDiscarder> packetDiscarder = createPacketDiscarder();
  834. #if defined(WIN32) && defined(_DEBUG) && defined(_DEBUG_HEAP_FULL)
  835. int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
  836. tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
  837. _CrtSetDbgFlag( tmpFlag );
  838. #endif
  839. setSEHtoExceptionHandler(&abortHandler);
  840. if (runOnce)
  841. {
  842. Owned <IRoxieListener> roxieServer = createRoxieSocketListener(0, 1, 0, false);
  843. try
  844. {
  845. const char *format = globals->queryProp("format");
  846. if (!format)
  847. {
  848. if (globals->hasProp("-xml"))
  849. format = "xml";
  850. else if (globals->hasProp("-csv"))
  851. format = "csv";
  852. else if (globals->hasProp("-raw"))
  853. format = "raw";
  854. else
  855. format = "ascii";
  856. }
  857. StringBuffer query;
  858. query.appendf("<roxie format='%s'/>", format);
  859. roxieServer->runOnce(query.str()); // MORE - should use the wu listener instead I suspect
  860. fflush(stdout); // in windows if output is redirected results don't appear without flushing
  861. }
  862. catch (IException *E)
  863. {
  864. EXCLOG(E);
  865. E->Release();
  866. }
  867. }
  868. else
  869. {
  870. Owned<IPropertyTreeIterator> roxieFarms = topology->getElements("./RoxieFarmProcess");
  871. ForEach(*roxieFarms)
  872. {
  873. IPropertyTree &roxieFarm = roxieFarms->query();
  874. unsigned listenQueue = roxieFarm.getPropInt("@listenQueue", DEFAULT_LISTEN_QUEUE_SIZE);
  875. unsigned numThreads = roxieFarm.getPropInt("@numThreads", numServerThreads);
  876. unsigned port = roxieFarm.getPropInt("@port", ROXIE_SERVER_PORT);
  877. unsigned requestArrayThreads = roxieFarm.getPropInt("@requestArrayThreads", 5);
  878. if (!roxiePort)
  879. {
  880. roxiePort = port;
  881. ownEP.set(roxiePort, getNodeAddress(myNodeIndex));
  882. }
  883. bool suspended = roxieFarm.getPropBool("@suspended", false);
  884. Owned <IRoxieListener> roxieServer;
  885. if (port)
  886. roxieServer.setown(createRoxieSocketListener(port, numThreads, listenQueue, suspended));
  887. else
  888. roxieServer.setown(createRoxieWorkUnitListener(numThreads, suspended));
  889. const char *aclName = roxieFarm.queryProp("@aclName");
  890. if (aclName && *aclName)
  891. {
  892. Owned<IPropertyTree> aclInfo = createPTree("AccessInfo");
  893. getAccessList(aclName, topology, aclInfo);
  894. Owned<IPropertyTreeIterator> accesses = aclInfo->getElements("Access");
  895. ForEach(*accesses)
  896. {
  897. IPropertyTree &access = accesses->query();
  898. try
  899. {
  900. roxieServer->addAccess(access.getPropBool("@allow", true), access.getPropBool("@allowBlind", true), access.queryProp("@ip"), access.queryProp("@mask"), access.queryProp("@query"), access.queryProp("@error"), access.getPropInt("@errorCode"));
  901. }
  902. catch (IException *E)
  903. {
  904. StringBuffer s, x;
  905. E->errorMessage(s);
  906. E->Release();
  907. toXML(&access, x, 0, 0);
  908. throw MakeStringException(ROXIE_ACL_ERROR, "Error in access statement %s: %s", x.str(), s.str());
  909. }
  910. }
  911. }
  912. socketListeners.append(*roxieServer.getLink());
  913. time(&startupTime);
  914. roxieServer->start();
  915. }
  916. writeSentinelFile(sentinelFile);
  917. DBGLOG("Waiting for queries");
  918. if (pingInterval)
  919. startPingTimer();
  920. LocalIAbortHandler abortHandler(waiter);
  921. waiter.wait();
  922. }
  923. shuttingDown = true;
  924. if (pingInterval)
  925. stopPingTimer();
  926. setSEHtoExceptionHandler(NULL);
  927. while (socketListeners.isItem(0))
  928. {
  929. socketListeners.item(0).stop(1000);
  930. socketListeners.remove(0);
  931. }
  932. packetDiscarder->stop();
  933. packetDiscarder.clear();
  934. ROQ->stop();
  935. ROQ->join();
  936. ROQ->Release();
  937. ROQ = NULL;
  938. }
  939. catch (IException *E)
  940. {
  941. StringBuffer x;
  942. DBGLOG("EXCEPTION: (%d): %s", E->errorCode(), E->errorMessage(x).str());
  943. E->Release();
  944. }
  945. roxieMetrics.clear();
  946. stopPerformanceMonitor();
  947. ::Release(globalPackageSetManager);
  948. globalPackageSetManager = NULL;
  949. cleanupPlugins();
  950. closeMulticastSockets();
  951. releaseSlaveDynamicFileCache();
  952. releaseRoxieStateCache();
  953. setDaliServixSocketCaching(false); // make sure it cleans up or you get bogus memleak reports
  954. setNodeCaching(false); // ditto
  955. strdup("Make sure leak checking is working");
  956. UseSysLogForOperatorMessages(false);
  957. ExitModuleObjects();
  958. releaseAtoms();
  959. strdup("Make sure leak checking is working");
  960. #ifdef _WIN32
  961. #ifdef _DEBUG
  962. #if 1
  963. StringBuffer leakFileDir(logDirectory.str());
  964. leakFileDir.append("roxieleaks.log");
  965. HANDLE h = CreateFile(leakFileDir.str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
  966. _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE|_CRTDBG_MODE_DEBUG);
  967. _CrtSetReportFile( _CRT_WARN, h);
  968. _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE|_CRTDBG_MODE_DEBUG);
  969. _CrtSetReportFile( _CRT_ERROR, h);
  970. _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE|_CRTDBG_MODE_DEBUG);
  971. _CrtSetReportFile( _CRT_ASSERT, h);
  972. // _CrtDumpMemoryLeaks(); if you uncomment these lines you get to see the leaks sooner (so can look in debugger at full memory)
  973. // CloseHandle(h); but there will be additional leaks reported that are not really leaks
  974. #endif
  975. #endif
  976. #endif
  977. return 0;
  978. }