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

cursor::search loses key value after WT_NOTFOUND

    • Type: Icon: Task Task
    • Resolution: Done
    • WT2.4.0
    • Affects Version/s: None
    • Component/s: None
    • None

      As reported by Dmiti Shubin on wiredtiger-users:

      In http://source.wiredtiger.com/2.3.1/cursor_ops.html#cursor_error I can read

      "For cursor operations that expect a key to be set before the operation begins (including WT_CURSOR::search, WT_CURSOR::insert, WT_CURSOR::update and WT_CURSOR::remove), the application's key and value will not be cleared by an error."

      But it seems that cursor::search() drops key value.
      Simple test:

       $ cat a.c
      #include <assert.h>
      #include <stdio.h>
      #include <string.h>
      
      #include <wiredtiger.h>
      
      int main(void)
      {
          WT_CONNECTION *conn;
          WT_CURSOR *cursor;
          WT_SESSION *session;
          const char *key, *value;
          int ret;
      
          assert(wiredtiger_open(NULL, NULL, "create", &conn) == 0);
          assert(conn->open_session(conn, NULL, NULL, &session) == 0);
      
          assert(session->create(session, "table:access", "key_format=S,value_format=S") == 0);
      
          assert(session->open_cursor(session, "table:access", NULL, NULL, &cursor) == 0);
      
          cursor->set_key(cursor, "key1");
          assert(cursor->search(cursor) == WT_NOTFOUND);
      
          //cursor->set_key(cursor, "key1"); ///////////////////// FIX
          cursor->set_value(cursor, "value1");
      
          ret = cursor->update(cursor);
          if (ret != 0) {
              fprintf(stderr, "cursor::update: %s\n", wiredtiger_strerror(ret));
              return (ret);
          }
      
          return (ret);
      }
      $ gcc -lwiredtiger a.c
      $ ./a.out 
      [1410189429:594441][24047:00173c388f7f0000], file:access.wt, cursor.update: requires key be set: Invalid argument
      cursor::update: Invalid argument
      

      If I set the key before update it works as expected.
      Am I missing something?

            Assignee:
            michael.cahill@mongodb.com Michael Cahill (Inactive)
            Reporter:
            michael.cahill@mongodb.com Michael Cahill (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: