Esempio n. 1
0
    def test_search_eot(self):
        # Populate the tree and reopen the connection, forcing it to disk
        # and moving the records to an on-page format.
        simple_populate(self, self.uri, self.fmt, 100)
        self.reopen_conn()

        # Open a cursor.
        cursor = self.session.open_cursor(self.uri, None)

        # Search for a record at the end of the table, which should succeed.
        cursor.set_key(key_populate(cursor, 100))
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))

        # Search-near for a record at the end of the table, which should
        # succeed, returning the last record.
        cursor.set_key(key_populate(cursor, 100))
        self.assertEqual(cursor.search_near(), 0)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))

        # Search for a record past the end of the table, which should fail.
        cursor.set_key(key_populate(cursor, 200))
        self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Search-near for a record past the end of the table, which should
        # succeed, returning the last record.
        cursor.set_key(key_populate(cursor, 200))
        self.assertEqual(cursor.search_near(), -1)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))
Esempio n. 2
0
    def test_bulk_load_col_delete(self):
        if self.keyfmt != 'r':
                return

        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 1000):
            if i % 7 == 0:
                cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Ensure we create all the missing records.
        i = i + 1
        cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)

        # Verify all the records are there, in their proper state.
        for i in range(1, 1000):
            cursor.set_key(key_populate(cursor, i))
            if i % 7 == 0:
                cursor.search()
                self.assertEqual(cursor.get_value(), value_populate(cursor, i))
            elif cursor.value_format == '8t':
                cursor.search()
                self.assertEqual(cursor.get_value(), 0)
            else:
                self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
Esempio n. 3
0
    def test_bulk_load_col_delete(self):
        if self.keyfmt != 'r':
            return

        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 1000):
            if i % 7 == 0:
                cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Ensure we create all the missing records.
        i = i + 1
        cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)

        # Verify all the records are there, in their proper state.
        for i in range(1, 1000):
            cursor.set_key(key_populate(cursor, i))
            if i % 7 == 0:
                cursor.search()
                self.assertEqual(cursor.get_value(), value_populate(cursor, i))
            elif cursor.value_format == '8t':
                cursor.search()
                self.assertEqual(cursor.get_value(), 0)
            else:
                self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
Esempio n. 4
0
    def test_search_eot(self):
        # Populate the tree and reopen the connection, forcing it to disk
        # and moving the records to an on-page format.
        simple_populate(self, self.uri, self.fmt, 100)
        self.reopen_conn()

        # Open a cursor.
        cursor = self.session.open_cursor(self.uri, None)

        # Search for a record at the end of the table, which should succeed.
        cursor.set_key(key_populate(cursor, 100))
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))

        # Search-near for a record at the end of the table, which should
        # succeed, returning the last record.
        cursor.set_key(key_populate(cursor, 100))
        self.assertEqual(cursor.search_near(), 0)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))

        # Search for a record past the end of the table, which should fail.
        cursor.set_key(key_populate(cursor, 200))
        self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Search-near for a record past the end of the table, which should
        # succeed, returning the last record.
        cursor.set_key(key_populate(cursor, 200))
        self.assertEqual(cursor.search_near(), -1)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 100))
        self.assertEqual(cursor.get_value(), value_populate(cursor, 100))
Esempio n. 5
0
    def test_search_invisible_two(self):
        uri = 'file:test_bug008'                # This is a btree layer test.

        # Populate the tree and reopen the connection, forcing it to disk
        # and moving the records to an on-page format.
        simple_populate(self, uri, self.fmt, 100) 
        self.reopen_conn()

        # Add some additional visible records.
        cursor = self.session.open_cursor(uri, None)
        for i in range(100, 120):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()
        cursor.close()

        # Begin a transaction, and add some additional records.
        self.session.begin_transaction()
        cursor = self.session.open_cursor(uri, None)
        for i in range(120, 140):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Open a separate session and cursor.
        s = self.conn.open_session()
        cursor = s.open_cursor(uri, None)

        # Search for an invisible record.
        cursor.set_key(key_populate(cursor, 130))
        if self.empty:
            # Invisible updates to fixed-length column-store objects are
            # invisible to the reader, but the fact that they exist past
            # the end of the initial records causes the instantiation of
            # empty records: confirm successful return of an empty row.
            cursor.search()
            self.assertEqual(cursor.get_key(), 130)
            self.assertEqual(cursor.get_value(), 0)
        else:
            # Otherwise, we should not find any matching records.
            self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Search-near for an invisible record, which should succeed, returning
        # the last visible record.
        cursor.set_key(key_populate(cursor, 130))
        cursor.search_near()
        if self.empty:
            # Invisible updates to fixed-length column-store objects are
            # invisible to the reader, but the fact that they exist past
            # the end of the initial records causes the instantiation of
            # empty records: confirm successful return of an empty row.
            cursor.search()
            self.assertEqual(cursor.get_key(), 130)
            self.assertEqual(cursor.get_value(), 0)
        else:
            # Otherwise, we should find the closest record for which we can see
            # the value.
            self.assertEqual(cursor.get_key(), key_populate(cursor, 119))
            self.assertEqual(cursor.get_value(), value_populate(cursor, 119))
