PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/storage/ndb/src/common/transporter/failoverSCI/failoverSCI.cpp

https://bitbucket.org/Habibutsu/mysql
C++ | 862 lines | 515 code | 198 blank | 149 comment | 131 complexity | 1f6a78b90d00cc9f24d657b05aba7e26 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /* Copyright (C) 2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #include <ndb_global.h>
  13. #include "sisci_types.h"
  14. #include "sisci_api.h"
  15. #include "sisci_error.h"
  16. //#include "sisci_demolib.h"
  17. #include <NdbTick.h>
  18. #include <NdbSleep.h>
  19. #define NO_CALLBACK NULL
  20. #define NO_FLAGS 0
  21. #define DATA_TRANSFER_READY 8
  22. sci_error_t error;
  23. sci_desc_t sdOne;
  24. sci_desc_t sdTwo;
  25. sci_local_segment_t localSegmentOne;
  26. sci_local_segment_t localSegmentTwo;
  27. sci_remote_segment_t remoteSegmentOne;
  28. sci_remote_segment_t remoteSegmentTwo;
  29. sci_map_t localMapOne;
  30. sci_map_t localMapTwo;
  31. sci_map_t remoteMapOne;
  32. sci_map_t remoteMapTwo;
  33. unsigned int localAdapterNo = 0;
  34. unsigned int standbyAdapterNo = 1;
  35. unsigned int localNodeId1;
  36. unsigned int localNodeId2;
  37. unsigned int remoteNodeId1 = 0;
  38. unsigned int remoteNodeId2 = 0;
  39. unsigned int localSegmentId;
  40. unsigned int remoteSegmentId1;
  41. unsigned int remoteSegmentId2;
  42. unsigned int segmentSize = 8192;
  43. unsigned int offset = 0;
  44. unsigned int client = 0;
  45. unsigned int server = 0;
  46. unsigned int *localbufferPtr;
  47. static int data;
  48. static int interruptConnected=0;
  49. /*********************************************************************************/
  50. /* U S A G E */
  51. /* */
  52. /*********************************************************************************/
  53. void Usage()
  54. {
  55. printf("Usage of shmem\n");
  56. printf("shmem -rn <remote node-id> -client/server [ -adapterno <adapter no> -size <segment size> ] \n\n");
  57. printf(" -rn : Remote node-id\n");
  58. printf(" -client : The local node is client\n");
  59. printf(" -server : The local node is server\n");
  60. printf(" -adapterno : Local adapter number (default %d)\n", localAdapterNo);
  61. printf(" -size : Segment block size (default %d)\n", segmentSize);
  62. printf(" -help : This helpscreen\n");
  63. printf("\n");
  64. }
  65. /*********************************************************************************/
  66. /* P R I N T P A R A M E T E R S */
  67. /* */
  68. /*********************************************************************************/
  69. void PrintParameters(void)
  70. {
  71. printf("Test parameters for %s \n",(client) ? "client" : "server" );
  72. printf("----------------------------\n\n");
  73. printf("Local node-id1 : %d\n",localNodeId1);
  74. printf("Local node-id2 : %d\n",localNodeId2);
  75. // printf("Remote node-id : %d\n",remoteNodeId);
  76. printf("Local adapter no. : %d\n",localAdapterNo);
  77. printf("Segment size : %d\n",segmentSize);
  78. printf("----------------------------\n\n");
  79. }
  80. /*********************************************************************************/
  81. /* F I L L S E G M E N T W I T H D A T A */
  82. /* */
  83. /*********************************************************************************/
  84. sci_error_t GetLocalNodeId(Uint32 localAdapterNo, Uint32* localNodeId)
  85. {
  86. sci_query_adapter_t queryAdapter;
  87. sci_error_t error;
  88. unsigned int _localNodeId;
  89. queryAdapter.subcommand = SCI_Q_ADAPTER_NODEID;
  90. queryAdapter.localAdapterNo = localAdapterNo;
  91. queryAdapter.data = &_localNodeId;
  92. SCIQuery(SCI_Q_ADAPTER,&queryAdapter,NO_FLAGS,&error);
  93. *localNodeId=_localNodeId;
  94. return error;
  95. }
  96. sci_error_t SendInterrupt(sci_desc_t sd,
  97. Uint32 localAdapterNo,
  98. Uint32 localSciNodeId,
  99. Uint32 remoteSciNodeId,
  100. Uint32 interruptNo){
  101. sci_error_t error;
  102. sci_remote_interrupt_t remoteInterrupt;
  103. Uint32 timeOut = SCI_INFINITE_TIMEOUT;
  104. // Now connect to the other sides interrupt flag
  105. do {
  106. SCIConnectInterrupt(sd, &remoteInterrupt, remoteSciNodeId, localAdapterNo,
  107. interruptNo, timeOut, NO_FLAGS, &error);
  108. } while (error != SCI_ERR_OK);
  109. if (error != SCI_ERR_OK) {
  110. fprintf(stderr, "SCIConnectInterrupt failed - Error code 0x%x\n", error);
  111. return error;
  112. }
  113. // Trigger interrupt
  114. printf("\nNode %u sent interrupt (0x%x) to node %d\n",localSciNodeId, interruptNo, remoteSciNodeId);
  115. SCITriggerInterrupt(remoteInterrupt, NO_FLAGS, &error);
  116. if (error != SCI_ERR_OK) {
  117. fprintf(stderr, "SCITriggerInterrupt failed - Error code 0x%x\n", error);
  118. return error;
  119. }
  120. // Disconnect and remove interrupts
  121. SCIDisconnectInterrupt(remoteInterrupt, NO_FLAGS, &error);
  122. if (error != SCI_ERR_OK) {
  123. fprintf(stderr, "SCIDisconnectInterrupt failed - Error code 0x%x\n", error);
  124. return error;
  125. }
  126. return error;
  127. }
  128. sci_error_t ReceiveInterrupt(sci_desc_t sd,
  129. Uint32 localAdapterNo,
  130. Uint32 localSciNodeId,
  131. Uint32 interruptNo,
  132. Uint32 timeout) {
  133. sci_error_t error;
  134. sci_local_interrupt_t localInterrupt;
  135. Uint32 timeOut = SCI_INFINITE_TIMEOUT;
  136. // Create an interrupt
  137. SCICreateInterrupt(sd, &localInterrupt, localAdapterNo,
  138. &interruptNo, 0, NULL, SCI_FLAG_FIXED_INTNO, &error);
  139. if (error != SCI_ERR_OK) {
  140. fprintf(stderr, "SCICreateInterrupt failed - Error code 0x%x\n", error);
  141. return error;
  142. }
  143. // Wait for an interrupt
  144. SCIWaitForInterrupt(localInterrupt, timeOut, NO_FLAGS, &error);
  145. printf("\nNode %u received interrupt (0x%x)\n", localSciNodeId, interruptNo);
  146. // Remove interrupt
  147. SCIRemoveInterrupt(localInterrupt, NO_FLAGS, &error);
  148. if (error != SCI_ERR_OK) {
  149. fprintf(stderr, "SCIRemoveInterrupt failed - Error code 0x%x\n", error);
  150. return error;
  151. }
  152. return error;
  153. }
  154. sci_error_t FillSegmentWithData(unsigned int segmentSize, int reverse)
  155. {
  156. unsigned int i;
  157. unsigned int nostores;
  158. nostores = (segmentSize) / sizeof(unsigned int);
  159. /* Allocate buffer */
  160. localbufferPtr = (unsigned int*)malloc( segmentSize );
  161. if ( localbufferPtr == NULL ) {
  162. /*
  163. * Unable to create local buffer - Insufficient memory available
  164. */
  165. return SCI_ERR_NOSPC;
  166. }
  167. if(reverse) {
  168. /* Fill in the data into a local buffer */
  169. printf("Filling forward order \n");
  170. for (i=0;i<nostores;i++) {
  171. localbufferPtr[i] = i;
  172. }
  173. }
  174. else {
  175. int temp=nostores;
  176. printf("Filling reverse order \n");
  177. for (i=0;i<nostores;i++) {
  178. localbufferPtr[i] = temp-- ;
  179. }
  180. }
  181. return SCI_ERR_OK;
  182. }
  183. /*********************************************************************************/
  184. /* P R I N T C L I E N T D A T A */
  185. /* */
  186. /*********************************************************************************/
  187. void PrintClientData(void)
  188. {
  189. unsigned int i;
  190. printf("\nClient data: ");
  191. /* Print the first 20 entries in the segment */
  192. for (i=0;i<20;i++) {
  193. printf("%d ",localbufferPtr[i]);
  194. }
  195. printf("\n");
  196. }
  197. /*********************************************************************************/
  198. /* P R I N T S E R V E R D A T A */
  199. /* */
  200. /*********************************************************************************/
  201. void PrintServerData(volatile unsigned int *localMapAddr)
  202. {
  203. unsigned int *buffer;
  204. int i;
  205. // printf("\nServer data: ");
  206. buffer = (unsigned int *)localMapAddr;
  207. /* Print the first 20 entries in the segment */
  208. for (i=0; i< 20; i++) {
  209. printf("%d ",buffer[i]);
  210. }
  211. printf("\n");
  212. }
  213. /*********************************************************************************/
  214. /* T R A N S F E R D A T A */
  215. /* */
  216. /*********************************************************************************/
  217. unsigned int TransferData(sci_map_t remoteMap,
  218. volatile unsigned int *remoteSegmentAddr1,
  219. volatile unsigned int *remoteSegmentAddr2,
  220. unsigned int segmentSize)
  221. {
  222. volatile unsigned int *remoteBuffer1;
  223. volatile unsigned int *remoteBuffer;
  224. volatile unsigned int *remoteBuffer2;
  225. static int times = 0;
  226. sci_sequence_t sequence;
  227. sci_error_t error;
  228. unsigned int nostores;
  229. unsigned int j;
  230. sci_sequence_status_t sequenceStatus;
  231. remoteBuffer1 = (volatile unsigned int *)remoteSegmentAddr1;
  232. remoteBuffer2 = (volatile unsigned int *)remoteSegmentAddr2;
  233. remoteBuffer=remoteBuffer1;
  234. /* 4-byte test only */
  235. nostores = (segmentSize) / sizeof(unsigned int);
  236. /* Create a sequence for data error checking */
  237. SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
  238. if (error != SCI_ERR_OK) {
  239. fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
  240. return error;
  241. }
  242. /* Fill in the data into a local buffer */
  243. error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
  244. error = FillSegmentWithData(segmentSize, 0);
  245. tryagain:
  246. PrintServerData(localbufferPtr);
  247. fprintf(stderr,"After recover \n");
  248. while(1){
  249. //data=0;
  250. if (error != SCI_ERR_OK) {
  251. /*
  252. * Unable to create local buffer - Insufficient memory available
  253. */
  254. printf( "Unable to create local buffer - Insufficient memory available\n" );
  255. return error;
  256. }
  257. do {
  258. /* Start data error checking */
  259. sequenceStatus = SCIStartSequence(sequence,NO_FLAGS,&error);
  260. } while (sequenceStatus != SCI_SEQ_OK) ;
  261. /* Transfer data to remote node */
  262. for (j=0;j<nostores;j++) {
  263. remoteBuffer[j] = localbufferPtr[j];
  264. }
  265. /* Check for error after data transfer */
  266. sequenceStatus = SCICheckSequence(sequence,NO_FLAGS,&error);
  267. if (sequenceStatus != SCI_SEQ_OK) {
  268. fprintf(stderr,"Data transfer failed\n");
  269. if(times==0) {
  270. error = FillSegmentWithData(segmentSize, 1);
  271. SCICreateMapSequence(remoteMapTwo,&sequence,NO_FLAGS,&error);
  272. if (error != SCI_ERR_OK) {
  273. fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
  274. return error;
  275. return SCI_ERR_TRANSFER_FAILED;
  276. }
  277. }
  278. else
  279. {
  280. error = FillSegmentWithData(segmentSize, 0);
  281. /* Create a sequence for data error checking */
  282. SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
  283. if (error != SCI_ERR_OK) {
  284. fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
  285. return error;
  286. return SCI_ERR_TRANSFER_FAILED;
  287. }
  288. }
  289. fprintf(stderr,"Recovery \n");
  290. if(times==0)
  291. remoteBuffer=remoteBuffer2;
  292. else
  293. remoteBuffer=remoteBuffer1;
  294. times++;
  295. printf("remotebuffer %p times %d\n", remoteBuffer, times);
  296. goto tryagain;
  297. }
  298. int timeout=0;
  299. // error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
  300. // NdbSleep_MilliSleep(100);
  301. //error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout);
  302. }
  303. /* Remove the Sequence */
  304. SCIRemoveSequence(sequence,NO_FLAGS, &error);
  305. if (error != SCI_ERR_OK) {
  306. fprintf(stderr,"SCIRemoveSequence failed - Error code 0x%x\n",error);
  307. return error;
  308. }
  309. return SCI_ERR_OK;
  310. }
  311. /*********************************************************************************/
  312. /* S H M E M C L I E N T N O D E */
  313. /* */
  314. /*********************************************************************************/
  315. unsigned int ShmemClientNode(void)
  316. {
  317. volatile unsigned int *remoteMapAddr1;
  318. volatile unsigned int *remoteMapAddr2;
  319. printf("here?\n");
  320. /* Create a segmentId */
  321. remoteSegmentId1 = 1;//(remoteNodeId1 << 16) | localNodeId1;
  322. /* Connect to remote segment */
  323. printf("Connect to remote segment .... \n");
  324. printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
  325. do {
  326. SCIConnectSegment(sdOne,
  327. &remoteSegmentOne,
  328. remoteNodeId1,
  329. remoteSegmentId1,
  330. localAdapterNo,
  331. NO_CALLBACK,
  332. NULL,
  333. SCI_INFINITE_TIMEOUT,
  334. NO_FLAGS,
  335. &error);
  336. } while (error != SCI_ERR_OK);
  337. printf("connected\n");
  338. // remoteSegmentId2 = (remoteNodeId2 << 16) | localNodeId2;
  339. // printf("segid = %d\n",remoteSegmentId2 );
  340. printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
  341. do {
  342. SCIConnectSegment(sdTwo,
  343. &remoteSegmentTwo,
  344. remoteNodeId2,
  345. remoteSegmentId1,
  346. standbyAdapterNo,
  347. NO_CALLBACK,
  348. NULL,
  349. SCI_INFINITE_TIMEOUT,
  350. NO_FLAGS,
  351. &error);
  352. } while (error != SCI_ERR_OK);
  353. printf("connected 3\n");
  354. printf("Remote segment (id=0x%x) is connected.\n", remoteSegmentId2);
  355. /* Map remote segment to user space */
  356. remoteMapAddr1 = (unsigned int*)SCIMapRemoteSegment(remoteSegmentOne,&remoteMapOne,offset,segmentSize,NULL,NO_FLAGS,&error);
  357. if (error == SCI_ERR_OK) {
  358. printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId1, remoteMapAddr1);
  359. } else {
  360. fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
  361. return 0;
  362. }
  363. remoteMapAddr2 = (unsigned int *)SCIMapRemoteSegment(remoteSegmentTwo,&remoteMapTwo,offset,segmentSize,NULL,NO_FLAGS,&error);
  364. if (error == SCI_ERR_OK) {
  365. printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId2, remoteMapAddr2);
  366. } else {
  367. fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
  368. return 0;
  369. }
  370. /* Start data transfer and error checking */
  371. error = (sci_error_t)TransferData(remoteMapOne,remoteMapAddr1, remoteMapAddr2,segmentSize);
  372. if (error == SCI_ERR_OK) {
  373. printf("Data transfer done!\n\n");
  374. } else {
  375. fprintf(stderr,"Data transfer failed - Error code 0x%x\n\n",error);
  376. return 0;
  377. }
  378. /* Send an interrupt to remote node telling that the data transfer is ready */
  379. error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
  380. if (error == SCI_ERR_OK) {
  381. printf("\nInterrupt message sent to remote node\n");
  382. } else {
  383. printf("\nInterrupt synchronization failed\n");
  384. return 0;
  385. }
  386. PrintClientData();
  387. /* Unmap remote segment */
  388. SCIUnmapSegment(remoteMapOne,NO_FLAGS,&error);
  389. if (error == SCI_ERR_OK) {
  390. printf("The remote segment is unmapped\n");
  391. } else {
  392. fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
  393. return 0;
  394. }
  395. SCIUnmapSegment(remoteMapTwo,NO_FLAGS,&error);
  396. if (error == SCI_ERR_OK) {
  397. printf("The remote segment is unmapped\n");
  398. } else {
  399. fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
  400. return 0;
  401. }
  402. /* Disconnect segment */
  403. SCIDisconnectSegment(remoteSegmentOne,NO_FLAGS,&error);
  404. if (error == SCI_ERR_OK) {
  405. printf("The segment is disconnected\n");
  406. } else {
  407. fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error);
  408. return 0;
  409. }
  410. SCIDisconnectSegment(remoteSegmentTwo,NO_FLAGS,&error);
  411. if (error == SCI_ERR_OK) {
  412. printf("The segment is disconnected\n");
  413. } else {
  414. fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error);
  415. return 0;
  416. }
  417. return 1;
  418. }
  419. /*********************************************************************************/
  420. /* S H M E M S E R V E R N O D E */
  421. /* */
  422. /*********************************************************************************/
  423. unsigned int ShmemServerNode(void)
  424. {
  425. unsigned int *localMapAddr;
  426. /* Create a segmentId */
  427. localSegmentId =1;// (localNodeId1 << 16) | remoteNodeId1;
  428. /* Create local segment */
  429. SCICreateSegment(sdOne,&localSegmentOne,localSegmentId, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error);
  430. if (error == SCI_ERR_OK) {
  431. printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
  432. } else {
  433. fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error);
  434. return 0;
  435. }
  436. //localSegmentId = (localNodeId2 << 16) | remoteNodeId2;
  437. /*
  438. SCICreateSegment(sdTwo,&localSegmentTwo,localSegmentId+1, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error);
  439. if (error == SCI_ERR_OK) {
  440. printf("Local segment (id=%d, size=%d) is created (2). \n", localSegmentId, segmentSize);
  441. } else {
  442. fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error);
  443. return 0;
  444. }
  445. printf("segment one %p segment 2 %p\n", localSegmentOne, localSegmentTwo);
  446. */
  447. /* Prepare the segment */
  448. SCIPrepareSegment(localSegmentOne,localAdapterNo,NO_FLAGS,&error);
  449. if (error == SCI_ERR_OK) {
  450. printf("Local segment (id=%d, size=%d) is prepared. \n", localSegmentId, segmentSize);
  451. } else {
  452. fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error);
  453. return 0;
  454. }
  455. /* Prepare the segment */
  456. SCIPrepareSegment(localSegmentOne,standbyAdapterNo,NO_FLAGS,&error);
  457. if (error == SCI_ERR_OK) {
  458. printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
  459. } else {
  460. fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error);
  461. return 0;
  462. }
  463. /* Map local segment to user space */
  464. localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentOne,&localMapOne, offset,segmentSize, NULL,NO_FLAGS,&error);
  465. if (error == SCI_ERR_OK) {
  466. printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr);
  467. } else {
  468. fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error);
  469. return 0;
  470. }
  471. /* Map local segment to user space */
  472. /*
  473. localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentTwo,&localMapTwo, offset,segmentSize, NULL,NO_FLAGS,&error);
  474. if (error == SCI_ERR_OK) {
  475. printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr);
  476. printf("Local segment (id=%d) is mapped to user space.\n", localSegmentId);
  477. } else {
  478. fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error);
  479. return 0;
  480. }
  481. */
  482. /* Set the segment available */
  483. SCISetSegmentAvailable(localSegmentOne, localAdapterNo, NO_FLAGS, &error);
  484. if (error == SCI_ERR_OK) {
  485. printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
  486. } else {
  487. fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
  488. return 0;
  489. }
  490. SCISetSegmentAvailable(localSegmentOne, standbyAdapterNo, NO_FLAGS, &error);
  491. if (error == SCI_ERR_OK) {
  492. printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
  493. } else {
  494. fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
  495. return 0;
  496. }
  497. int timeout=0;
  498. error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout);
  499. if (error == SCI_ERR_OK) {
  500. printf("\nThe data transfer is ready\n");
  501. } else {
  502. printf("\nInterrupt synchronization failed\n");
  503. return 0;
  504. }
  505. again:
  506. // printf("Wait for the shared memory data transfer .....");
  507. /* Wait for interrupt signal telling that block transfer is ready */
  508. //printf("\nData transfer done!\n");
  509. //PrintClientData()
  510. PrintServerData(localMapAddr);
  511. /*Uint32 micros;
  512. Uint32 micros2;
  513. NDB_TICKS secs;
  514. NdbTick_CurrentMicrosecond(&secs, &micros);
  515. error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
  516. NdbTick_CurrentMicrosecond(&secs, &micros2);
  517. printf("TIME ELAPSED %d \n", micros2-micros);
  518. // NdbSleep_MilliSleep(100);
  519. */
  520. goto again;
  521. /* Unmap local segment */
  522. SCIUnmapSegment(localMapTwo,NO_FLAGS,&error);
  523. if (error == SCI_ERR_OK) {
  524. printf("The local segment is unmapped\n");
  525. } else {
  526. fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
  527. return 0;
  528. }
  529. /* Unmap local segment */
  530. SCIUnmapSegment(localMapOne,NO_FLAGS,&error);
  531. if (error == SCI_ERR_OK) {
  532. printf("The local segment is unmapped\n");
  533. } else {
  534. fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
  535. return 0;
  536. }
  537. /* Remove local segment */
  538. SCIRemoveSegment(localSegmentOne,NO_FLAGS,&error);
  539. if (error == SCI_ERR_OK) {
  540. printf("The local segment is removed\n");
  541. } else {
  542. fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error);
  543. return 0;
  544. }
  545. /* Remove local segment */
  546. SCIRemoveSegment(localSegmentTwo,NO_FLAGS,&error);
  547. if (error == SCI_ERR_OK) {
  548. printf("The local segment is removed\n");
  549. } else {
  550. fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error);
  551. return 0;
  552. }
  553. return 1;
  554. }
  555. /*********************************************************************************/
  556. /* M A I N */
  557. /* */
  558. /*********************************************************************************/
  559. int main(int argc,char *argv[])
  560. {
  561. int counter;
  562. printf("\n %s compiled %s : %s\n\n",argv[0],__DATE__,__TIME__);
  563. if (argc<3) {
  564. Usage();
  565. exit(-1);
  566. }
  567. /* Get the parameters */
  568. for (counter=1; counter<argc; counter++) {
  569. if (!strcmp("-rn",argv[counter])) {
  570. // remoteNodeId = strtol(argv[counter+1],(char **) NULL,10);
  571. continue;
  572. }
  573. if (!strcmp("-size",argv[counter])) {
  574. segmentSize = strtol(argv[counter+1],(char **) NULL,10);
  575. continue;
  576. }
  577. if (!strcmp("-adapterno",argv[counter])) {
  578. localAdapterNo = strtol(argv[counter+1],(char **) NULL,10);
  579. continue;
  580. }
  581. if (!strcmp("-client",argv[counter])) {
  582. client = 1;
  583. continue;
  584. }
  585. if (!strcmp("-server",argv[counter])) {
  586. server = 1;
  587. continue;
  588. }
  589. if (!strcmp("-help",argv[counter])) {
  590. Usage();
  591. exit(0);
  592. }
  593. }
  594. // if (remoteNodeId == 0) {
  595. // fprintf(stderr,"Remote node-id is not specified. Use -rn <remote node-id>\n");
  596. // exit(-1);
  597. //}
  598. if (server == 0 && client == 0) {
  599. fprintf(stderr,"You must specify a client node or a server node\n");
  600. exit(-1);
  601. }
  602. if (server == 1 && client == 1) {
  603. fprintf(stderr,"Both server node and client node is selected.\n");
  604. fprintf(stderr,"You must specify either a client or a server node\n");
  605. exit(-1);
  606. }
  607. /* Initialize the SISCI library */
  608. SCIInitialize(NO_FLAGS, &error);
  609. if (error != SCI_ERR_OK) {
  610. fprintf(stderr,"SCIInitialize failed - Error code: 0x%x\n",error);
  611. exit(error);
  612. }
  613. /* Open a file descriptor */
  614. SCIOpen(&sdOne,NO_FLAGS,&error);
  615. if (error != SCI_ERR_OK) {
  616. if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
  617. fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
  618. }
  619. fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
  620. exit(error);
  621. }
  622. /* Open a file descriptor */
  623. SCIOpen(&sdTwo,NO_FLAGS,&error);
  624. if (error != SCI_ERR_OK) {
  625. if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
  626. fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
  627. }
  628. fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
  629. exit(error);
  630. }
  631. /* Get local node-id */
  632. error = GetLocalNodeId(localAdapterNo, &localNodeId1);
  633. error = GetLocalNodeId(standbyAdapterNo, &localNodeId2);
  634. if (error != SCI_ERR_OK) {
  635. fprintf(stderr,"Could not find the local adapter %d\n", localAdapterNo);
  636. SCIClose(sdOne,NO_FLAGS,&error);
  637. SCIClose(sdTwo,NO_FLAGS,&error);
  638. exit(-1);
  639. }
  640. /* Print parameters */
  641. PrintParameters();
  642. if (client) {
  643. remoteNodeId1=324;
  644. remoteNodeId2=328;
  645. ShmemClientNode();
  646. } else {
  647. remoteNodeId1=452;
  648. remoteNodeId2=456;
  649. ShmemServerNode();
  650. }
  651. /* Close the file descriptor */
  652. SCIClose(sdOne,NO_FLAGS,&error);
  653. SCIClose(sdTwo,NO_FLAGS,&error);
  654. if (error != SCI_ERR_OK) {
  655. fprintf(stderr,"SCIClose failed - Error code: 0x%x\n",error);
  656. }
  657. /* Free allocated resources */
  658. SCITerminate();
  659. return SCI_ERR_OK;
  660. }