From 6ce9973341aa07c1ca5a7445b4e28f33907fc8ad Mon Sep 17 00:00:00 2001 From: Michael Berlin Date: Wed, 2 Sep 2015 17:55:17 -0700 Subject: [PATCH] Exporting internal changes back to open-source. NOTE: Changes were already LGTM'd internally. --- test/utils.py | 2 +- test/worker.py | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/test/utils.py b/test/utils.py index e7da95a776..9bfad2f542 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1078,7 +1078,7 @@ class Vtctld(object): if python: from vtctl import grpc_vtctl_client rpc_port = self.grpc_port - return (protocol, 'localhost:%d' % rpc_port) + return (protocol, '%s:%d' % (socket.getfqdn(), rpc_port)) def process_args(self): return ['-vtctld_addr', 'http://localhost:%d/' % self.port] diff --git a/test/worker.py b/test/worker.py index 626231f705..d9bfb99a0e 100755 --- a/test/worker.py +++ b/test/worker.py @@ -242,18 +242,30 @@ class TestBaseSplitClone(unittest.TestCase): keyspace_id: the value of `keyspace_id` column. """ k = '%d' % keyspace_id - values_str = '' - for i in xrange(num_values): - if i != 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 ' - '/* EMD keyspace_id:%s*/' % (values_str, k), - 'commit'], - write=True) + + # 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 + 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 ' + '/* EMD keyspace_id:%s*/' % (values_str, k), + 'commit'], + write=True) def insert_values( self, tablet, num_values, num_shards, offset=0, keyspace_id_range=2**64):