Esempio n. 6
0
    def test_search_invisible_two(self):
        uri = 'file:test_bug008'  # This is a btree layer test.

        # Populate the tree and reopen the connection, forcing it to disk
        # and moving the records to an on-page format.
        simple_populate(self, uri, self.fmt, 100)
        self.reopen_conn()

        # Add some additional visible records.
        cursor = self.session.open_cursor(uri, None)
        for i in range(100, 120):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()
        cursor.close()

        # Begin a transaction, and add some additional records.
        self.session.begin_transaction()
        cursor = self.session.open_cursor(uri, None)
        for i in range(120, 140):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Open a separate session and cursor.
        s = self.conn.open_session()
        cursor = s.open_cursor(uri, None)

        # Search for an invisible record.
        cursor.set_key(key_populate(cursor, 130))
        if self.empty:
            # Invisible updates to fixed-length column-store objects are
            # invisible to the reader, but the fact that they exist past
            # the end of the initial records causes the instantiation of
            # empty records: confirm successful return of an empty row.
            cursor.search()
            self.assertEqual(cursor.get_key(), 130)
            self.assertEqual(cursor.get_value(), 0)
        else:
            # Otherwise, we should not find any matching records.
            self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Search-near for an invisible record, which should succeed, returning
        # the last visible record.
        cursor.set_key(key_populate(cursor, 130))
        cursor.search_near()
        if self.empty:
            # Invisible updates to fixed-length column-store objects are
            # invisible to the reader, but the fact that they exist past
            # the end of the initial records causes the instantiation of
            # empty records: confirm successful return of an empty row.
            cursor.search()
            self.assertEqual(cursor.get_key(), 130)
            self.assertEqual(cursor.get_value(), 0)
        else:
            # Otherwise, we should find the closest record for which we can see
            # the value.
            self.assertEqual(cursor.get_key(), key_populate(cursor, 119))
            self.assertEqual(cursor.get_value(), value_populate(cursor, 119))
Esempio n. 7
0
    def test_bulk_load_row_order_check(self):
        uri = self.type + self.name
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None, "bulk")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)

        cursor.set_key(key_populate(cursor, 1))
        cursor.set_value(value_populate(cursor, 1))
        msg = '/compares smaller than previously inserted key/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
            lambda: cursor.insert(), msg)
Esempio n. 8
0
    def test_bulk_load_row_order_check(self):
        uri = self.type + self.name
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None, "bulk")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)

        cursor.set_key(key_populate(cursor, 1))
        cursor.set_value(value_populate(cursor, 1))
        msg = '/compares smaller than previously inserted key/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
                                     lambda: cursor.insert(), msg)
Esempio n. 9
0
    def test_bulk_load_row_order_nocheck(self):
        uri = self.type + self.name
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None, "bulk,skip_sort_check")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)
        cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)

        if not wiredtiger.diagnostic_build():
            self.skipTest('requires a diagnostic build')

        # Close explicitly, there's going to be a fallure.
        msg = '/are incorrectly sorted/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
            lambda: self.conn.close(), msg)
Esempio n. 10
0
 def test_smoke(self):
     simple_populate(self,
         self.uri, self.config + self.keyfmt, self.nentries)
     self.reopen_conn()
     c = self.session.open_cursor(self.uri, None)
     c.set_key(key_populate(c, 100))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 100))
     c.set_key(key_populate(c, 101))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 101))
     c.set_key(key_populate(c, 9999))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 9999))
Esempio n. 11
0
    def test_bulk_load_row_order_nocheck(self):
        uri = self.type + self.name
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None, "bulk,skip_sort_check")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)
        cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)

        if not wiredtiger.diagnostic_build():
            self.skipTest('requires a diagnostic build')

        # Close explicitly, there's going to be a fallure.
        msg = '/are incorrectly sorted/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
                                     lambda: self.conn.close(), msg)
Esempio n. 12
0
 def test_smoke(self):
     simple_populate(self, self.uri, self.config + self.keyfmt,
                     self.nentries)
     self.reopen_conn()
     c = self.session.open_cursor(self.uri, None)
     c.set_key(key_populate(c, 100))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 100))
     c.set_key(key_populate(c, 101))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 101))
     c.set_key(key_populate(c, 9999))
     self.assertEqual(c.search(), 0)
     self.assertEqual(c.get_value(), value_populate(c, 9999))
Esempio n. 13
0
    def test_colmax_op(self):
        recno = self.recno

        uri = self.type + self.name
        self.session.create(uri,
                            'key_format=r' + ',value_format=' + self.valfmt)

        # Insert a big record with/without a bulk cursor.
        bulk_config = ""
        if self.bulk:
            bulk_config = "bulk"
        cursor = self.session.open_cursor(uri, None, bulk_config)

        # Optionaly make the big record the only record in the table.
        if not self.single:
            for i in range(1, 723):
                cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Confirm searching past the end of the table works.
        if not self.bulk:
            cursor.set_key(recno)
            self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Insert the big record.
        cursor[key_populate(cursor, recno)] = value_populate(cursor, recno)

        # Optionally flush to disk; re-open the cursor as necessary.
        if self.bulk or self.reopen:
            cursor.close()
        if self.reopen == 1:
            self.reopen_conn()
        if self.bulk or self.reopen:
            cursor = self.session.open_cursor(uri, None, None)

        # Search for the large record.
        cursor.set_key(recno)
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_value(), value_populate(cursor, recno))

        # Update it.
        cursor[key_populate(cursor, recno)] = value_populate(cursor, 37)
        cursor.set_key(recno)
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_value(), value_populate(cursor, 37))

        # Remove it.
        cursor.set_key(recno)
        self.assertEqual(cursor.remove(), 0)
        cursor.set_key(key_populate(cursor, recno))
        self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
Esempio n. 14
0
    def test_colmax_op(self):
        recno = self.recno

        uri = self.type + self.name
        self.session.create(uri, 'key_format=r' +',value_format=' + self.valfmt)

        # Insert a big record with/without a bulk cursor.
        bulk_config = ""
        if self.bulk:
            bulk_config = "bulk"
        cursor = self.session.open_cursor(uri, None, bulk_config)

        # Optionaly make the big record the only record in the table.
        if not self.single:
            for i in range(1, 723):
                cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Confirm searching past the end of the table works.
        if not self.bulk:
            cursor.set_key(recno)
            self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)

        # Insert the big record.
        cursor[key_populate(cursor, recno)] = value_populate(cursor, recno)

        # Optionally flush to disk; re-open the cursor as necessary.
        if self.bulk or self.reopen:
            cursor.close()
        if self.reopen == 1:
            self.reopen_conn()
        if self.bulk or self.reopen:
            cursor = self.session.open_cursor(uri, None, None)

        # Search for the large record.
        cursor.set_key(recno)
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_value(), value_populate(cursor, recno))

        # Update it.
        cursor[key_populate(cursor, recno)] = value_populate(cursor, 37)
        cursor.set_key(recno)
        self.assertEqual(cursor.search(), 0)
        self.assertEqual(cursor.get_value(), value_populate(cursor, 37))

        # Remove it.
        cursor.set_key(recno)
        self.assertEqual(cursor.remove(), 0)
        cursor.set_key(key_populate(cursor, recno))
        self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
Esempio n. 15
0
    def test_bulk_load_order_check(self):
        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)

        for i in [1, 9, 10]:
            cursor.set_key(key_populate(cursor, 1))
            cursor.set_value(value_populate(cursor, 1))
            msg = '/than previously inserted key/'
            self.assertRaisesWithMessage(
                wiredtiger.WiredTigerError, lambda: cursor.insert(), msg)

        cursor[key_populate(cursor, 11)] = value_populate(cursor, 11)
Esempio n. 16
0
    def test_bulk_load_order_check(self):
        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)

        for i in [1, 9, 10]:
            cursor.set_key(key_populate(cursor, 1))
            cursor.set_value(value_populate(cursor, 1))
            msg = '/than previously inserted key/'
            self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
                                         lambda: cursor.insert(), msg)

        cursor[key_populate(cursor, 11)] = value_populate(cursor, 11)
Esempio n. 17
0
    def test_insert_over_delete_replace(self):
        table_config = self.get_table_config()
        msg = '/WT_CACHE_FULL.*/'
        self.assertRaisesHavingMessage(wiredtiger.WiredTigerError,
            lambda:simple_populate(self,
                "table:" + self.name, table_config, 10000000), msg)

        cursor = self.session.open_cursor('table:' + self.name, None)
        cursor.prev()
        last_key = int(cursor.get_key())

        # Now that the database contains as much data as will fit into
        # the configured cache, verify removes succeed.
        cursor = self.session.open_cursor('table:' + self.name, None)
        for i in range(1, last_key / 4, 1):
            cursor.set_key(key_populate(cursor, i))
            cursor.remove()

        cursor.reset()
        # Spin inserting to give eviction a chance to reclaim space
        inserted = False
        for i in range(1, 1000):
            try:
                cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)
            except wiredtiger.WiredTigerError:
                cursor.reset()
                sleep(1)
                continue
            inserted = True
            break
        self.assertTrue(inserted)
Esempio n. 18
0
 def test_bulk_load(self):
     uri = self.type + self.name
     self.session.create(uri,
         'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
     cursor = self.session.open_cursor(uri, None, "bulk")
     for i in range(1, 1000):
         cursor[key_populate(cursor, i)] = value_populate(cursor, i)
Esempio n. 19
0
    def test_bulk_load_checkpoint(self):
        # Open a bulk cursor and insert a few records.
        self.session.create(self.uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(self.uri, None, 'bulk')
        for i in range(1, 10):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Checkpoint a few times (to test the drop code).
        for i in range(1, 5):
            if self.name == 0:
                self.session.checkpoint()
            else:
                self.session.checkpoint('name=myckpt')

        # Close the bulk cursor.
        cursor.close()

        # In the case of named checkpoints, verify they're still there,
        # reflecting an empty file.
        if self.name == 1:
            cursor = self.session.open_cursor(
                self.uri, None, 'checkpoint=myckpt')
            self.assertEquals(cursor.next(), wiredtiger.WT_NOTFOUND)
            cursor.close()
Esempio n. 20
0
    def test_bulkload_checkpoint(self):
        # Open a bulk cursor and insert a few records.
        self.session.create(self.uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(self.uri, None, 'bulk')
        for i in range(1, 10):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Checkpoint a few times (to test the drop code).
        for i in range(1, 5):
            if self.ckpt_type == 'named':
                self.session.checkpoint('name=myckpt')
            else:
                self.session.checkpoint()

        # Close the bulk cursor.
        cursor.close()

        # In the case of named checkpoints, verify they're still there,
        # reflecting an empty file.
        if self.ckpt_type == 'named':
            cursor = self.session.open_cursor(self.uri, None,
                                              'checkpoint=myckpt')
            self.assertEquals(cursor.next(), wiredtiger.WT_NOTFOUND)
            cursor.close()
Esempio n. 21
0
 def set_kv(self, cursor):
     cursor.set_key(key_populate(cursor, 10))
     if self.complex == 1:
         v = complex_value_populate(cursor, 10)
         cursor.set_value(v[0], v[1], v[2], v[3])
     else:
         cursor.set_value(value_populate(cursor, 10))
Esempio n. 22
0
    def test_bug006(self):
        uri = self.uri + self.name
        self.session.create(uri, 'value_format=S,key_format=S')
        cursor = self.session.open_cursor(uri, None)
        for i in range(1, 1000):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Table operations should fail, the cursor is open.
        self.assertRaises(wiredtiger.WiredTigerError,
                          lambda: self.session.drop(uri, None))
        self.assertRaises(
            wiredtiger.WiredTigerError,
            lambda: self.session.rename(uri, self.uri + "new", None))
        self.assertRaises(wiredtiger.WiredTigerError,
                          lambda: self.session.salvage(uri, None))
        self.assertRaises(wiredtiger.WiredTigerError,
                          lambda: self.session.truncate(uri, None, None, None))
        self.assertRaises(wiredtiger.WiredTigerError,
                          lambda: self.session.upgrade(uri, None))
        self.assertRaises(wiredtiger.WiredTigerError,
                          lambda: self.session.verify(uri, None))

        cursor.close()

        # Table operations should succeed, the cursor is closed.
        self.session.rename(uri, self.uri + "new", None)
        self.session.rename(self.uri + "new", uri, None)
        self.session.salvage(uri, None)
        self.session.truncate(uri, None, None, None)
        self.session.upgrade(uri, None)
        self.session.verify(uri, None)

        self.session.drop(uri, None)
Esempio n. 23
0
    def test_bulk_load_var_append(self):
        if self.keyfmt != 'r':
                return

        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk,append")
        for i in range(1, 1000):
            cursor[key_populate(cursor, 37)] = value_populate(cursor, i)
        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)
        for i in range(1, 1000):
            cursor.set_key(key_populate(cursor, i))
            cursor.search()
            self.assertEqual(cursor.get_value(), value_populate(cursor, i))
Esempio n. 24
0
    def test_bug006(self):
        uri = self.uri + self.name
        self.session.create(uri, 'value_format=S,key_format=S')
        cursor = self.session.open_cursor(uri, None)
        for i in range(1, 1000):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Table operations should fail, the cursor is open.
        self.assertRaises(
            wiredtiger.WiredTigerError, lambda: self.session.drop(uri, None))
        self.assertRaises(
            wiredtiger.WiredTigerError,
            lambda: self.session.rename(uri, self.uri + "new", None))
        self.assertRaises(
            wiredtiger.WiredTigerError, lambda: self.session.salvage(uri, None))
        self.assertRaises(
            wiredtiger.WiredTigerError, lambda: self.session.upgrade(uri, None))
        self.assertRaises(
            wiredtiger.WiredTigerError, lambda: self.session.verify(uri, None))

        cursor.close()

        # Table operations should succeed, the cursor is closed.
        self.session.rename(uri, self.uri + "new", None)
        self.session.rename(self.uri + "new", uri, None)
        self.session.salvage(uri, None)
        self.session.truncate(uri, None, None, None)
        self.session.upgrade(uri, None)
        self.session.verify(uri, None)

        self.session.drop(uri, None)
Esempio n. 25
0
 def test_bulk_load(self):
     uri = self.type + self.name
     self.session.create(
         uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
     cursor = self.session.open_cursor(uri, None, "bulk")
     for i in range(1, 1000):
         cursor[key_populate(cursor, i)] = value_populate(cursor, i)
Esempio n. 26
0
    def test_bulk_load_var_append(self):
        if self.keyfmt != 'r':
            return

        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk,append")
        for i in range(1, 1000):
            cursor[key_populate(cursor, 37)] = value_populate(cursor, i)
        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)
        for i in range(1, 1000):
            cursor.set_key(key_populate(cursor, i))
            cursor.search()
            self.assertEqual(cursor.get_value(), value_populate(cursor, i))
Esempio n. 27
0
 def set_kv(self, cursor):
     cursor.set_key(key_populate(cursor, 10))
     if self.complex == 1:
         v = complex_value_populate(cursor, 10)
         cursor.set_value(v[0], v[1], v[2], v[3])
     else:
         cursor.set_value(value_populate(cursor, 10))
Esempio n. 28
0
 def test_bulk_load_busy(self):
     uri = self.type + self.name
     self.session.create(uri, 'key_format=S,value_format=S')
     cursor = self.session.open_cursor(uri, None)
     cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)
     # Don't close the insert cursor, we want EBUSY.
     self.assertRaises(wiredtiger.WiredTigerError,
         lambda: self.session.open_cursor(uri, None, "bulk"))
Esempio n. 29
0
 def backward(self, c, max, notfound):
     for i in range(max, 0, -1):
         c.set_key(key_populate(c, i))
         if i in notfound:
             self.assertEqual(c.search(), wiredtiger.WT_NOTFOUND)
         else:
             self.assertEqual(c.search(), 0)
             self.assertEqual(c.get_value(), value_populate(c, i))
Esempio n. 30
0
 def backward(self, c, max, notfound):
     for i in range(max, 0, -1):
         c.set_key(key_populate(c, i))
         if i in notfound:
             self.assertEqual(c.search(), wiredtiger.WT_NOTFOUND)
         else:
             self.assertEqual(c.search(), 0)
             self.assertEqual(c.get_value(), value_populate(c, i))
Esempio n. 31
0
 def test_bulk_load_busy(self):
     uri = self.type + self.name
     self.session.create(uri, 'key_format=S,value_format=S')
     cursor = self.session.open_cursor(uri, None)
     cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)
     # Don't close the insert cursor, we want EBUSY.
     self.assertRaises(wiredtiger.WiredTigerError,
                       lambda: self.session.open_cursor(uri, None, "bulk"))
Esempio n. 32
0
    def test_bug004(self):
        # Create the object, fill with overflow keys and values.
        self.session.create(self.uri, self.config)
        c1 = self.session.open_cursor(self.uri, None)
        for i in range(1, self.nentries):
            c1.set_key(key_populate(c1, i) + 'abcdef' * 100)
            c1.set_value(value_populate(c1, i) + 'abcdef' * 100)
            c1.insert()
        c1.close()

        # Verify the object, force it to disk, and verify the on-disk version.
        self.session.verify(self.uri)
        self.reopen_conn()
        self.session.verify(self.uri)

        # Create a new session and start a transaction to force the engine
        # to access old versions of the key/value pairs.
        tmp_session = self.conn.open_session(None)
        tmp_session.begin_transaction("isolation=snapshot")

        # Load the object and use truncate to delete a set of records.  (I'm
        # using truncate because it doesn't instantiate keys, all other ops
        # currently do -- that's unlikely to change, but is a problem for the
        # test going forward.)
        c1 = self.session.open_cursor(self.uri, None)
        c1.set_key(key_populate(c1, self.nentries - 5) + 'abcdef' * 100)
        c2 = self.session.open_cursor(self.uri, None)
        c2.set_key(key_populate(c2, self.nentries + 5) + 'abcdef' * 100)
        self.session.truncate(None, c1, c2, None)
        c1.close()
        c2.close()

        # Checkpoint, freeing overflow blocks.
        self.session.checkpoint()

        # Use the snapshot cursor to retrieve the old key/value pairs
        c1 = tmp_session.open_cursor(self.uri, None)
        c1.set_key(key_populate(c1, 1) + 'abcdef' * 100)
        c1.search()
        for i in range(2, self.nentries):
            c1.next()
            self.assertEquals(
                c1.get_key(), key_populate(c1, i) + 'abcdef' * 100)
            self.assertEquals(
                c1.get_value(), value_populate(c1, i) + 'abcdef' * 100)
Esempio n. 33
0
 def test_bulk_load(self):
     uri = self.type + self.name
     self.session.create(uri, "key_format=" + self.keyfmt + ",value_format=" + self.valfmt)
     cursor = self.session.open_cursor(uri, None, "bulk")
     for i in range(1, 100):
         cursor.set_key(key_populate(cursor, i))
         cursor.set_value(value_populate(cursor, i))
         cursor.insert()
     cursor.close()
Esempio n. 34
0
 def test_bulk_load_not_empty(self):
     uri = self.type + self.name
     self.session.create(uri, 'key_format=S,value_format=S')
     cursor = self.session.open_cursor(uri, None)
     cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)
     # Close the insert cursor, else we'll get EBUSY.
     cursor.close()
     msg = '/bulk-load is only supported on newly created objects/'
     self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
         lambda: self.session.open_cursor(uri, None, "bulk"), msg)
Esempio n. 35
0
 def test_bulk_load(self):
     uri = self.type + self.name
     self.session.create(
         uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
     cursor = self.session.open_cursor(uri, None, "bulk")
     for i in range(1, 100):
         cursor.set_key(key_populate(cursor, i))
         cursor.set_value(value_populate(cursor, i))
         cursor.insert()
     cursor.close()
Esempio n. 36
0
    def test_cursor_random_invisible_before(self):
        uri = self.type
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None)

        # Insert a single leading record.
        cursor[key_populate(cursor, 99)] = value_populate(cursor, 99)

        # Start a transaction.
        self.session.begin_transaction()
        for i in range(2, 100):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Open another session, the updates won't yet be visible, we should
        # return the only possible record.
        s = self.conn.open_session()
        cursor = s.open_cursor(uri, None, self.config)
        self.assertEquals(cursor.next(), 0)
        self.assertEqual(cursor.get_key(), key_populate(cursor, 99))
Esempio n. 37
0
 def test_bulk_load_not_empty(self):
     uri = self.type + self.name
     self.session.create(uri, 'key_format=S,value_format=S')
     cursor = self.session.open_cursor(uri, None)
     cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)
     # Close the insert cursor, else we'll get EBUSY.
     cursor.close()
     msg = '/bulk-load is only supported on newly created objects/'
     self.assertRaisesWithMessage(
         wiredtiger.WiredTigerError,
         lambda: self.session.open_cursor(uri, None, "bulk"), msg)
Esempio n. 38
0
    def test_bulk_load_col_big(self):
        if self.keyfmt != 'r' or self.valfmt == '8t':
            return

        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 10):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # A big record -- if it's not efficient, we'll just hang.
        big = 18446744073709551606
        cursor[key_populate(cursor, big)] = value_populate(cursor, big)

        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)
        cursor.set_key(key_populate(cursor, big))
        cursor.search()
        self.assertEqual(cursor.get_value(), value_populate(cursor, big))
Esempio n. 39
0
    def test_bulk_load_col_big(self):
        if self.keyfmt != 'r' or self.valfmt == '8t':
                return

        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 10):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # A big record -- if it's not efficient, we'll just hang.
        big = 18446744073709551606
        cursor[key_populate(cursor, big)] = value_populate(cursor, big)

        cursor.close()
        cursor = self.session.open_cursor(uri, None, None)
        cursor.set_key(key_populate(cursor, big))
        cursor.search()
        self.assertEqual(cursor.get_value(), value_populate(cursor, big))
Esempio n. 40
0
    def test_bulk_load_var_rle(self):
        if self.keyfmt != 'r' or self.valfmt == '8t':
            return

        # We can't directly test RLE, it's internal to WiredTiger. However,
        # diagnostic builds catch records that should have been RLE compressed,
        # but weren't, so setting matching values should be sufficient.
        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 1000):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i / 7)
Esempio n. 41
0
    def test_bulk_load_row_order_nocheck(self):
        # Row-store offers an optional fast-past that skips the relatively
        # expensive key-order checks, used when the input is known to be
        # correct. Column-store comparisons are cheap, so it doesn't have
        # that fast-path support.
        if self.keyfmt != 'S':
            return

        uri = self.type + self.name
        self.session.create(
            uri, 'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk,skip_sort_check")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)
        cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)

        if not wiredtiger.diagnostic_build():
            self.skipTest('requires a diagnostic build')

        # Close explicitly, there's going to be a fallure.
        msg = '/are incorrectly sorted/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
                                     lambda: self.conn.close(), msg)
