зеркало из https://github.com/github/vitess-gh.git
test: Move common resharding functions into base_resharding.py.
Fixed two pylint errors in resharding.py.
This commit is contained in:
Родитель
2a8dce510b
Коммит
1c90606716
|
@ -7,11 +7,19 @@
|
|||
"""This module contains a base class and utility functions for sharding tests.
|
||||
"""
|
||||
|
||||
import struct
|
||||
|
||||
import logging
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import utils
|
||||
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
||||
|
||||
class BaseShardingTest(object):
|
||||
"""This base class uses unittest.TestCase methods to check various things.
|
||||
|
||||
|
@ -19,6 +27,84 @@ class BaseShardingTest(object):
|
|||
methods as needed.
|
||||
"""
|
||||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
['begin',
|
||||
'insert into %s(id, msg, keyspace_id) '
|
||||
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ '
|
||||
'/* id:%d */' %
|
||||
(table, mid, msg, keyspace_id, k, mid),
|
||||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet_obj, table, mid):
|
||||
"""Returns the row(s) from the table for the provided id, using MySQL.
|
||||
|
||||
Args:
|
||||
tablet_obj: the tablet to get data from.
|
||||
table: the table to query.
|
||||
mid: id field of the table.
|
||||
Returns:
|
||||
A tuple of results.
|
||||
"""
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' %
|
||||
(table, mid))
|
||||
|
||||
def _check_value(self, tablet_obj, table, mid, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
if should_be_here:
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, mid,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
"""_is_value_present_and_correct tries to read a value.
|
||||
|
||||
Args:
|
||||
tablet_obj: the tablet to get data from.
|
||||
table: the table to query.
|
||||
mid: the id of the row to query.
|
||||
msg: expected value of the msg column in the row.
|
||||
keyspace_id: expected value of the keyspace_id column in the row.
|
||||
Returns:
|
||||
True if the value (row) is there and correct.
|
||||
False if the value is not there.
|
||||
If the value is not correct, the method will call self.fail.
|
||||
"""
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, '
|
||||
'keyspace_id=' + fmt) % (
|
||||
tablet_obj.tablet_alias, mid, keyspace_id))
|
||||
return True
|
||||
|
||||
def check_binlog_player_vars(self, tablet_obj, source_shards,
|
||||
seconds_behind_master_max=0):
|
||||
"""Checks the binlog player variables are correctly exported.
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
- we remove the original shard
|
||||
"""
|
||||
|
||||
import struct
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
|
@ -28,9 +26,6 @@ import environment
|
|||
import tablet
|
||||
import utils
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
||||
# initial shard, covers everything
|
||||
shard_master = tablet.Tablet()
|
||||
shard_replica = tablet.Tablet()
|
||||
|
@ -92,7 +87,7 @@ index by_msg (msg)
|
|||
auto_log=True)
|
||||
|
||||
def _add_sharding_key_to_schema(self):
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
if base_sharding.keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
t = 'varbinary(64)'
|
||||
else:
|
||||
t = 'bigint(20) unsigned'
|
||||
|
@ -103,7 +98,7 @@ index by_msg (msg)
|
|||
auto_log=True)
|
||||
|
||||
def _mark_sharding_key_not_null(self):
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
if base_sharding.keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
t = 'varbinary(64)'
|
||||
else:
|
||||
t = 'bigint(20) unsigned'
|
||||
|
@ -136,64 +131,6 @@ index by_msg (msg)
|
|||
'commit'
|
||||
], write=True)
|
||||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet_obj.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, mid, msg, keyspace_id, k, mid),
|
||||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet_obj, table, mid):
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' % (table, mid))
|
||||
|
||||
def _check_value(self, tablet_obj, table, mid, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
if should_be_here:
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, mid,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
# _is_value_present_and_correct tries to read a value.
|
||||
# if it is there, it will check it is correct and return True if it is.
|
||||
# if not correct, it will self.fail.
|
||||
# if not there, it will return False.
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' + fmt) % (
|
||||
tablet_obj.tablet_alias, mid, keyspace_id))
|
||||
return True
|
||||
|
||||
def _check_startup_values(self):
|
||||
# check first value is in the right shard
|
||||
for t in [shard_0_master, shard_0_replica, shard_0_rdonly1]:
|
||||
|
@ -326,7 +263,7 @@ index by_msg (msg)
|
|||
|
||||
# now we can be a sharded keyspace (and propagate to SrvKeyspace)
|
||||
utils.run_vtctl(['SetKeyspaceShardingInfo', 'test_keyspace',
|
||||
'keyspace_id', keyspace_id_type])
|
||||
'keyspace_id', base_sharding.keyspace_id_type])
|
||||
utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'],
|
||||
auto_log=True)
|
||||
|
||||
|
@ -427,7 +364,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -\n'
|
||||
'Partitions(rdonly): -\n'
|
||||
'Partitions(replica): -\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
# we need to create the schema, and the worker will do data copying
|
||||
for keyspace_shard in ('test_keyspace/-80', 'test_keyspace/80-'):
|
||||
|
@ -512,7 +449,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
# make sure rdonly tablets are back to serving before hitting vtgate.
|
||||
for t in [shard_0_rdonly1, shard_1_rdonly1]:
|
||||
|
@ -541,7 +478,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
# move replica back and forth
|
||||
utils.run_vtctl(
|
||||
|
@ -555,7 +492,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
utils.run_vtctl(['MigrateServedTypes', 'test_keyspace/0', 'replica'],
|
||||
auto_log=True)
|
||||
|
@ -567,7 +504,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
# then serve master from the split shards
|
||||
utils.run_vtctl(['MigrateServedTypes', 'test_keyspace/0', 'master'],
|
||||
|
@ -576,7 +513,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
keyspace_id_type=base_sharding.keyspace_id_type)
|
||||
|
||||
# check the binlog players are gone now
|
||||
self.check_no_binlog_player(shard_0_master)
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
# Use of this source code is governed by a BSD-style license that can
|
||||
# be found in the LICENSE file.
|
||||
|
||||
"""Re-runs initial_sharding.py with a varbinary keyspace_id."""
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import base_sharding
|
||||
import initial_sharding
|
||||
import utils
|
||||
|
||||
# this test is just re-running an entire initial_sharding.py with a
|
||||
# varbinary keyspace_id
|
||||
if __name__ == '__main__':
|
||||
initial_sharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
base_sharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
utils.main(initial_sharding)
|
||||
|
|
|
@ -13,8 +13,6 @@ Note this test is just testing the full workflow, not corner cases or error
|
|||
cases. These are mostly done by the other resharding tests.
|
||||
"""
|
||||
|
||||
import struct
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
|
@ -26,9 +24,6 @@ import tablet
|
|||
import utils
|
||||
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
||||
# initial shards
|
||||
# shard -40
|
||||
shard_0_master = tablet.Tablet()
|
||||
|
@ -84,7 +79,7 @@ class TestMergeSharding(unittest.TestCase, base_sharding.BaseShardingTest):
|
|||
# create_schema will create the same schema on the keyspace
|
||||
# then insert some values
|
||||
def _create_schema(self):
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
if base_sharding.keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
t = 'varbinary(64)'
|
||||
else:
|
||||
t = 'bigint(20) unsigned'
|
||||
|
@ -113,75 +108,6 @@ index by_msg (msg)
|
|||
'test_keyspace'],
|
||||
auto_log=True)
|
||||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
['begin',
|
||||
'insert into %s(id, msg, keyspace_id) '
|
||||
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ '
|
||||
'/* id:%d */' %
|
||||
(table, mid, msg, keyspace_id, k, mid),
|
||||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet_obj, table, mid):
|
||||
"""Returns the row(s) from the table for the provided id, using MySQL.
|
||||
|
||||
Args:
|
||||
tablet_obj: the tablet to get data from.
|
||||
table: the table to query.
|
||||
mid: id field of the table.
|
||||
Returns:
|
||||
A tuple of results.
|
||||
"""
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' %
|
||||
(table, mid))
|
||||
|
||||
def _check_value(self, tablet_obj, table, mid, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
if should_be_here:
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, mid,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
# _is_value_present_and_correct tries to read a value.
|
||||
# if it is there, it will check it is correct and return True if it is.
|
||||
# if not correct, it will self.fail.
|
||||
# if not there, it will return False.
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, '
|
||||
'keyspace_id=' + fmt) % (
|
||||
tablet_obj.tablet_alias, mid, keyspace_id))
|
||||
return True
|
||||
|
||||
def _insert_startup_values(self):
|
||||
# row covered by shard -40 (should be merged).
|
||||
self._insert_value(shard_0_master, 'resharding1', 0, 'msg1',
|
||||
|
@ -247,7 +173,7 @@ index by_msg (msg)
|
|||
def test_merge_sharding(self):
|
||||
utils.run_vtctl(['CreateKeyspace',
|
||||
'--sharding_column_name', 'keyspace_id',
|
||||
'--sharding_column_type', keyspace_id_type,
|
||||
'--sharding_column_type', base_sharding.keyspace_id_type,
|
||||
'test_keyspace'])
|
||||
|
||||
shard_0_master.init_tablet('master', 'test_keyspace', '-40')
|
||||
|
@ -323,7 +249,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -40 40-80 80-\n'
|
||||
'Partitions(rdonly): -40 40-80 80-\n'
|
||||
'Partitions(replica): -40 40-80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
# copy the schema
|
||||
|
@ -426,7 +352,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -40 40-80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -40 40-80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
# now serve replica from the split shards
|
||||
|
@ -436,7 +362,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -40 40-80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
# now serve master from the split shards
|
||||
|
@ -446,7 +372,7 @@ index by_msg (msg)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_tablet_query_service(self, shard_0_master, False, True)
|
||||
utils.check_tablet_query_service(self, shard_1_master, False, True)
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import base_sharding
|
||||
import merge_sharding
|
||||
import utils
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
merge_sharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
base_sharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
utils.main(merge_sharding)
|
||||
|
|
|
@ -22,7 +22,6 @@ effects, like:
|
|||
- makes sure the key range rules are properly enforced on masters.
|
||||
"""
|
||||
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
@ -38,9 +37,6 @@ import environment
|
|||
import tablet
|
||||
import utils
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
||||
# initial shards
|
||||
# range '' - 80
|
||||
shard_0_master = tablet.Tablet()
|
||||
|
@ -137,7 +133,7 @@ class InsertThread(threading.Thread):
|
|||
'commit'],
|
||||
write=True, user='vt_app')
|
||||
time.sleep(0.2)
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
logging.exception('InsertThread got exception.')
|
||||
|
||||
|
||||
|
@ -173,7 +169,7 @@ class MonitorLagThread(threading.Thread):
|
|||
if lag_ms > self.max_lag_ms:
|
||||
self.max_lag_ms = lag_ms
|
||||
time.sleep(1.0)
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
logging.exception('MonitorLagThread got exception.')
|
||||
|
||||
|
||||
|
@ -182,7 +178,7 @@ class TestResharding(unittest.TestCase, base_sharding.BaseShardingTest):
|
|||
# create_schema will create the same schema on the keyspace
|
||||
# then insert some values
|
||||
def _create_schema(self):
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
if base_sharding.keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
t = 'varbinary(64)'
|
||||
else:
|
||||
t = 'bigint(20) unsigned'
|
||||
|
@ -229,66 +225,6 @@ primary key (name)
|
|||
'test_keyspace'],
|
||||
auto_log=True)
|
||||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet_obj.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, mid, msg, keyspace_id, k, mid),
|
||||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet_obj, table, mid):
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' %
|
||||
(table, mid))
|
||||
|
||||
def _check_value(self, tablet_obj, table, mid, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
if should_be_here:
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, mid,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
# _is_value_present_and_correct tries to read a value.
|
||||
# if it is there, it will check it is correct and return True if it is.
|
||||
# if not correct, it will self.fail.
|
||||
# if not there, it will return False.
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
else:
|
||||
fmt = '%x'
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, '
|
||||
'keyspace_id=' + fmt) % (
|
||||
tablet_obj.tablet_alias, mid, keyspace_id))
|
||||
return True
|
||||
|
||||
def _insert_startup_values(self):
|
||||
self._insert_value(shard_0_master, 'resharding1', 1, 'msg1',
|
||||
0x1000000000000000)
|
||||
|
@ -403,7 +339,8 @@ primary key (name)
|
|||
utils.run_vtctl(['SetKeyspaceShardingInfo', 'test_keyspace',
|
||||
'keyspace_id', 'uint64'], expect_fail=True)
|
||||
utils.run_vtctl(['SetKeyspaceShardingInfo', '-force',
|
||||
'test_keyspace', 'keyspace_id', keyspace_id_type])
|
||||
'test_keyspace',
|
||||
'keyspace_id', base_sharding.keyspace_id_type])
|
||||
|
||||
shard_0_master.init_tablet('master', 'test_keyspace', '-80')
|
||||
shard_0_replica.init_tablet('replica', 'test_keyspace', '-80')
|
||||
|
@ -419,7 +356,8 @@ primary key (name)
|
|||
self.assertEqual(ks['sharding_column_name'], 'keyspace_id')
|
||||
|
||||
# we set full_mycnf_args to True as a test in the KIT_BYTES case
|
||||
full_mycnf_args = keyspace_id_type == keyrange_constants.KIT_BYTES
|
||||
full_mycnf_args = (base_sharding.keyspace_id_type ==
|
||||
keyrange_constants.KIT_BYTES)
|
||||
|
||||
# create databases so vttablet can start behaving somewhat normally
|
||||
for t in [shard_0_master, shard_0_replica, shard_0_ny_rdonly,
|
||||
|
@ -502,7 +440,7 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
# disable shard_1_slave2, so we're sure filtered replication will go
|
||||
|
@ -650,13 +588,13 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_srv_keyspace('test_ny', 'test_keyspace',
|
||||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_tablet_query_service(self, shard_0_ny_rdonly, True, False)
|
||||
utils.check_tablet_query_service(self, shard_1_ny_rdonly, True, False)
|
||||
|
@ -669,13 +607,13 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_srv_keyspace('test_ny', 'test_keyspace',
|
||||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_tablet_query_service(self, shard_0_ny_rdonly, True, False)
|
||||
utils.check_tablet_query_service(self, shard_1_ny_rdonly, False, True)
|
||||
|
@ -690,7 +628,7 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-c0 c0-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_tablet_query_service(self, shard_1_slave2, False, True)
|
||||
|
||||
|
@ -710,7 +648,7 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
utils.run_vtctl(['MigrateServedTypes', 'test_keyspace/80-', 'replica'],
|
||||
|
@ -727,7 +665,7 @@ primary key (name)
|
|||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-c0 c0-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
|
||||
# reparent shard_2 to shard_2_replica1, then insert more data and
|
||||
|
@ -785,7 +723,7 @@ primary key (name)
|
|||
'Partitions(master): -80 80-c0 c0-\n'
|
||||
'Partitions(rdonly): -80 80-c0 c0-\n'
|
||||
'Partitions(replica): -80 80-c0 c0-\n',
|
||||
keyspace_id_type=keyspace_id_type,
|
||||
keyspace_id_type=base_sharding.keyspace_id_type,
|
||||
sharding_column_name='keyspace_id')
|
||||
utils.check_tablet_query_service(self, shard_1_master, False, True)
|
||||
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
# Use of this source code is governed by a BSD-style license that can
|
||||
# be found in the LICENSE file.
|
||||
|
||||
"""Re-runs resharding.py with a varbinary keyspace_id."""
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import base_sharding
|
||||
import resharding
|
||||
import utils
|
||||
|
||||
# this test is just re-running an entire resharding.py with a
|
||||
# varbinary keyspace_id
|
||||
if __name__ == '__main__':
|
||||
resharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
base_sharding.keyspace_id_type = keyrange_constants.KIT_BYTES
|
||||
utils.main(resharding)
|
||||
|
|
Загрузка…
Ссылка в новой задаче