4
0

ckptstress.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <pthread.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <errno.h>
  39. #include <unistd.h>
  40. #include <sys/types.h>
  41. #include <sys/socket.h>
  42. #include <sys/select.h>
  43. #include <sys/un.h>
  44. #include "saAis.h"
  45. #include "saCkpt.h"
  46. int ckptinv;
  47. struct thread_data {
  48. int thread_no;
  49. };
  50. void printSaNameT (SaNameT *name)
  51. {
  52. int i;
  53. for (i = 0; i < name->length; i++) {
  54. printf ("%c", name->value[i]);
  55. }
  56. }
  57. SaVersionT version = { 'B', 1, 1 };
  58. SaCkptCallbacksT callbacks = {
  59. 0,
  60. 0
  61. };
  62. SaNameT checkpointName = { 5, "abra\0" };
  63. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  64. SA_CKPT_WR_ALL_REPLICAS,
  65. 100000,
  66. 0,
  67. 5,
  68. 20000,
  69. 10
  70. };
  71. SaCkptSectionIdT sectionId1 = {
  72. 14,
  73. (SaUint8T *) "section ID #1"
  74. };
  75. SaCkptSectionIdT sectionId2 = {
  76. 14,
  77. (SaUint8T *) "section ID #2"
  78. };
  79. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  80. &sectionId1,
  81. 0xFFFFFFFF
  82. };
  83. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  84. &sectionId2,
  85. 0xFFFFFFFF
  86. };
  87. char readBuffer1[1025];
  88. char readBuffer2[1025];
  89. SaCkptIOVectorElementT ReadVectorElements[] = {
  90. {
  91. {
  92. 14,
  93. (SaUint8T *) "section ID #1"
  94. },
  95. readBuffer1,
  96. sizeof (readBuffer1),
  97. 0,
  98. 0
  99. },
  100. {
  101. {
  102. 14,
  103. (SaUint8T *) "section ID #2"
  104. },
  105. readBuffer2,
  106. sizeof (readBuffer2),
  107. 0,
  108. 0
  109. }
  110. };
  111. #define DATASIZE 250000
  112. char data[DATASIZE];
  113. SaCkptIOVectorElementT WriteVectorElements[] = {
  114. {
  115. {
  116. 14,
  117. (SaUint8T *) "section ID #1"
  118. },
  119. data, /*"written data #1, this should extend past end of old section data", */
  120. DATASIZE, /*sizeof ("written data #1, this should extend past end of old section data") + 1, */
  121. 0, //5,
  122. 0
  123. }
  124. #ifdef COMPILE_OUT
  125. {
  126. {
  127. 14,
  128. (SaUint8T *) "section ID #2"
  129. },
  130. data, /*"written data #2, this should extend past end of old section data" */
  131. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  132. 0, //3,
  133. 0
  134. }
  135. #endif
  136. };
  137. void *th_dispatch (void *arg)
  138. {
  139. struct thread_data *td = (struct thread_data *)arg;
  140. SaCkptHandleT ckptHandle;
  141. SaCkptCheckpointHandleT handle;
  142. SaAisErrorT error;
  143. int i;
  144. SaUint32T erroroneousVectorIndex = 0;
  145. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  146. error = saCkptCheckpointOpen (ckptHandle,
  147. &checkpointName,
  148. &checkpointCreationAttributes,
  149. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  150. 0,
  151. &handle);
  152. for (i = 0; i < 1000; i++) {
  153. error = saCkptCheckpointWrite (handle,
  154. WriteVectorElements,
  155. 1,
  156. &erroroneousVectorIndex);
  157. printf ("Thread %d: Attempt %d: error %d\n",
  158. td->thread_no, i, error);
  159. if (error != SA_AIS_OK) {
  160. printf ("Thread %d: Error from write.\n", td->thread_no);
  161. }
  162. }
  163. error = saCkptFinalize (ckptHandle);
  164. return (0);
  165. }
  166. int main (void) {
  167. SaCkptHandleT ckptHandle;
  168. SaCkptCheckpointHandleT checkpointHandle;
  169. SaAisErrorT error;
  170. int i;
  171. pthread_t dispatch_thread;
  172. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  173. error = saCkptCheckpointOpen (ckptHandle,
  174. &checkpointName,
  175. &checkpointCreationAttributes,
  176. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  177. 0,
  178. &checkpointHandle);
  179. printf ("first open result %d (should be 1)\n", error);
  180. error = saCkptSectionCreate (checkpointHandle,
  181. &sectionCreationAttributes1,
  182. "Initial Data #0",
  183. strlen ("Initial Data #0") + 1);
  184. printf ("create2 error is %d\n", error);
  185. error = saCkptSectionCreate (checkpointHandle,
  186. &sectionCreationAttributes2,
  187. "Initial Data #0",
  188. strlen ("Initial Data #0") + 1);
  189. printf ("create2 error is %d\n", error);
  190. for (i = 0; i < 40; i++) {
  191. struct thread_data *td;
  192. td = malloc (sizeof (struct thread_data));
  193. td->thread_no = i;
  194. pthread_create (&dispatch_thread, NULL, th_dispatch, td);
  195. }
  196. pthread_join (dispatch_thread, NULL);
  197. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  198. return (0);
  199. }