Esempio n. 42
0
    def test_bulk_load_row_order_nocheck(self):
        # Row-store offers an optional fast-past that skips the relatively
        # expensive key-order checks, used when the input is known to be
        # correct. Column-store comparisons are cheap, so it doesn't have
        # that fast-path support.
        if self.keyfmt != 'S':
                return

        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk,skip_sort_check")
        cursor[key_populate(cursor, 10)] = value_populate(cursor, 10)
        cursor[key_populate(cursor, 1)] = value_populate(cursor, 1)

        if not wiredtiger.diagnostic_build():
            self.skipTest('requires a diagnostic build')

        # Close explicitly, there's going to be a fallure.
        msg = '/are incorrectly sorted/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
            lambda: self.conn.close(), msg)
Esempio n. 43
0
    def test_missing(self):
        simple_populate(self,
            self.uri, self.config + self.keyfmt, self.nentries)
        c = self.session.open_cursor(self.uri, None)
        for i in range(self.nentries + 3000, self.nentries + 5001):
            c[key_populate(c, i)] = value_populate(c, i)
        self.reopen_conn()
        c = self.session.open_cursor(self.uri, None)
        self.forward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 3000)))
        self.backward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 3000)))

        # Insert into the empty space so we test searching inserted items.
        for i in range(self.nentries + 1000, self.nentries + 2001):
            c[key_populate(c, i)] = value_populate(c, i)
        self.forward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 1000) +\
                 range(self.nentries + 2001, self.nentries + 3000)))
        self.backward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 1000) +\
                 range(self.nentries + 2001, self.nentries + 3000)))
Esempio n. 44
0
    def test_missing(self):
        simple_populate(self, self.uri, self.config + self.keyfmt,
                        self.nentries)
        c = self.session.open_cursor(self.uri, None)
        for i in range(self.nentries + 3000, self.nentries + 5001):
            c[key_populate(c, i)] = value_populate(c, i)
        self.reopen_conn()
        c = self.session.open_cursor(self.uri, None)
        self.forward(c, self.nentries + 5000,
                     list(range(self.nentries + 1, self.nentries + 3000)))
        self.backward(c, self.nentries + 5000,
                      list(range(self.nentries + 1, self.nentries + 3000)))

        # Insert into the empty space so we test searching inserted items.
        for i in range(self.nentries + 1000, self.nentries + 2001):
            c[key_populate(c, i)] = value_populate(c, i)
        self.forward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 1000) +\
                 range(self.nentries + 2001, self.nentries + 3000)))
        self.backward(c, self.nentries + 5000,
            list(range(self.nentries + 1, self.nentries + 1000) +\
                 range(self.nentries + 2001, self.nentries + 3000)))
Esempio n. 45
0
    def test_bulk_load_var_rle(self):
        if self.keyfmt != 'r' or self.valfmt == '8t':
                return

        # We can't directly test RLE, it's internal to WiredTiger. However,
        # diagnostic builds catch records that should have been RLE compressed,
        # but weren't, so setting matching values should be sufficient.
        uri = self.type + self.name
        self.session.create(uri,
            'key_format=' + self.keyfmt + ',value_format=' + self.valfmt)
        cursor = self.session.open_cursor(uri, None, "bulk")
        for i in range(1, 1000):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i/7)
Esempio n. 46
0
 def test_stat_cursor_size(self):
     self.pop(self, self.uri, 'key_format=S' + self.cfg, 100)
     self.openAndWalkStatCursor()
     cursor = self.session.open_cursor(self.uri, None)
     for i in range(100, 40000 + 1):
         if i % 100 == 0:
             self.openAndWalkStatCursor()
         if self.pop == simple_populate:
             cursor[key_populate(cursor, i)] = value_populate(cursor, i)
         else:
             cursor[key_populate(cursor, i)] = \
                     tuple(complex_value_populate(cursor, i))
     cursor.close()
     self.openAndWalkStatCursor()
Esempio n. 47
0
    def test_cursor09(self):
        uri = self.type + "cursor09"

        if self.complex:
            complex_populate(self, uri, self.config, 100)
        else:
            simple_populate(self, uri, self.config, 100)

        cursor = self.session.open_cursor(uri, None, None)
        cursor[key_populate(cursor, 10)] = (
            tuple(complex_value_populate(cursor, 10)) if self.complex else value_populate(cursor, 10)
        )
        msg = "/requires key be set/"
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, cursor.search, msg)
Esempio n. 48
0
    def test_cursor_random_invisible_after(self):
        uri = 'file:random'
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None)

        # Insert a single leading record.
        cursor.set_key(key_populate(cursor, 1))
        cursor.set_value(value_populate(cursor, 1))
        cursor.insert()

        # Start a transaction.
        self.session.begin_transaction()
        for i in range(2, 100):
            cursor.set_key(key_populate(cursor, i))
            cursor.set_value(value_populate(cursor, i))
            cursor.insert()

        # Open another session, the updates won't yet be visible, we should
        # return the only possible record.
        s = self.conn.open_session()
        cursor = s.open_cursor(uri, None, "next_random=true")
        cursor.next()
        self.assertEqual(cursor.get_key(), key_populate(cursor, 1))
