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

session->drop() SEGFAULT crash while recreating index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • WT2.7.0
    • Affects Version/s: WT2.6.1
    • Component/s: None
    • None

      Hi!

      I got a crash while recreating index:

      #include <assert.h>
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      
      #include <wiredtiger.h>
      
      #define WT_HOME "db"
      
      #define WT_CALL(call) \
          do { \
              const int __rc = call; \
              if (__rc != 0) { \
                  fprintf(stderr, # call " at (%s:%d) failed: %s [%d]\n", __FILE__, __LINE__, wiredtiger_strerror(__rc), __rc); \
                  exit(EXIT_FAILURE); \
              } \
          } while (0)
      
      static int
      me(WT_EXTRACTOR *extractor, WT_SESSION *session,
          const WT_ITEM *key, const WT_ITEM *value,
          WT_CURSOR *result_cursor)
      {
          //some extractor
          //it's not called in this program
          exit(1);
      }
      
      static WT_EXTRACTOR my_extractor = {me, NULL, NULL};
      
      
      int
      main(void)
      {
          WT_CONNECTION *conn;
          WT_SESSION *session;
          WT_CURSOR *cursor;
      
          const char* idx1 = "index:main:aab";
          const char* idx2 = "index:main:aaa"; // "aaa" < "aab" by strcmp
      
      
          assert(system("rm -rf \"" WT_HOME "\" && mkdir \"" WT_HOME "\"") == 0);
      
          WT_CALL(wiredtiger_open(WT_HOME, NULL, "create", &conn));
          WT_CALL(conn->open_session(conn, NULL, NULL, &session));
      
      
          WT_CALL(session->create(session, "table:main", "columns=(k,v)"));
      
      
          WT_CALL(conn->add_extractor(conn, "ex1", &my_extractor, NULL));
          WT_CALL(conn->add_extractor(conn, "ex2", &my_extractor, NULL));
      
          //create both indexes
          WT_CALL(session->create(session, idx1, "extractor=ex1,key_format=u"));
          WT_CALL(session->create(session, idx2, "extractor=ex2,key_format=u"));
      
          //recreate index 1
          WT_CALL(session->drop(session, idx1, "force=true"));
          WT_CALL(session->create(session, idx1, "extractor=ex1,key_format=u"));
      
          //recreate index 2
          WT_CALL(session->drop(session, idx2, "force=true")); //crash
          WT_CALL(session->create(session, idx2, "extractor=ex2,key_format=u"));
      
          WT_CALL(conn->close(conn, NULL));
      
          return 0;
      }
      

      gdb backtrace is:

      Program received signal SIGSEGV, Segmentation fault.
      __wt_schema_get_index (session=0x7ffff290b900, uri=0x4016c6 "index:main:aaa", quiet=1, tablep=0x7fffffffde30, indexp=0x7fffffffde10)
          at /wiredtiger/2.6.1/src/src/schema/schema_open.c:572
      572                     if (strcmp(idx->name, uri) == 0) {
      
      #0  __wt_schema_get_index (session=0x7ffff290b900, uri=0x4016c6 "index:main:aaa", quiet=1, tablep=0x7fffffffde30, indexp=0x7fffffffde10)
          at /wiredtiger/2.6.1/src/src/schema/schema_open.c:572
      #1  0x00007ffff47ba780 in __drop_index (session=0x7ffff290b900, uri=0x4016c6 "index:main:aaa", cfg=<optimized out>, force=<optimized out>)
          at /wiredtiger/2.6.1/src/src/schema/schema_drop.c:88
      #2  __wt_schema_drop (session=0x7ffff290b900, uri=0x4016c6 "index:main:aaa", cfg=0x7fffffffde70)
          at /wiredtiger/2.6.1/src/src/schema/schema_drop.c:182
      #3  0x00007ffff47c40f7 in __session_drop (wt_session=0x7ffff290b900, uri=0x4016c6 "index:main:aaa", config=<optimized out>)
          at /wiredtiger/2.6.1/src/src/session/session_api.c:530
      #4  0x00000000004013d9 in main () at main.cpp:64
      
      

      Its look like __wt_schema_get_table() returns WT_TABLE structure with

      table->nindices > 0
      

      and

      table->indices[i] == NULL
      

      if recreating index in the same order as in the above code with indexes

      strcmp(idx1, idx2) > 0
      

            Assignee:
            donald.anderson@mongodb.com Donald Anderson
            Reporter:
            tonyozr Anton Dunaev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: