Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-191

race in session open/close/truncate

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: WT1.2
    • Component/s: None
    • Labels:

      Description

      Reported race in session open/close/truncate.

      Here's the test program.

      #include <string.h>
      #include <pthread.h>
      #include "wiredtiger.h"
       
      typedef struct {
          WT_CONNECTION* conn;
          long count;
          char table[64];
      } Arg;
       
      WT_SESSION*
      session_open(WT_CONNECTION* conn)
      {
          WT_SESSION* session;
          int rc = conn->open_session(conn, NULL, NULL, &session);
          if (rc != 0) {
              fprintf(stderr, "open session failed: %s\n", wiredtiger_strerror(rc));
              pthread_exit(0);
          }
          return session;
      }
       
      void
      session_close(WT_SESSION* session)
      {
          int rc = session->close(session, NULL);
          if (rc != 0) {
              fprintf(stderr, "close session failed: %s\n", wiredtiger_strerror(rc));
              pthread_exit(0);
          }
      }
       
      WT_CURSOR*
      cursor_open(WT_SESSION* session, const char* table)
      {
          WT_CURSOR* cursor;
          int rc = session->open_cursor(session, table, NULL, "overwrite,raw", &cursor);
          if (rc != 0) {
              fprintf(stderr, "open cursor failed: %s\n", wiredtiger_strerror(rc));
              pthread_exit(0);
          }
          return cursor;
      }
       
      void
      cursor_close(WT_CURSOR* cursor)
      {
          int rc = cursor->close(cursor);
          if (rc != 0) {
              fprintf(stderr, "close cursor failed: %s\n", wiredtiger_strerror(rc));
              pthread_exit(0);
          }
      }
       
      void
      check_empty(WT_SESSION* session, const char* table)
      {
          WT_CURSOR* cursor = cursor_open(session, table);
          int rc = cursor->next(cursor);
          if (rc != WT_NOTFOUND) {
              fprintf(stderr, "cursor next failed: %s\n", wiredtiger_strerror(rc));
              pthread_exit(0);
          }
          cursor_close(cursor);
      }
       
      void*
      thr(void* p)
      {
          Arg* arg = (Arg*)p;
          WT_CONNECTION* conn = arg->conn;
          WT_SESSION* session = session_open(conn);
          int rc = session->create(session, arg->table, NULL);
          if (rc != 0) {
              fprintf(stderr, "session create failed: %s\n", wiredtiger_strerror(rc));
              return 0;
          }
          session_close(session);
          while (arg->count--) {
              session = session_open(conn);
              check_empty(session, arg->table);
              session_close(session);
              session = session_open(conn);
              rc = session->truncate(session, arg->table, NULL, NULL, NULL);
              if (rc != 0) {
                  fprintf(stderr, "session truncate failed: %s\n", wiredtiger_strerror(rc));
                  return 0;
              }
              session_close(session);
          }
          return 0;
      }
       
      #define NUMTHREADS 64
       
      int
      main(int argc, char** argv)
      {
          WT_CONNECTION* conn;
          pthread_t thread[NUMTHREADS];
          Arg arg[NUMTHREADS];
          int i, rc;
       
          system("rm -rf wt && mkdir wt");
          rc = wiredtiger_open("wt", NULL, "create,cache_size=100MB,session_max=100", &conn);
          if (rc != 0) {
              fprintf(stderr, "connection open failed: %s\n", wiredtiger_strerror(rc));
              return 1;
          }
          for (i = 0; i < NUMTHREADS; ++i) {
              arg[i].conn = conn;
              arg[i].count = 200;
              memset(arg[i].table, 0, sizeof arg[i].table);
              sprintf(arg[i].table, "table:wt%050d", i);
              pthread_create(&thread[i], NULL, thr, &arg[i]);
          }
          for (i = 0; i < NUMTHREADS; ++i) {
              void* v;
              pthread_join(thread[i], &v);
          }
          return 0;
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                michael.cahill Michael Cahill
                Reporter:
                keith.bostic Keith Bostic
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: