ckptstress.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 <errno.h>
  38. #include <unistd.h>
  39. #include <sys/types.h>
  40. #include <sys/socket.h>
  41. #include <sys/select.h>
  42. #include <sys/un.h>
  43. #include "ais_types.h"
  44. #include "saCkpt.h"
  45. int ckptinv;
  46. struct thread_data {
  47. int thread_no;
  48. };
  49. void printSaNameT (SaNameT *name)
  50. {
  51. int i;
  52. for (i = 0; i < name->length; i++) {
  53. printf ("%c", name->value[i]);
  54. }
  55. }
  56. SaVersionT version = { 'B', 1, 1 };
  57. SaCkptCallbacksT callbacks = {
  58. 0,
  59. 0
  60. };
  61. SaNameT checkpointName = { 5, "abra\0" };
  62. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  63. SA_CKPT_WR_ALL_REPLICAS,
  64. 100000,
  65. 0,
  66. 5,
  67. 20000,
  68. 10
  69. };
  70. SaCkptSectionIdT sectionId1 = {
  71. 14,
  72. "section ID #1"
  73. };
  74. SaCkptSectionIdT sectionId2 = {
  75. 14,
  76. "section ID #2"
  77. };
  78. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  79. &sectionId1,
  80. 0xFFFFFFFF
  81. };
  82. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  83. &sectionId2,
  84. 0xFFFFFFFF
  85. };
  86. char readBuffer1[1025];
  87. char readBuffer2[1025];
  88. SaCkptIOVectorElementT ReadVectorElements[] = {
  89. {
  90. {
  91. 14,
  92. "section ID #1"
  93. },
  94. readBuffer1,
  95. sizeof (readBuffer1),
  96. 0,
  97. 0
  98. },
  99. {
  100. {
  101. 14,
  102. "section ID #2"
  103. },
  104. readBuffer2,
  105. sizeof (readBuffer2),
  106. 0,
  107. 0
  108. }
  109. };
  110. #define DATASIZE 250000
  111. char data[DATASIZE];
  112. SaCkptIOVectorElementT WriteVectorElements[] = {
  113. {
  114. {
  115. 14,
  116. "section ID #1"
  117. },
  118. data, /*"written data #1, this should extend past end of old section data", */
  119. DATASIZE, /*sizeof ("written data #1, this should extend past end of old section data") + 1, */
  120. 0, //5,
  121. 0
  122. }
  123. #ifdef COMPILE_OUT
  124. {
  125. {
  126. 14,
  127. "section ID #2"
  128. },
  129. data, /*"written data #2, this should extend past end of old section data" */
  130. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  131. 0, //3,
  132. 0
  133. }
  134. #endif
  135. };
  136. void *th_dispatch (void *arg)
  137. {
  138. struct thread_data *td = (struct thread_data *)arg;
  139. SaCkptHandleT ckptHandle;
  140. SaCkptCheckpointHandleT handle;
  141. SaErrorT error;
  142. int i;
  143. SaUint32T erroroneousVectorIndex = 0;
  144. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  145. error = saCkptCheckpointOpen (ckptHandle,
  146. &checkpointName,
  147. &checkpointCreationAttributes,
  148. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  149. 0,
  150. &handle);
  151. for (i = 0; i < 1000; i++) {
  152. error = saCkptCheckpointWrite (handle,
  153. WriteVectorElements,
  154. 1,
  155. &erroroneousVectorIndex);
  156. printf ("Thread %d: Attempt %d: error %d\n",
  157. td->thread_no, i, error);
  158. if (error != SA_OK) {
  159. printf ("Thread %d: Error from write.\n", td->thread_no);
  160. }
  161. }
  162. error = saCkptFinalize (ckptHandle);
  163. return (0);
  164. }
  165. int main (void) {
  166. SaCkptHandleT ckptHandle;
  167. SaCkptCheckpointHandleT checkpointHandle;
  168. SaErrorT error;
  169. int i;
  170. pthread_t dispatch_thread;
  171. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  172. error = saCkptCheckpointOpen (ckptHandle,
  173. &checkpointName,
  174. &checkpointCreationAttributes,
  175. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  176. 0,
  177. &checkpointHandle);
  178. printf ("first open result %d (should be 1)\n", error);
  179. error = saCkptSectionCreate (checkpointHandle,
  180. &sectionCreationAttributes1,
  181. "Initial Data #0",
  182. strlen ("Initial Data #0") + 1);
  183. printf ("create2 error is %d\n", error);
  184. error = saCkptSectionCreate (checkpointHandle,
  185. &sectionCreationAttributes2,
  186. "Initial Data #0",
  187. strlen ("Initial Data #0") + 1);
  188. printf ("create2 error is %d\n", error);
  189. for (i = 0; i < 40; i++) {
  190. struct thread_data *td;
  191. td = malloc (sizeof (struct thread_data));
  192. td->thread_no = i;
  193. pthread_create (&dispatch_thread, NULL, th_dispatch, td);
  194. }
  195. pthread_join (dispatch_thread, NULL);
  196. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  197. return (0);
  198. }