本文整理汇总了Python中tablet.mquery函数的典型用法代码示例。如果您正苦于以下问题:Python mquery函数的具体用法?Python mquery怎么用?Python mquery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mquery函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_db_not_created
def _check_db_not_created(self, tablet):
# Broadly catch all exceptions, since the exception being raised
# is internal to MySQL. We're strictly checking the error message
# though, so should be fine.
with self.assertRaisesRegexp(
Exception, '(1049, "Unknown database \'%s\'")' % db_name):
tablet.mquery(db_name, 'show tables')
示例2: _insert_values
def _insert_values(self, tablet, id_offset, msg, keyspace_id, num_values):
"""Inserts values into MySQL along with the required routing comments.
Args:
tablet: the Tablet instance to modify.
id: the value of `id` column.
msg: the value of `msg` column.
keyspace_id: the value of `keyspace_id` column.
"""
# For maximum performance, multiple values are inserted in one statement.
# However, when the statements are too long, queries will timeout and
# vttablet will kill them. Therefore, we chunk it into multiple statements.
def chunks(full_list, n):
"""Yield successive n-sized chunks from full_list."""
for i in xrange(0, len(full_list), n):
yield full_list[i:i+n]
max_chunk_size = 100*1000
k = utils.uint64_to_hex(keyspace_id)
for chunk in chunks(range(1, num_values+1), max_chunk_size):
logging.debug('Inserting values for range [%d, %d].', chunk[0], chunk[-1])
values_str = ''
for i in chunk:
if i != chunk[0]:
values_str += ','
values_str += "(%d, '%s', 0x%x)" % (id_offset + i, msg, keyspace_id)
tablet.mquery(
'vt_test_keyspace', [
'begin',
'insert into worker_test(id, msg, keyspace_id) values%s '
'/* vtgate:: keyspace_id:%s */' % (values_str, k),
'commit'],
write=True)
示例3: setUp
def setUp(self):
create_table = (
'create table test (pk1 bigint, pk2 bigint, pk3 bigint, '
'keyspace_id bigint, msg varchar(64), primary key (pk1, pk2, pk3)) '
'Engine=InnoDB')
destination_tablet.create_db('test_checkers')
destination_tablet.mquery('test_checkers', create_table, True)
for i, t in enumerate(source_tablets):
t.create_db('test_checkers%s' % i)
t.mquery('test_checkers%s' % i, create_table, True)
destination_queries = []
source_queries = [[] for t in source_tablets]
for i in range(1, 400):
query = (
'insert into test (pk1, pk2, pk3, msg, keyspace_id) '
"values (%s, %s, %s, 'message %s', %s)" % (i/100+1, i/10+1, i, i, i))
destination_queries.append(query)
source_queries[i % 2].append(query)
for i in range(1100, 1110):
query = (
'insert into test (pk1, pk2, pk3, msg, keyspace_id) '
"values (%s, %s, %s, 'message %s', %s)" % (i/100+1, i/10+1, i, i, i))
source_queries[0].append(query)
destination_tablet.mquery('test_checkers', destination_queries, write=True)
for i, (tablet, queries) in enumerate(zip(source_tablets, source_queries)):
tablet.mquery('test_checkers%s' % i, queries, write=True)
self.c = self.make_checker()
示例4: _backfill_keyspace_id
def _backfill_keyspace_id(self, tablet):
tablet.mquery('vt_test_keyspace', [
'begin',
'update resharding1 set keyspace_id=0x1000000000000000 where id=1',
'update resharding1 set keyspace_id=0x9000000000000000 where id=2',
'update resharding1 set keyspace_id=0xD000000000000000 where id=3',
'commit'
], write=True)
示例5: _insert_value
def _insert_value(self, tablet, table, id, msg, keyspace_id):
k = utils.uint64_to_hex(keyspace_id)
tablet.mquery(
'vt_test_keyspace',
['begin',
'insert into %s(id, msg, keyspace_id) '
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ /* user_id:%d */' %
(table, id, msg, keyspace_id, k, id),
'commit'],
write=True)
示例6: _insert_value
def _insert_value(self, tablet, table, id, msg, keyspace_id):
if keyspace_id_type == keyrange_constants.KIT_BYTES:
k = base64.b64encode(pack_keyspace_id(keyspace_id))
else:
k = "%u" % keyspace_id
tablet.mquery('vt_test_keyspace', [
'begin',
'insert into %s(id, msg, keyspace_id) values(%u, "%s", 0x%x) /* EMD keyspace_id:%s user_id:%u */' % (table, id, msg, keyspace_id, k, id),
'commit'
], write=True)
示例7: _backfill_keyspace_id
def _backfill_keyspace_id(self, tablet):
tablet.mquery(
"vt_test_keyspace",
[
"begin",
"update resharding1 set keyspace_id=0x1000000000000000 where id=1",
"update resharding1 set keyspace_id=0x9000000000000000 where id=2",
"update resharding1 set keyspace_id=0xD000000000000000 where id=3",
"commit",
],
write=True,
)
示例8: _insert_value
def _insert_value(self, tablet, table, id, msg, keyspace_id):
k = utils.uint64_to_hex(keyspace_id)
tablet.mquery(
"vt_test_keyspace",
[
"begin",
"insert into %s(id, msg, keyspace_id) "
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ /* user_id:%d */'
% (table, id, msg, keyspace_id, k, id),
"commit",
],
write=True,
)
示例9: _insert_value
def _insert_value(self, tablet, id, msg, keyspace_id):
"""Inserts a value in the MySQL database along with the required routing comments.
Args:
tablet - the Tablet instance to insert into
id - the value of `id` column
msg - the value of `msg` column
keyspace_id - the value of `keyspace_id` column
"""
k = "%u" % keyspace_id
tablet.mquery('vt_test_keyspace', [
'begin',
'insert into worker_test(id, msg, keyspace_id) values(%u, "%s", 0x%x) /* EMD keyspace_id:%s user_id:%u */' % (id, msg, keyspace_id, k, id),
'commit'
], write=True)
示例10: _check_tables
def _check_tables(self, tablet, expectedCount):
tables = tablet.mquery(db_name, "show tables")
self.assertEqual(
len(tables),
expectedCount,
"Unexpected table count on %s (not %d): got tables: %s" % (tablet.tablet_alias, expectedCount, str(tables)),
)
示例11: _check_values
def _check_values(self, tablet, dbname, table, first, count):
logging.debug("Checking %d values from %s/%s starting at %d", count, dbname, table, first)
rows = tablet.mquery(dbname, "select id, msg from %s where id>=%d order by id limit %d" % (table, first, count))
self.assertEqual(count, len(rows), "got wrong number of rows: %d != %d" % (len(rows), count))
for i in xrange(count):
self.assertEqual(first + i, rows[i][0], "invalid id[%d]: %d != %d" % (i, first + i, rows[i][0]))
self.assertEqual(
"value %d" % (first + i), rows[i][1], "invalid msg[%d]: 'value %d' != '%s'" % (i, first + i, rows[i][1])
)
示例12: _check_vt_insert_test
def _check_vt_insert_test(self, tablet, index):
# wait until it gets the data
timeout = 10.0
while True:
result = tablet.mquery("vt_test_keyspace", "select msg from vt_insert_test where id=%d" % index)
if len(result) == 1:
break
timeout = utils.wait_step(
"waiting for replication to catch up on %s" % tablet.tablet_alias, timeout, sleep_time=0.1
)
示例13: check_value
def check_value(tablet, table, id, msg, keyspace_id, should_be_here=True):
result = tablet.mquery('vt_test_keyspace', 'select id, msg, keyspace_id from %s where id=%u' % (table, id))
if should_be_here:
if len(result) != 1:
raise utils.TestError("Missing row in tablet %s for id=%u, keyspace_id=%x" % (tablet.tablet_alias, id, keyspace_id))
result = result[0]
if result[0] != id or result[1] != msg or result[2] != keyspace_id:
raise utils.TestError("Row mismatch in tablet %s for id=%u, keyspace_id=%x: %s" % (tablet.tablet_alias, id, keyspace_id, str(result)))
else:
if len(result) != 0:
raise utils.TestError("Extra row in tablet %s for id=%u, keyspace_id=%x: %s" % (tablet.tablet_alias, id, keyspace_id, str(result[0])))
示例14: _insert_values
def _insert_values(self, tablet, id_offset, msg, keyspace_id, num_values):
"""Inserts values in the MySQL database along with the required routing comments.
Args:
tablet - the Tablet instance to insert into
id - the value of `id` column
msg - the value of `msg` column
keyspace_id - the value of `keyspace_id` column
"""
k = "%u" % keyspace_id
values_str = ''
for i in xrange(num_values):
if i != 0:
values_str += ','
values_str += '(%u, "%s", 0x%x)' % (id_offset + i, msg, keyspace_id)
tablet.mquery('vt_test_keyspace', [
'begin',
'insert into worker_test(id, msg, keyspace_id) values%s /* EMD keyspace_id:%s*/' % (values_str, k),
'commit'
], write=True)
示例15: _check_values
def _check_values(self, tablet, dbname, table, first, count):
logging.debug('Checking %u values from %s/%s starting at %u', count, dbname,
table, first)
rows = tablet.mquery(dbname, 'select id, msg from %s where id>=%u order by id limit %u' % (table, first, count))
self.assertEqual(count, len(rows), 'got wrong number of rows: %u != %u' %
(len(rows), count))
for i in xrange(count):
self.assertEqual(first + i, rows[i][0], 'invalid id[%u]: %u != %u' %
(i, first + i, rows[i][0]))
self.assertEqual('value %u' % (first + i), rows[i][1],
"invalid msg[%u]: 'value %u' != '%s'" %
(i, first + i, rows[i][1]))