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

session->drop() SEGFAULT crash while recreating index

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: WT2.6.1
    • Fix Version/s: WT2.7.0
    • Labels:
      None
    • # Replies:
      4
    • Last comment by Customer:
      true

      Description

      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
      

        Activity

        Hide
        xgen-internal-githook Githook User added a comment -

        Author:

        {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

        Message: WT-2162. Add a null pointer check for the WT_TABLE.indices array.
        This array may be partially populated after an index is dropped.
        Branch: develop
        https://github.com/wiredtiger/wiredtiger/commit/d746adb7e1cce9f0532c311e788b0ab24155a4fe

        Show
        xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-2162 . Add a null pointer check for the WT_TABLE.indices array. This array may be partially populated after an index is dropped. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/d746adb7e1cce9f0532c311e788b0ab24155a4fe
        Hide
        xgen-internal-githook Githook User added a comment -

        Author:

        {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

        Message: WT-2162. Add a Python test equivalent to the reported test case.
        Branch: develop
        https://github.com/wiredtiger/wiredtiger/commit/419889ba63717c9e92a180aba695e81de947dc71

        Show
        xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-2162 . Add a Python test equivalent to the reported test case. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/419889ba63717c9e92a180aba695e81de947dc71
        Hide
        xgen-internal-githook Githook User added a comment -

        Author:

        {u'username': u'agorrod', u'name': u'Alex Gorrod', u'email': u'alexander.gorrod@mongodb.com'}

        Message: Merge pull request #2245 from wiredtiger/wt-2162-index-recreate

        WT-2162. Add null pointer check, needed after an index is dropped.
        Branch: develop
        https://github.com/wiredtiger/wiredtiger/commit/544f27de73419dbf4494b9ad826c643dfec38e6c

        Show
        xgen-internal-githook Githook User added a comment - Author: {u'username': u'agorrod', u'name': u'Alex Gorrod', u'email': u'alexander.gorrod@mongodb.com'} Message: Merge pull request #2245 from wiredtiger/wt-2162-index-recreate WT-2162 . Add null pointer check, needed after an index is dropped. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/544f27de73419dbf4494b9ad826c643dfec38e6c
        Hide
        michael.cahill Michael Cahill added a comment -

        Anton Dunaev, thank you for the bug report: you were correct and Don Anderson has pushed a fix to WiredTiger's develop branch. It will be in the next release of WiredTiger.

        I'm going to resolve this issue now. If you need anything else in relation to this bug, please reopen and follow up.

        Show
        michael.cahill Michael Cahill added a comment - Anton Dunaev , thank you for the bug report: you were correct and Don Anderson has pushed a fix to WiredTiger's develop branch. It will be in the next release of WiredTiger. I'm going to resolve this issue now. If you need anything else in relation to this bug, please reopen and follow up.

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              1 year, 24 weeks, 6 days ago
              Date of 1st Reply: