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