本文整理汇总了Python中wtdataset.SimpleDataSet.key方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleDataSet.key方法的具体用法?Python SimpleDataSet.key怎么用?Python SimpleDataSet.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtdataset.SimpleDataSet
的用法示例。
在下文中一共展示了SimpleDataSet.key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insert_over_delete_replace
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_insert_over_delete_replace(self):
msg = '/WT_CACHE_FULL.*/'
ds = SimpleDataSet(self, self.uri, 10000000, key_format=self.keyfmt,
value_format=self.valuefmt, config=self.table_config)
self.assertRaisesHavingMessage(wiredtiger.WiredTigerError,
ds.populate, msg)
cursor = self.session.open_cursor(self.uri, 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(self.uri, None)
for i in range(1, last_key / 4, 1):
cursor.set_key(ds.key(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[ds.key(1)] = ds.value(1)
except wiredtiger.WiredTigerError:
cursor.reset()
sleep(1)
continue
inserted = True
break
self.assertTrue(inserted)
示例2: test_truncate_cursor_order
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_truncate_cursor_order(self):
uri = self.type + self.name
# A simple, one-file file or table object.
ds = SimpleDataSet(self, uri, 100, key_format=self.keyfmt)
ds.populate()
c1 = self.session.open_cursor(uri, None)
c1.set_key(ds.key(1000))
c2 = self.session.open_cursor(uri, None)
c2.set_key(ds.key(2000))
self.session.truncate(None, c1, c2, None)
self.assertEqual(c1.close(), 0)
self.assertEqual(c2.close(), 0)
self.session.drop(uri)
if self.type == "table:":
ds = ComplexDataSet(self, uri, 100, key_format=self.keyfmt)
ds.populate()
c1 = self.session.open_cursor(uri, None)
c1.set_key(ds.key(1000))
c2 = self.session.open_cursor(uri, None)
c2.set_key(ds.key(2000))
self.session.truncate(None, c1, c2, None)
self.assertEqual(c1.close(), 0)
self.assertEqual(c2.close(), 0)
self.session.drop(uri)
示例3: test_search_invisible_two
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_search_invisible_two(self):
# Populate the tree and reopen the connection, forcing it to disk
# and moving the records to an on-page format.
ds = SimpleDataSet(self, self.uri, 100, key_format=self.key_format,
value_format=self.value_format)
ds.populate()
self.reopen_conn()
# Add some additional visible records.
cursor = self.session.open_cursor(self.uri, None)
for i in range(100, 120):
cursor[ds.key(i)] = ds.value(i)
cursor.close()
# Begin a transaction, and add some additional records.
self.session.begin_transaction()
cursor = self.session.open_cursor(self.uri, None)
for i in range(120, 140):
cursor[ds.key(i)] = ds.value(i)
# Open a separate session and cursor.
s = self.conn.open_session()
cursor = s.open_cursor(self.uri, None)
# Search for an invisible record.
cursor.set_key(ds.key(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(ds.key(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(), ds.key(119))
self.assertEqual(cursor.get_value(), ds.value(119))
示例4: test_truncate_cursor_order
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_truncate_cursor_order(self):
uri = self.type + self.name
ds = SimpleDataSet(self, uri, 100, key_format=self.keyfmt)
ds.populate()
c1 = self.session.open_cursor(uri, None)
c2 = self.session.open_cursor(uri, None)
c1.set_key(ds.key(20))
c2.set_key(ds.key(10))
msg = "/the start cursor position is after the stop cursor position/"
self.assertRaisesWithMessage(wiredtiger.WiredTigerError, lambda: self.session.truncate(None, c1, c2, None), msg)
c2.set_key(ds.key(20))
self.session.truncate(None, c1, c2, None)
示例5: test_search_empty
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_search_empty(self):
# Create the object and open a cursor.
ds = SimpleDataSet(self, self.uri, 0, key_format=self.key_format,
value_format=self.value_format)
ds.create()
cursor = self.session.open_cursor(self.uri, None)
# Search for a record past the end of the table, which should fail.
cursor.set_key(ds.key(100))
self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
# Search-near for a record past the end of the table, which should fail.
cursor.set_key(ds.key(100))
self.assertEqual(cursor.search_near(), wiredtiger.WT_NOTFOUND)
示例6: test_smoke
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_smoke(self):
ds = SimpleDataSet(self, self.uri, self.nentries,
config=self.config, key_format=self.keyfmt)
ds.populate()
self.reopen_conn()
c = self.session.open_cursor(self.uri, None)
c.set_key(ds.key(100))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(100))
c.set_key(ds.key(101))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(101))
c.set_key(ds.key(9999))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(9999))
示例7: test_modify_delete
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_modify_delete(self):
ds = SimpleDataSet(self,
self.uri, 20, key_format=self.keyfmt, value_format='u')
ds.populate()
c = self.session.open_cursor(self.uri, None)
c.set_key(ds.key(10))
self.assertEquals(c.remove(), 0)
mods = []
mod = wiredtiger.Modify('ABCD', 3, 3)
mods.append(mod)
c.set_key(ds.key(10))
self.assertEqual(c.modify(mods), wiredtiger.WT_NOTFOUND)
示例8: address_deleted
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def address_deleted(self):
# Create the object, force it to disk, and verify the object.
ds = SimpleDataSet(self, self.uri, self.nentries, config=self.config)
ds.populate()
self.reopen_conn()
self.session.verify(self.uri)
# Create a new session and start a transaction to force the upcoming
# checkpoint operation to write address-deleted cells to disk.
tmp_session = self.conn.open_session(None)
tmp_session.begin_transaction("isolation=snapshot")
# Truncate a big range of rows; the leaf pages aren't in memory, so
# leaf page references will be deleted without being read.
start = self.session.open_cursor(self.uri, None)
start.set_key(ds.key(10))
end = self.session.open_cursor(self.uri, None)
end.set_key(ds.key(self.nentries - 10))
self.session.truncate(None, start, end, None)
self.assertEqual(start.close(), 0)
self.assertEqual(end.close(), 0)
# Checkpoint, forcing address-deleted cells to be written.
self.session.checkpoint()
# Crash/reopen the connection and verify the object.
self.reopen_conn()
self.session.verify(self.uri)
# Open a cursor and update a record (to dirty the tree, else we won't
# mark pages with address-deleted cells dirty), then walk the tree so
# we get a good look at all the internal pages and the address-deleted
# cells.
cursor = self.session.open_cursor(self.uri, None)
cursor.set_key(ds.key(5))
cursor.set_value("changed value")
self.assertEqual(cursor.update(), 0)
cursor.reset()
for key,val in cursor:
continue
self.assertEqual(cursor.close(), 0)
# Checkpoint, freeing the pages.
self.session.checkpoint()
return ds
示例9: test_search_eot
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
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.
ds = SimpleDataSet(self, self.uri, 100, key_format=self.key_format,
value_format=self.value_format)
ds.populate()
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(ds.key(100))
self.assertEqual(cursor.search(), 0)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
# Search-near for a record at the end of the table, which should
# succeed, returning the last record.
cursor.set_key(ds.key(100))
self.assertEqual(cursor.search_near(), 0)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
# Search for a record past the end of the table, which should fail.
cursor.set_key(ds.key(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(ds.key(200))
self.assertEqual(cursor.search_near(), -1)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
示例10: test_modify_many
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_modify_many(self):
ds = SimpleDataSet(self,
self.uri, 20, key_format=self.keyfmt, value_format='u')
ds.populate()
c = self.session.open_cursor(self.uri, None)
c.set_key(ds.key(10))
orig = 'abcdefghijklmnopqrstuvwxyz'
c.set_value(orig)
self.assertEquals(c.update(), 0)
for i in range(0, 50000):
new = "".join([random.choice(string.digits) for i in xrange(5)])
orig = orig[:10] + new + orig[15:]
mods = []
mod = wiredtiger.Modify(new, 10, 5)
mods.append(mod)
self.assertEquals(c.modify(mods), 0)
c.set_key(ds.key(10))
self.assertEquals(c.search(), 0)
self.assertEquals(c.get_value(), orig)
示例11: test_insert_over_delete
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_insert_over_delete(self):
msg = '/WT_CACHE_FULL.*/'
ds = SimpleDataSet(self, self.uri, 10000000, key_format=self.keyfmt,
value_format=self.valuefmt, config=self.table_config)
self.assertRaisesHavingMessage(wiredtiger.WiredTigerError,
ds.populate, msg)
# Now that the database contains as much data as will fit into
# the configured cache, verify removes succeed.
cursor = self.session.open_cursor(self.uri, None)
for i in range(1, 100):
cursor.set_key(ds.key(i))
cursor.remove()
示例12: test_bug014
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_bug014(self):
# Populate a table with 1000 keys on small pages.
uri = 'table:test_bug014'
ds = SimpleDataSet(self, uri, 1000,
config='allocation_size=512,leaf_page_max=512')
ds.populate()
# Reopen it so we can fast-delete pages.
self.reopen_conn()
# Truncate a chunk of the key/value pairs inside a transaction.
self.session.begin_transaction(None)
start = self.session.open_cursor(uri, None)
start.set_key(ds.key(250))
end = self.session.open_cursor(uri, None)
end.set_key(ds.key(500))
self.session.truncate(None, start, end, None)
start.close()
end.close()
# With the truncation uncommitted, checkpoint the database.
ckpt_session = self.conn.open_session()
ckpt_session.checkpoint(None)
ckpt_session.close()
# Simulate a crash by copying to a new directory.
copy_wiredtiger_home(".", "RESTART")
# Open the new directory.
conn = self.setUpConnectionOpen("RESTART")
session = self.setUpSessionOpen(conn)
cursor = session.open_cursor(uri)
# Confirm all of the records are there.
for i in range(1, 1001):
cursor.set_key(ds.key(i))
self.assertEqual(cursor.search(), 0)
conn.close()
示例13: test_checkpoint_last
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_checkpoint_last(self):
# Create an object, change one record to an easily recognizable string,
# then checkpoint it and open a cursor, confirming we see the correct
# value. Repeat this action, we want to be sure the engine gets the
# latest checkpoint information each time.
uri = self.uri
ds = SimpleDataSet(self, uri, 100, key_format=self.fmt)
ds.populate()
for value in ('FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH'):
# Update the object.
cursor = self.session.open_cursor(uri, None, "overwrite")
cursor[ds.key(10)] = value
cursor.close()
# Checkpoint the object.
self.session.checkpoint()
# Verify the "last" checkpoint sees the correct value.
cursor = self.session.open_cursor(
uri, None, "checkpoint=WiredTigerCheckpoint")
self.assertEquals(cursor[ds.key(10)], value)
示例14: test_column_store_gap_traverse
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_column_store_gap_traverse(self):
uri = 'table:gap'
# Initially just create tables.
ds = SimpleDataSet(self, uri, 0, key_format='r')
ds.populate()
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[ds.key(i)] = ds.value(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[ds.key(i)] = ds.value(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)))
示例15: test_missing
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import key [as 别名]
def test_missing(self):
ds = SimpleDataSet(self, self.uri, self.nentries,
config=self.config, key_format=self.keyfmt)
ds.populate()
c = self.session.open_cursor(self.uri, None)
for i in range(self.nentries + 3000, self.nentries + 5001):
c[ds.key(i)] = ds.value(i)
self.reopen_conn()
c = self.session.open_cursor(self.uri, None)
self.forward(c, ds, self.nentries + 5000,
list(range(self.nentries + 1, self.nentries + 3000)))
self.backward(c, ds, 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[ds.key(i)] = ds.value(i)
self.forward(c, ds, self.nentries + 5000,
list(list(range(self.nentries + 1, self.nentries + 1000)) +\
list(range(self.nentries + 2001, self.nentries + 3000))))
self.backward(c, ds, self.nentries + 5000,
list(list(range(self.nentries + 1, self.nentries + 1000)) +\
list(range(self.nentries + 2001, self.nentries + 3000))))