Esempio n. 49
0
 def test_stat_cursor_size(self):
     self.pop(self, self.uri, 'key_format=S' + self.cfg, 100)
     self.openAndWalkStatCursor()
     cursor = self.session.open_cursor(self.uri, None)
     for i in range(100, 40000 + 1):
         if i % 100 == 0:
             self.openAndWalkStatCursor()
         if self.pop == simple_populate:
             cursor[key_populate(cursor, i)] = value_populate(cursor, i)
         else:
             cursor[key_populate(cursor, i)] = \
                     tuple(complex_value_populate(cursor, i))
     cursor.close()
     self.openAndWalkStatCursor()
Esempio n. 50
0
    def test_cursor09(self):
        uri = self.type + 'cursor09'

        if self.complex:
            complex_populate(self, uri, self.config, 100)
        else:
            simple_populate(self, uri, self.config, 100)

        cursor = self.session.open_cursor(uri, None, None)
        cursor[key_populate(cursor, 10)] = \
            tuple(complex_value_populate(cursor, 10)) if self.complex \
            else value_populate(cursor, 10)
        msg = '/requires key be set/'
        self.assertRaisesWithMessage(wiredtiger.WiredTigerError, cursor.search,
                                     msg)
Esempio n. 51
0
    def test_column_store_gap_traverse(self):
        uri = 'table:gap'
        simple_populate(self, uri, 'key_format=r,value_format=S', 0)
        cursor = self.session.open_cursor(uri, None, None)
        self.nentries = 0

        # Create a column store with key gaps. The particular values aren't
        # important, we just want some gaps.
        v = [ 1000, 1001, 2000, 2001]
        for i in v:
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)
            self.nentries += 1

        # In-memory cursor forward, backward.
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))

        self.reopen_conn()
        cursor = self.session.open_cursor(uri, None, None)

        # Disk page cursor forward, backward.
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))

        # Insert some new records, so there are in-memory updates and an
        # on disk image. Put them in the middle of the existing values
        # so the traversal walks to them.
        v2 = [ 1500, 1501 ]
        for i in v2:
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)
            self.nentries += 1

        # Tell the validation what to expect.
        v = [ 1000, 1001, 1500, 1501, 2000, 2001 ]
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))
Esempio n. 52
0
    def test_column_store_gap_traverse(self):
        uri = 'table:gap'
        simple_populate(self, uri, 'key_format=r,value_format=S', 0)
        cursor = self.session.open_cursor(uri, None, None)
        self.nentries = 0

        # Create a column store with key gaps. The particular values aren't
        # important, we just want some gaps.
        v = [ 1000, 1001, 2000, 2001]
        for i in v:
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)
            self.nentries += 1

        # In-memory cursor forward, backward.
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))

        self.reopen_conn()
        cursor = self.session.open_cursor(uri, None, None)

        # Disk page cursor forward, backward.
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))

        # Insert some new records, so there are in-memory updates and an
        # on disk image. Put them in the middle of the existing values
        # so the traversal walks to them.
        v2 = [ 1500, 1501 ]
        for i in v2:
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)
            self.nentries += 1

        # Tell the validation what to expect.
        v = [ 1000, 1001, 1500, 1501, 2000, 2001 ]
        self.forward(cursor, v)
        self.backward(cursor, list(reversed(v)))
Esempio n. 53
0
    def test_cursor_random_invisible_all(self):
        uri = self.type
        self.session.create(uri, 'key_format=S,value_format=S')
        cursor = self.session.open_cursor(uri, None)

        # Start a transaction.
        self.session.begin_transaction()
        for i in range(1, 100):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)

        # Open another session, the updates won't yet be visible, we shouldn't
        # find anything at all.
        s = self.conn.open_session()
        cursor = s.open_cursor(uri, None, self.config)
        self.assertEqual(cursor.next(), wiredtiger.WT_NOTFOUND)
Esempio n. 54
0
    def test_bug005(self):
        # Create the object.
        self.session.create(self.uri, 'value_format=S,key_format=S')
        cursor = self.session.open_cursor(self.uri, None)
        for i in range(1, 1000):
            cursor[key_populate(cursor, i)] = value_populate(cursor, i)
        cursor.close()

        # Verify the object, force it to disk, and verify the on-disk version.
        self.session.verify(self.uri)
        self.reopen_conn()
        self.session.verify(self.uri)

        # Append random data to the end.
        f = open('test_bug005', 'a')
        f.write('random data')
        f.close()

        # Verify the object again.
        self.session.verify(self.uri)