dalidiag.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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 "jlib.hpp"
  15. #include "jmisc.hpp"
  16. #include "mpbase.hpp"
  17. #include "mpcomm.hpp"
  18. #include "daclient.hpp"
  19. #include "dadiags.hpp"
  20. #include "danqs.hpp"
  21. #include "dasds.hpp"
  22. #include "dadfs.hpp"
  23. #include "dautils.hpp"
  24. #include "jptree.hpp"
  25. #include "jlzw.hpp"
  26. #include "environment.hpp"
  27. static const char *cmds[] = { "locks", "sdsstats", "sdssubscribers", "connections", "threads", "mpqueue", "clients", "mpverify", "timeq", "cleanq", "timesds", "build", "sdsfetch", "dirparts", "sdssize", "nodeinfo", "slavenode", "backuplist", "save", NULL };
  28. void usage(const char *exe)
  29. {
  30. printf("USAGE: dalidiag <dali-ip> -command\n");
  31. printf("Commands:\n");
  32. printf("-locks -- list active SDS locks\n");
  33. printf("-sdsstats -- SDS statistics\n");
  34. printf("-sdssubscribers -- list active SDS subscribers\n");
  35. printf("-connections -- list SDS connections\n");
  36. printf("-allowlist -- list entries in allowlist\n");
  37. printf("-threads -- running threads\n");
  38. printf("-mpqueue -- list waiting MP queue items\n");
  39. printf("-clients -- list connected Dali clients\n");
  40. printf("-mpverify -- test MP connections and remove stale\n");
  41. printf(" (NB should not do on busy system!)\n");
  42. printf("-timeq -- time Dali named queue speed\n");
  43. printf("-cleanq -- remove empty queue names\n");
  44. printf("-timesds -- time SDS subscriptions\n");
  45. printf("-build -- list current build info\n");
  46. printf("-sdsfetch <xpath> -- get a SDS branch\n");
  47. printf(" (no externals, better to use daliadmin export)\n");
  48. printf("-sdssize -- calculate size of SDS branch\n");
  49. printf(" (NB don't do on large branch - may run out of memory!)\n");
  50. printf("-nodeinfo <ip> -- information about the given node (i.e cluster and part)\n");
  51. printf("-slavenode <cluster> <partno> -- lists IP of given part (0 for master)\n");
  52. printf("-backuplist <cluster> -- list of nodes and backup nodes in cluster\n");
  53. printf("-partlist <filename> [0|1] -- lists the part info for a file\n");
  54. printf(" the optional 0 or 1 is the copy\n");
  55. printf("-perf -- performance info\n");
  56. printf("-disconnect <ip>:<port> -- forcably disconnect a clients connection\n");
  57. printf("-permissions <logicalname> <user> <password> -- get file permissions\n");
  58. printf("-unlock <connection_id> [close] -- forcibly disconnect an sds lock\n");
  59. printf(" (use id's given by '-locks'\n");
  60. printf("-settracetransactions -- trace dali transactions\n");
  61. printf("-settraceslowtransactions <millisecond-threshold> -- trace slow dali transactions\n");
  62. printf("-cleartracetransactions -- stop tracing dali transactions\n");
  63. printf("-setldapflags <val> -- set LDAP flags\n");
  64. printf("-getldapflags -- get LDAP flags\n");
  65. printf("-save -- force Dali to save (will block all clients whilst saving)\n");
  66. }
  67. class CTestSDSSubscription : public CInterface, implements ISDSSubscription
  68. {
  69. public:
  70. Semaphore notifysem;
  71. IMPLEMENT_IINTERFACE;
  72. virtual void notify(SubscriptionId id, const char *xpath, SDSNotifyFlags flags, unsigned valueLen, const void *valueData)
  73. {
  74. notifysem.signal();
  75. }
  76. };
  77. #define MAXHISTORY 1000
  78. #define MININC (0.001)
  79. void timeQorSDS(bool timeq)
  80. {
  81. double *res = (double *)calloc(MAXHISTORY,sizeof(double));
  82. unsigned in=0;
  83. unsigned sz=0;
  84. double max=0;
  85. double av=0;
  86. char inc=' ';
  87. double last100av=0;
  88. double last100max=0;
  89. char last100inc=' ';
  90. double last10av=0;
  91. double last10max=0;
  92. char last10inc=' ';
  93. unsigned i=0;
  94. SocketEndpoint ep;
  95. ep.setLocalHost(0);
  96. MemoryBuffer mb;
  97. Owned<INamedQueueConnection> qconn;
  98. Owned<IRemoteConnection> sdsconn;
  99. IPropertyTree *sdsroot = NULL;
  100. Owned<IQueueChannel> channel;
  101. CTestSDSSubscription testsdssub;
  102. SubscriptionId sdssubid=0;
  103. StringBuffer subname;
  104. if (timeq) {
  105. StringBuffer qname("TESTINGQ_");
  106. ep.getUrlStr(qname);
  107. qconn.setown(createNamedQueueConnection(0));
  108. channel.setown(qconn->open(qname.str()));
  109. while (channel->probe()) {
  110. mb.clear();
  111. channel->get(mb);
  112. }
  113. mb.clear().append("Hello").append(i); // prime queue to always keep one item on it
  114. ep.serialize(mb);
  115. channel->put(mb);
  116. }
  117. else {
  118. subname.append("TESTSDS_");
  119. ep.getUrlStr(subname);
  120. StringBuffer fullname("TESTING/");
  121. fullname.append(subname);
  122. sdssubid = querySDS().subscribe(fullname.str(), testsdssub);
  123. sdsconn.setown(querySDS().connect("/TESTING", myProcessSession(), RTM_CREATE_QUERY, 1000000));
  124. sdsroot = sdsconn->queryRoot();
  125. }
  126. HiresTimer hrt;
  127. unsigned last = msTick();
  128. DBGLOG("last 10 last 100 last 1000 change");
  129. for (;;) {
  130. i++;
  131. hrt.reset();
  132. if (timeq) {
  133. mb.clear().append("Hello").append(i);
  134. ep.serialize(mb);
  135. channel->put(mb);
  136. channel->get(mb);
  137. }
  138. else {
  139. sdsroot->setPropInt(subname.str(),i++);
  140. sdsconn->commit();
  141. if (!testsdssub.notifysem.wait(1000*60))
  142. DBGLOG("Notify Timeout!");
  143. }
  144. res[in] = hrt.get();
  145. if (sz<MAXHISTORY)
  146. sz++;
  147. in++;
  148. if (in>=MAXHISTORY)
  149. in = 0;
  150. Sleep(500); // stop getting too busy
  151. if (msTick()-last>5000) {
  152. unsigned p=in;
  153. // first total ac
  154. unsigned j=0;
  155. double m=0;
  156. double a=0;
  157. for (j=0;j<sz;j++) {
  158. if (p==0)
  159. p = MAXHISTORY;
  160. p--;
  161. a+=res[p];
  162. if (res[p]>m)
  163. m = res[p];
  164. }
  165. a /= sz;
  166. if (av>0.0) {
  167. if (a>av+MININC) inc='+'; else if (a<av-MININC) inc='-'; else inc=' ';
  168. }
  169. av = a;
  170. max = m;
  171. unsigned s=(sz<10)?sz:10;
  172. p = in;
  173. j=0;
  174. m=0;
  175. a=0;
  176. for (j=0;j<s;j++) {
  177. if (p==0)
  178. p = MAXHISTORY;
  179. p--;
  180. a+=res[p];
  181. if (res[p]>m)
  182. m = res[p];
  183. }
  184. a /= s;
  185. if (last10av>0.0) {
  186. if (a>last10av+MININC) last10inc='+'; else if (a<last10av-MININC) last10inc='-'; else last10inc=' ';
  187. }
  188. last10av = a;
  189. last10max = m;
  190. s=(sz<100)?sz:100;
  191. p = in;
  192. j=0;
  193. m=0;
  194. a=0;
  195. for (j=0;j<s;j++) {
  196. if (p==0)
  197. p = MAXHISTORY;
  198. p--;
  199. a+=res[p];
  200. if (res[p]>m)
  201. m = res[p];
  202. }
  203. a /= s;
  204. if (last100av>0.0) {
  205. if (a>last100av+MININC) last100inc='+'; else if (a<last100av-MININC) last100inc='-'; else last100inc=' ';
  206. }
  207. last100av = a;
  208. last100max = m;
  209. DBGLOG("%.6f, %.6f, %.6f, (%c%c%c)",
  210. last10av,last100av,av,last10inc,last100inc,inc);
  211. last = msTick();
  212. }
  213. }
  214. free(res);
  215. if (sdssubid!=0)
  216. querySDS().unsubscribe(sdssubid);
  217. }
  218. void cleanq()
  219. {
  220. StringBuffer path("/Queues");
  221. Owned<IRemoteConnection> conn = querySDS().connect(path.str(),myProcessSession(),RTM_LOCK_WRITE, INFINITE);
  222. if (!conn) {
  223. UERRLOG("Could not connect to %s",path.str());
  224. return;
  225. }
  226. Owned<IPropertyTree> root = conn->getRoot();
  227. Owned<IPropertyTreeIterator> elems=root->getElements("Queue");
  228. ICopyArrayOf<IPropertyTree> toremove;
  229. ForEach(*elems.get()) {
  230. IPropertyTree& elem = elems->query();
  231. if (!elem.hasProp("Item[1]")) { // empty, lets delete
  232. toremove.append(elem);
  233. }
  234. }
  235. ForEachItemIn(i,toremove) {
  236. IPropertyTree &item=toremove.item(i);
  237. root->removeTree(&item);
  238. }
  239. conn->commit();
  240. elems.clear();
  241. root.clear();
  242. }
  243. void dirParts(const char *ip,const char *dir)
  244. {
  245. PROGLOG("No longer supported");
  246. /*
  247. SocketEndpoint ep(ip);
  248. Owned<IDirectoryPartIterator> iter = queryDistributedFileDirectory().getDirectoryPartIterator(dir, ep);
  249. ForEach(*iter) {
  250. StringBuffer tmp(iter->queryFileName());
  251. tmp.append('[').append(iter->partNum());
  252. if (iter->isReplicate())
  253. tmp.append('R');
  254. tmp.append(']');
  255. printf("%-30s %-48s\n",iter->queryPartName(),tmp.str());
  256. }
  257. */
  258. }
  259. void partInfo(const char *name,unsigned copy)
  260. {
  261. Owned<IDistributedFile> f = queryDistributedFileDirectory().lookup(name,UNKNOWN_USER, AccessMode::tbdRead, false, false, nullptr, defaultPrivilegedUser);
  262. if (f) {
  263. Owned<IDistributedFilePartIterator> parts = f->getIterator();
  264. unsigned partno = 0;
  265. ForEach(*parts) {
  266. partno++;
  267. IDistributedFilePart &part = parts->query();
  268. RemoteFilename fn;
  269. part.getFilename(fn,copy);
  270. StringBuffer buf;
  271. SocketEndpoint ep = fn.queryEndpoint();
  272. printf("%3d %10" I64F "d %5s\n",partno,part.queryAttributes().getPropInt64("@size", -1),fn.getRemotePath(buf).str());
  273. }
  274. }
  275. else
  276. UERRLOG("ERROR: %s not found", name);
  277. }
  278. void nodeInfo(const char *ip)
  279. {
  280. #ifndef _CONTAINERIZED
  281. Owned<IEnvironmentFactory> factory = getEnvironmentFactory(false);
  282. Owned<IConstEnvironment> env = factory->openEnvironment();
  283. Owned<IConstMachineInfo> machine = env->getMachineByAddress(ip);
  284. if (machine)
  285. {
  286. Owned<const IPropertyTree> machinePTree = &machine->getPTree();
  287. printf("Node: %s\n", ip);
  288. const char *name = machinePTree->queryProp("@name");
  289. printf("Name: %s\n", name);
  290. printf("State: %s\n", machinePTree->queryProp("@state"));
  291. Owned<const IPropertyTree> envPTree = &env->getPTree();
  292. Owned<IPropertyTreeIterator> clusters = envPTree->getElements("Software/ThorCluster");
  293. ForEach(*clusters)
  294. {
  295. const IPropertyTree &cluster = clusters->query();
  296. VStringBuffer xpath("ThorSlaveProcess[@computer=\"%s\"]", name);
  297. const IPropertyTree *slave = cluster.queryPropTree(xpath);
  298. if (slave)
  299. {
  300. printf("Cluster: %s\n", cluster.queryProp("@name"));
  301. printf("Id: %s\n", slave->queryProp("@name"));
  302. }
  303. }
  304. }
  305. else
  306. printf("ERROR: cannot find '%s' in Dali Environment\n",ip);
  307. #endif
  308. }
  309. void slaveNode(const char *thor,unsigned n)
  310. {
  311. StringBuffer tag;
  312. Owned<IRemoteConnection> conn = querySDS().connect("/Environment", myProcessSession(), 0, INFINITE);
  313. IPropertyTree* root = conn->queryRoot();
  314. StringBuffer query("Software/ThorCluster[@name=\"");
  315. query.append(thor).append("\"]");
  316. Owned<IPropertyTree> cluster = root->getPropTree(query.str());
  317. if (n==0) {
  318. tag.append("m1");
  319. printf("%s Master ",thor);
  320. }
  321. else {
  322. tag.append('s').append(n);
  323. printf("%s Slave %d ",thor,n);
  324. }
  325. if (cluster) {
  326. query.clear().append("ThorSlaveProcess[@name=\"").append(tag.str()).append("\"]");
  327. Owned<IPropertyTree> process = cluster->getPropTree(query.str());
  328. if (process) {
  329. const char *cname = process->queryProp("@computer");
  330. query.clear().append("Hardware/Computer[@name=\"").append(cname).append("\"]");
  331. Owned<IPropertyTree> machine = root->getPropTree(query.str());
  332. if (machine) {
  333. printf("on %s\n",machine->queryProp("@netAddress"));
  334. }
  335. else
  336. printf("%s IP not found in Environment(Error)\n",cname);
  337. }
  338. else
  339. printf("'%s' not found in %s Environment\n",tag.str(),thor);
  340. }
  341. else
  342. printf("cluster name not found in Environment\n");
  343. }
  344. void backupList(const char *cluster)
  345. {
  346. Owned<IGroup> group = queryNamedGroupStore().lookup(cluster);
  347. if (group) {
  348. unsigned n = group->ordinality();
  349. rank_t r;
  350. StringBuffer str;
  351. for (r=0;r<n;r++) {
  352. group->queryNode(r).endpoint().getUrlStr(str.clear());
  353. str.append(' ');
  354. group->queryNode((r+1)%n).endpoint().getUrlStr(str);
  355. printf("%s\n",str.str());
  356. }
  357. }
  358. else
  359. UERRLOG("Cluster %s not found", cluster);
  360. }
  361. void filePermissions(const char *lname,const char *username,const char *password)
  362. {
  363. Owned<IUserDescriptor> user = createUserDescriptor();
  364. user->set(username,password);
  365. SecAccessFlags perm=queryDistributedFileDirectory().getFilePermissions(lname,user);
  366. printf("Permissions for %s = %d\n",lname,perm);
  367. }
  368. void nqPingPong(const char *q,const char *q2)
  369. {
  370. if (q2) {
  371. Owned<INamedQueueConnection> qconn = createNamedQueueConnection(0);
  372. Owned<IQueueChannel> channel1=qconn->open(q);
  373. Owned<IQueueChannel> channel2=qconn->open(q2);
  374. MemoryBuffer mb;
  375. while (channel2->probe())
  376. channel2->get(mb.clear());
  377. for (;;) {
  378. Sleep(getRandom()%500);
  379. PROGLOG("queue put to %s",q);
  380. mb.clear().append(q2);
  381. channel1->put(mb);
  382. Sleep(getRandom()%500);
  383. PROGLOG("queue got from %s",q2);
  384. for (;;) {
  385. channel2->get(mb.clear(),60*1000);
  386. if (mb.length())
  387. break;
  388. PROGLOG("queue cycle");
  389. }
  390. }
  391. }
  392. class cThread: public Thread
  393. {
  394. public:
  395. const char *q;
  396. int num;
  397. int run() {
  398. MemoryBuffer mb;
  399. Owned<INamedQueueConnection> qconn = createNamedQueueConnection(0);
  400. Owned<IQueueChannel> channel1=qconn->open(q);
  401. while (channel1->probe())
  402. channel1->get(mb.clear());
  403. for (;;) {
  404. Sleep(getRandom()%1000);
  405. channel1->get(mb.clear(),60*1000);
  406. StringAttr replyq;
  407. if (mb.length()!=0) {
  408. mb.read(replyq);
  409. Owned<IQueueChannel> channel2=qconn->open(replyq);
  410. PROGLOG("queue %d got",num);
  411. Sleep(getRandom()%1000);
  412. mb.clear().append("Hello");
  413. PROGLOG("queue %d put to %s",num,replyq.get());
  414. channel2->put(mb);
  415. }
  416. else
  417. PROGLOG("queue %d cycle",num);
  418. }
  419. return 0;
  420. }
  421. } threads[2];
  422. threads[0].q = q;
  423. threads[0].num = 1;
  424. threads[1].q = q;
  425. threads[1].num = 2;
  426. threads[0].start();
  427. threads[1].start();
  428. threads[0].join();
  429. threads[1].join();
  430. }
  431. static bool begins(const char *&ln,const char *pat)
  432. {
  433. size32_t sz = strlen(pat);
  434. if (memicmp(ln,pat,sz)==0) {
  435. ln += sz;
  436. return true;
  437. }
  438. return false;
  439. }
  440. // NB: there's strtoll under Linux
  441. static unsigned __int64 hextoll(const char *str, bool *error=NULL)
  442. {
  443. unsigned len = strlen(str);
  444. if (!len) return 0;
  445. unsigned __int64 factor = 1;
  446. unsigned __int64 rolling = 0;
  447. char *ptr = (char *)str+len-1;
  448. for (;;)
  449. {
  450. char c = *ptr;
  451. unsigned v;
  452. if (isdigit(c))
  453. v = c-'0';
  454. else if (c>='A' && c<='F')
  455. v = 10+(c-'A');
  456. else if (c>='a' && c<='f')
  457. v = 10+(c-'a');
  458. else
  459. {
  460. if (error)
  461. *error = true;
  462. return 0;
  463. }
  464. rolling += v * factor;
  465. factor <<= 4;
  466. if (ptr == str)
  467. break;
  468. --ptr;
  469. }
  470. if (error)
  471. *error = false;
  472. return rolling;
  473. }
  474. int main(int _argc, char* argv[])
  475. {
  476. unsigned argc = _argc;
  477. InitModuleObjects();
  478. EnableSEHtoExceptionMapping();
  479. SocketEndpoint ep;
  480. SocketEndpointArray epa;
  481. unsigned i;
  482. for (i=0;i<argc-1;i++) {
  483. if (argv[i+1][0]!='-') {
  484. ep.set(argv[i+1],DALI_SERVER_PORT);
  485. epa.append(ep);
  486. }
  487. else
  488. break;
  489. }
  490. if (argc<2 || !epa.ordinality())
  491. {
  492. usage(argv[0]);
  493. return 0;
  494. }
  495. try {
  496. Owned<IGroup> group = createIGroup(epa);
  497. assertex(group);
  498. initClientProcess(group, DCR_DaliDiag, 0, NULL, NULL, MP_WAIT_FOREVER);
  499. i++;
  500. for (; i <argc; i++)
  501. {
  502. const char *arg = argv[i];
  503. if ('-' == *arg)
  504. {
  505. ++arg;
  506. if (stricmp(arg,"timeq")==0) {
  507. timeQorSDS(true);
  508. break;
  509. }
  510. if (stricmp(arg,"timesds")==0) {
  511. timeQorSDS(false);
  512. break;
  513. }
  514. if (stricmp(arg,"cleanq")==0) {
  515. cleanq();
  516. break;
  517. }
  518. StringBuffer buf;
  519. if ((i+1<argc)&&(stricmp(arg,"sdsfetch")==0)) {
  520. MemoryBuffer mb;
  521. mb.append("sdsfetch").append(argv[++i]);
  522. getDaliDiagnosticValue(mb);
  523. Owned<IPropertyTree> pt = createPTree(mb);
  524. if (pt)
  525. toXML(pt,buf,2);
  526. printf("%s",buf.str());
  527. break;
  528. }
  529. if ((i+1<argc)&&(stricmp(arg,"sdssize")==0)) {
  530. MemoryBuffer mb;
  531. mb.append("sdssize").append(argv[++i]);
  532. getDaliDiagnosticValue(mb);
  533. size32_t ret;
  534. mb.read(ret);
  535. printf("Size %s = %d\n",argv[i],ret);
  536. break;
  537. }
  538. else if ((i+2<argc)&&(stricmp(arg,"dirparts")==0)) {
  539. dirParts(argv[i+1],argv[i+2]);
  540. break;
  541. }
  542. else if ((i+1<argc)&&(stricmp(arg,"nodeinfo")==0)) {
  543. nodeInfo(argv[i+1]);
  544. break;
  545. }
  546. else if ((i+2<argc)&&(stricmp(arg,"slavenode")==0)) {
  547. slaveNode(argv[i+1],atoi(argv[i+2]));
  548. break;
  549. }
  550. else if ((i+1<argc)&&(stricmp(arg,"backuplist")==0)) {
  551. backupList(argv[i+1]);
  552. break;
  553. }
  554. else if ((i+1<argc)&&(stricmp(arg,"partlist")==0)) {
  555. partInfo(argv[i+1],(i+2<argc)?atoi(argv[i+2]):0);
  556. break;
  557. }
  558. if ((i+1<argc)&&(stricmp(arg,"disconnect")==0)) {
  559. MemoryBuffer mb;
  560. mb.append("disconnect").append(argv[++i]);
  561. getDaliDiagnosticValue(mb);
  562. break;
  563. }
  564. if ((i+3<argc)&&(stricmp(arg,"permissions")==0)) {
  565. filePermissions(argv[i+1],argv[i+2],argv[i+3]);
  566. break;
  567. }
  568. if ((i+1<argc)&&(stricmp(arg,"nqpingpong")==0)) {
  569. nqPingPong(argv[i+1],i+2<argc?argv[i+2]:NULL);
  570. break;
  571. }
  572. if ((i+1<argc)&&(stricmp(arg,"unlock")==0)) {
  573. MemoryBuffer mb;
  574. __int64 connectionId;
  575. connectionId = hextoll(argv[i+1]);
  576. bool disconnect = (i+2<argc && 0==stricmp("close", argv[i+2]));
  577. mb.append("unlock").append(connectionId).append(disconnect);
  578. getDaliDiagnosticValue(mb);
  579. bool success;
  580. mb.read(success);
  581. StringBuffer connectionInfo;
  582. if (!success)
  583. PROGLOG("Lock not found");
  584. else
  585. {
  586. mb.read(connectionInfo);
  587. PROGLOG("Lock successfully removed: %s", connectionInfo.str());
  588. }
  589. break;
  590. }
  591. if ((i+1<argc)&&(stricmp(arg,"setldapflags")==0)) {
  592. MemoryBuffer mb;
  593. mb.append("setldapflags");
  594. unsigned f = (unsigned)atoi(argv[++i]);
  595. mb.append(f);
  596. getDaliDiagnosticValue(mb);
  597. printf("Dali LDAP flags set to %d\n",f);
  598. break;
  599. }
  600. if ((stricmp(arg,"getldapflags")==0)) {
  601. MemoryBuffer mb;
  602. mb.append("getldapflags");
  603. getDaliDiagnosticValue(mb);
  604. unsigned f;
  605. mb.read(f);
  606. printf("Dali LDAP flags = %d\n",f);
  607. break;
  608. }
  609. if ((stricmp(arg,"setsdsdebug")==0)) {
  610. MemoryBuffer mb;
  611. mb.append("setsdsdebug");
  612. unsigned n=argc-(i+1);
  613. mb.append(n);
  614. bool success = false;
  615. StringAttr reply;
  616. if (n)
  617. {
  618. while (n--)
  619. mb.append(argv[++i]);
  620. getDaliDiagnosticValue(mb);
  621. mb.read(success);
  622. mb.read(reply);
  623. }
  624. StringBuffer s("Dali setsdsdebug() call ");
  625. s.append(success?"successful":"failed");
  626. if (reply.length())
  627. s.append(" - ").append(reply);
  628. s.newline();
  629. printf("%s", s.str());
  630. break;
  631. }
  632. if (0 == stricmp(arg,"save")) {
  633. PROGLOG("Requesting SDS save");
  634. MemoryBuffer mb;
  635. mb.append("save");
  636. getDaliDiagnosticValue(mb);
  637. PROGLOG("SDS store saved");
  638. break;
  639. }
  640. if (0 == stricmp(arg, "locks")) {
  641. Owned<ILockInfoCollection> lockInfoCollection = querySDS().getLocks();
  642. lockInfoCollection->toString(buf);
  643. printf("\n%s:\n%s",arg,buf.str());
  644. break;
  645. }
  646. if (0 == stricmp(arg,"sdsstats")) {
  647. querySDS().getUsageStats(buf);
  648. printf("\n%s:\n%s",arg,buf.str());
  649. break;
  650. }
  651. if (0 == stricmp(arg, "connections")) {
  652. querySDS().getConnections(buf);
  653. printf("\n%s:\n%s",arg,buf.str());
  654. break;
  655. }
  656. if (0 == stricmp(arg, "sdssubscribers")) {
  657. querySDS().getSubscribers(buf);
  658. printf("\n%s:\n%s",arg,buf.str());
  659. break;
  660. }
  661. if ((stricmp(arg,"settraceslowtransactions")==0)) {
  662. MemoryBuffer mb;
  663. mb.append("settraceslowtransactions");
  664. unsigned slowThresholdMs = atoi(argv[++i]);
  665. mb.append(slowThresholdMs);
  666. getDaliDiagnosticValue(mb);
  667. StringAttr response;
  668. mb.read(response);
  669. printf("\nsettraceslowtransactions:\n%s", response.get());
  670. break;
  671. }
  672. else {
  673. for (;;) {
  674. getDaliDiagnosticValue(arg,buf.clear());
  675. if (stricmp(arg,"build")==0) {
  676. if (strcmp(buf.str(),"$I""d$")==0)
  677. buf.clear().append("Development");
  678. else if (strcmp(buf.str(),"UNKNOWN OPTION: build")==0)
  679. buf.clear().append("<=190a");
  680. }
  681. printf("\n%s:\n%s",arg,buf.str());
  682. if ((i+1<argc)&&(stricmp(arg,"perf")==0))
  683. Sleep(1000*atoi(argv[i+1]));
  684. else
  685. break;
  686. }
  687. }
  688. }
  689. else
  690. {
  691. usage(argv[0]);
  692. break;
  693. }
  694. }
  695. }
  696. catch (IException *e) {
  697. pexception("Exception",e);
  698. e->Release();
  699. }
  700. closedownClientProcess();
  701. releaseAtoms();
  702. return 0;
  703. }