def setup_tablets(): # Start up a master mysql and vttablet utils.debug("Setting up tablets") utils.run_vtctl('CreateKeyspace test_keyspace') master_tablet.init_tablet('master', 'test_keyspace', '0') utils.run_vtctl('RebuildShardGraph test_keyspace/0') utils.run_vtctl('RebuildKeyspaceGraph test_keyspace') utils.validate_topology() setup_schema() replica_tablet.create_db('vt_test_keyspace') master_tablet.start_vttablet(memcache=True) replica_tablet.init_tablet('idle', 'test_keyspace', start=True, memcache=True) snapshot_dir = os.path.join(utils.vtdataroot, 'snapshot') utils.run("mkdir -p " + snapshot_dir) utils.run("chmod +w " + snapshot_dir) utils.run_vtctl('Clone -force %s %s' % (master_tablet.tablet_alias, replica_tablet.tablet_alias)) utils.run_vtctl('Ping test_nj-0000062344') utils.run_vtctl('SetReadWrite ' + master_tablet.tablet_alias) utils.check_db_read_write(62344) utils.validate_topology() utils.run_vtctl('Ping test_nj-0000062345') utils.run_vtctl('ChangeSlaveType test_nj-0000062345 replica')
def setup_tablets(): # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl('CreateKeyspace test_keyspace') master_tablet.init_tablet('master', 'test_keyspace', '0') replica_tablet.init_tablet('replica', 'test_keyspace', '0') utils.run_vtctl('RebuildShardGraph test_keyspace/0') utils.validate_topology() master_tablet.create_db('vt_test_keyspace') replica_tablet.create_db('vt_test_keyspace') utils.run_vtctl('RebuildKeyspaceGraph test_keyspace') zkocc_server = utils.zkocc_start() master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl('SetReadWrite ' + master_tablet.tablet_alias) utils.check_db_read_write(62344) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl('ReparentShard -force test_keyspace/0 ' + master_tablet.tablet_alias, auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 setup_schema() master_tablet.vquery("set vt_schema_reload_time=86400", path="test_keyspace/0") replica_tablet.vquery("set vt_schema_reload_time=86400", path="test_keyspace/0")
def setup_tablets(): # Start up a master mysql and vttablet utils.debug("Setting up tablets") utils.run_vtctl("CreateKeyspace test_keyspace") master_tablet.init_tablet("master", "test_keyspace", "0") utils.run_vtctl("RebuildShardGraph test_keyspace/0") utils.run_vtctl("RebuildKeyspaceGraph test_keyspace") utils.validate_topology() setup_schema() replica_tablet.create_db("vt_test_keyspace") # master_tablet.start_vttablet(auth=True) master_tablet.start_vttablet() replica_tablet.init_tablet("idle", "test_keyspace", start=True) snapshot_dir = os.path.join(utils.vtdataroot, "snapshot") utils.run("mkdir -p " + snapshot_dir) utils.run("chmod +w " + snapshot_dir) utils.run_vtctl("Clone -force %s %s" % (master_tablet.tablet_alias, replica_tablet.tablet_alias)) utils.run_vtctl("Ping test_nj-0000062344") utils.run_vtctl("SetReadWrite " + master_tablet.tablet_alias) utils.check_db_read_write(62344) utils.validate_topology() utils.run_vtctl("Ping test_nj-0000062345") # reset counter so tests don't assert tablet.Tablet.tablets_running = 0
def _test_sanity(self): # Start up a master mysql and vttablet utils.run_vtctl(['CreateKeyspace', '-force', 'test_keyspace']) utils.run_vtctl(['createshard', '-force', 'test_keyspace/0']) tablet_62344.init_tablet('master', 'test_keyspace', '0', parent=False) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) utils.validate_topology() srvShard = utils.run_vtctl_json(['GetSrvShard', 'test_nj', 'test_keyspace/0']) self.assertEqual(srvShard['MasterCell'], 'test_nj') # if these statements don't run before the tablet it will wedge # waiting for the db to become accessible. this is more a bug than # a feature. tablet_62344.populate('vt_test_keyspace', self._create_vt_select_test, self._populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away result, _ = utils.run_vtctl(['Query', 'test_nj', 'test_keyspace', 'select * from vt_select_test'], mode=utils.VTCTL_VTCTL, trap_output=True) rows = result.splitlines() self.assertEqual(len(rows), 5, "expected 5 rows in vt_select_test: %s %s" % (str(rows), result)) # make sure direct dba queries work query_result = utils.run_vtctl_json(['ExecuteFetch', '-want_fields', tablet_62344.tablet_alias, 'select * from vt_test_keyspace.vt_select_test']) self.assertEqual(len(query_result['Rows']), 4, "expected 4 rows in vt_select_test: %s" % str(query_result)) self.assertEqual(len(query_result['Fields']), 2, "expected 2 fields in vt_select_test: %s" % str(query_result)) # check Pings utils.run_vtctl(['Ping', tablet_62344.tablet_alias]) utils.run_vtctl(['RpcPing', tablet_62344.tablet_alias]) # Quickly check basic actions. utils.run_vtctl(['SetReadOnly', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.run_vtctl(['SetReadWrite', tablet_62344.tablet_alias]) utils.check_db_read_write(62344) utils.run_vtctl(['DemoteMaster', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.validate_topology() utils.run_vtctl(['ValidateKeyspace', 'test_keyspace']) # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl(['ValidateShard', '-ping-tablets=false', 'test_keyspace/0']) srvShard = utils.run_vtctl_json(['GetSrvShard', 'test_nj', 'test_keyspace/0']) self.assertEqual(srvShard['MasterCell'], 'test_nj') tablet_62344.kill_vttablet() tablet_62344.init_tablet('idle') tablet_62344.scrap(force=True)
def _test_sanity(self): # Start up a master mysql and vttablet utils.run_vtctl(['CreateKeyspace', '-force', 'test_keyspace']) utils.run_vtctl(['createshard', '-force', 'test_keyspace/0']) tablet_62344.init_tablet('master', 'test_keyspace', '0', parent=False) utils.run_vtctl( ['RebuildKeyspaceGraph', '-rebuild_srv_shards', 'test_keyspace']) utils.validate_topology() self._check_srv_shard() # if these statements don't run before the tablet it will wedge # waiting for the db to become accessible. this is more a bug than # a feature. tablet_62344.populate('vt_test_keyspace', self._create_vt_select_test, self._populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away qr = tablet_62344.execute('select * from vt_select_test') self.assertEqual(len(qr['rows']), 4, 'expected 4 rows in vt_select_test: %s' % str(qr)) # make sure direct dba queries work query_result = utils.run_vtctl_json( ['ExecuteFetchAsDba', '-json', tablet_62344.tablet_alias, 'select * from vt_test_keyspace.vt_select_test']) self.assertEqual( len(query_result['rows']), 4, 'expected 4 rows in vt_select_test: %s' % str(query_result)) self.assertEqual( len(query_result['fields']), 2, 'expected 2 fields in vt_select_test: %s' % str(query_result)) # check Ping / RefreshState utils.run_vtctl(['Ping', tablet_62344.tablet_alias]) utils.run_vtctl(['RefreshState', tablet_62344.tablet_alias]) # Quickly check basic actions. utils.run_vtctl(['SetReadOnly', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.run_vtctl(['SetReadWrite', tablet_62344.tablet_alias]) utils.check_db_read_write(62344) utils.run_vtctl(['DemoteMaster', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.validate_topology() utils.run_vtctl(['ValidateKeyspace', 'test_keyspace']) # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl(['ValidateShard', '-ping-tablets=false', 'test_keyspace/0']) self._check_srv_shard() tablet_62344.kill_vttablet()
def setUpModule(): global vtgate_server global vtgate_port global vtgate_socket_file global master_start_position try: environment.topo_server_setup() # start mysql instance external to the test setup_procs = [master_tablet.init_mysql(), replica_tablet.init_mysql() ] utils.wait_procs(setup_procs) # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) master_tablet.init_tablet('master', 'test_keyspace', '0') replica_tablet.init_tablet('replica', 'test_keyspace', '0') utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0']) utils.validate_topology() master_tablet.create_db('vt_test_keyspace') master_tablet.create_db('other_database') replica_tablet.create_db('vt_test_keyspace') replica_tablet.create_db('other_database') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) vtgate_socket_file = environment.tmproot + '/vtgate.sock' vtgate_server, vtgate_port = utils.vtgate_start(socket_file=vtgate_socket_file) master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl(['SetReadWrite', master_tablet.tablet_alias]) utils.check_db_read_write(master_tablet.tablet_uid) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/0', master_tablet.tablet_alias], auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 master_start_position = _get_master_current_position() master_tablet.mquery('vt_test_keyspace', _create_vt_insert_test) master_tablet.mquery('vt_test_keyspace', _create_vt_a) master_tablet.mquery('vt_test_keyspace', _create_vt_b) utils.run_vtctl(['ReloadSchema', master_tablet.tablet_alias]) utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) except: tearDownModule() raise
def setUpModule(): global master_start_position try: environment.topo_server().setup() # start mysql instance external to the test setup_procs = [master_tablet.init_mysql(), replica_tablet.init_mysql()] utils.wait_procs(setup_procs) # start a vtctld so the vtctl insert commands are just RPCs, not forks utils.Vtctld().start() # Start up a master mysql and vttablet logging.debug('Setting up tablets') utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) master_tablet.init_tablet('master', 'test_keyspace', '0') replica_tablet.init_tablet('replica', 'test_keyspace', '0') utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0']) utils.validate_topology() master_tablet.create_db('vt_test_keyspace') master_tablet.create_db('other_database') replica_tablet.create_db('vt_test_keyspace') replica_tablet.create_db('other_database') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) utils.VtGate().start() master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl(['SetReadWrite', master_tablet.tablet_alias]) utils.check_db_read_write(master_tablet.tablet_uid) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl(['InitShardMaster', 'test_keyspace/0', master_tablet.tablet_alias], auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 master_start_position = _get_master_current_position() master_tablet.mquery('vt_test_keyspace', _create_vt_insert_test) master_tablet.mquery('vt_test_keyspace', _create_vt_a) master_tablet.mquery('vt_test_keyspace', _create_vt_b) utils.run_vtctl(['ReloadSchema', master_tablet.tablet_alias]) utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) except: tearDownModule() raise
def setUpModule(): global master_start_position try: environment.topo_server().setup() # start mysql instance external to the test setup_procs = [master_tablet.init_mysql(), replica_tablet.init_mysql()] utils.wait_procs(setup_procs) # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(["CreateKeyspace", "test_keyspace"]) master_tablet.init_tablet("master", "test_keyspace", "0") replica_tablet.init_tablet("replica", "test_keyspace", "0") utils.run_vtctl(["RebuildShardGraph", "test_keyspace/0"]) utils.validate_topology() master_tablet.create_db("vt_test_keyspace") master_tablet.create_db("other_database") replica_tablet.create_db("vt_test_keyspace") replica_tablet.create_db("other_database") utils.run_vtctl(["RebuildKeyspaceGraph", "test_keyspace"]) utils.VtGate().start(socket_file=environment.tmproot + "/vtgate.sock") master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl(["SetReadWrite", master_tablet.tablet_alias]) utils.check_db_read_write(master_tablet.tablet_uid) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl(["InitShardMaster", "test_keyspace/0", master_tablet.tablet_alias], auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 master_start_position = _get_master_current_position() master_tablet.mquery("vt_test_keyspace", _create_vt_insert_test) master_tablet.mquery("vt_test_keyspace", _create_vt_a) master_tablet.mquery("vt_test_keyspace", _create_vt_b) utils.run_vtctl(["ReloadSchema", master_tablet.tablet_alias]) utils.run_vtctl(["ReloadSchema", replica_tablet.tablet_alias]) except: tearDownModule() raise
def _test_sanity(self): # Start up a master mysql and vttablet utils.run_vtctl(["CreateKeyspace", "-force", "test_keyspace"]) utils.run_vtctl(["createshard", "-force", "test_keyspace/0"]) tablet_62344.init_tablet("master", "test_keyspace", "0", parent=False) utils.run_vtctl(["RebuildKeyspaceGraph", "-rebuild_srv_shards", "test_keyspace"]) utils.validate_topology() self._check_srv_shard() # if these statements don't run before the tablet it will wedge # waiting for the db to become accessible. this is more a bug than # a feature. tablet_62344.populate("vt_test_keyspace", self._create_vt_select_test, self._populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away qr = tablet_62344.execute("select * from vt_select_test") self.assertEqual(len(qr["rows"]), 4, "expected 4 rows in vt_select_test: %s" % str(qr)) # make sure direct dba queries work query_result = utils.run_vtctl_json( ["ExecuteFetchAsDba", "-json", tablet_62344.tablet_alias, "select * from vt_test_keyspace.vt_select_test"] ) self.assertEqual(len(query_result["rows"]), 4, "expected 4 rows in vt_select_test: %s" % str(query_result)) self.assertEqual(len(query_result["fields"]), 2, "expected 2 fields in vt_select_test: %s" % str(query_result)) # check Ping / RefreshState utils.run_vtctl(["Ping", tablet_62344.tablet_alias]) utils.run_vtctl(["RefreshState", tablet_62344.tablet_alias]) # Quickly check basic actions. utils.run_vtctl(["SetReadOnly", tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.run_vtctl(["SetReadWrite", tablet_62344.tablet_alias]) utils.check_db_read_write(62344) utils.run_vtctl(["DemoteMaster", tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.validate_topology() utils.run_vtctl(["ValidateKeyspace", "test_keyspace"]) # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl(["ValidateShard", "-ping-tablets=false", "test_keyspace/0"]) self._check_srv_shard() tablet_62344.kill_vttablet()
def setup_tablets(): # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl('CreateKeyspace %s' % TEST_KEYSPACE) shard_0_master.init_tablet('master', keyspace=TEST_KEYSPACE, shard='0') shard_0_replica.init_tablet('replica', keyspace=TEST_KEYSPACE, shard='0') shard_1_master.init_tablet('master', keyspace=TEST_KEYSPACE, shard='1') shard_1_replica.init_tablet('replica', keyspace=TEST_KEYSPACE, shard='1') utils.run_vtctl('RebuildShardGraph %s/0' % TEST_KEYSPACE, auto_log=True) utils.run_vtctl('RebuildShardGraph %s/1' % TEST_KEYSPACE, auto_log=True) utils.validate_topology() shard_0_master.create_db(shard_0_master.dbname) shard_0_replica.create_db(shard_0_master.dbname) shard_1_master.create_db(shard_0_master.dbname) shard_1_replica.create_db(shard_0_master.dbname) setup_schema() utils.run_vtctl('RebuildKeyspaceGraph %s' % TEST_KEYSPACE, auto_log=True) zkocc_server = utils.zkocc_start() shard_0_master.start_vttablet() shard_0_replica.start_vttablet() shard_1_master.start_vttablet() shard_1_replica.start_vttablet() utils.run_vtctl('SetReadWrite ' + shard_0_master.tablet_alias) utils.run_vtctl('SetReadWrite ' + shard_1_master.tablet_alias) utils.check_db_read_write(62344) for t in [shard_0_master, shard_0_replica]: t.reset_replication() utils.run_vtctl('ReparentShard -force test_keyspace/0 ' + shard_0_master.tablet_alias, auto_log=True) for t in [shard_1_master, shard_1_replica]: t.reset_replication() utils.run_vtctl('ReparentShard -force test_keyspace/1 ' + shard_1_master.tablet_alias, auto_log=True) # then get the topology and check it zkocc_client = zkocc.ZkOccConnection("localhost:%u" % utils.zkocc_port_base, "test_nj", 30.0) topology.read_keyspaces(zkocc_client) shard_0_master_addrs = topology.get_host_port_by_name(zkocc_client, "test_keyspace.0.master:_vtocc") logging.debug(shard_0_master_addrs)
def run_test_sanity(): # Start up a master mysql and vttablet utils.run_vtctl('CreateKeyspace -force test_keyspace') utils.run_vtctl('CreateShard -force test_keyspace/0') tablet_62344.init_tablet('master', 'test_keyspace', '0', parent=False) utils.run_vtctl('RebuildShardGraph test_keyspace/0') utils.run_vtctl('RebuildKeyspaceGraph test_keyspace') utils.validate_topology() # if these statements don't run before the tablet it will wedge waiting for the # db to become accessible. this is more a bug than a feature. tablet_62344.populate('vt_test_keyspace', create_vt_select_test, populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away result, _ = utils.run_vtctl('Query test_nj test_keyspace "select * from vt_select_test"', trap_output=True) rows = result.splitlines() if len(rows) != 5: raise utils.TestError("expected 5 rows in vt_select_test", rows, result) # check Pings utils.run_vtctl('Ping ' + tablet_62344.tablet_alias) utils.run_vtctl('RpcPing ' + tablet_62344.tablet_alias) # Quickly check basic actions. utils.run_vtctl('SetReadOnly ' + tablet_62344.tablet_alias) utils.wait_db_read_only(62344) utils.run_vtctl('SetReadWrite ' + tablet_62344.tablet_alias) utils.check_db_read_write(62344) utils.run_vtctl('DemoteMaster ' + tablet_62344.tablet_alias) utils.wait_db_read_only(62344) utils.validate_topology() utils.run_vtctl('ValidateKeyspace test_keyspace') # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl('ValidateShard -ping-tablets=false test_keyspace/0') tablet_62344.kill_vttablet() tablet_62344.init_tablet('idle') tablet_62344.scrap(force=True)
def setup_tablets(): # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl('CreateKeyspace %s' % TEST_KEYSPACE) shard_0_master.init_tablet('master', keyspace=TEST_KEYSPACE, shard='0') shard_0_replica.init_tablet('replica', keyspace=TEST_KEYSPACE, shard='0') shard_1_master.init_tablet('master', keyspace=TEST_KEYSPACE, shard='1') shard_1_replica.init_tablet('replica', keyspace=TEST_KEYSPACE, shard='1') utils.run_vtctl('RebuildShardGraph %s/0' % TEST_KEYSPACE, auto_log=True) utils.run_vtctl('RebuildShardGraph %s/1' % TEST_KEYSPACE, auto_log=True) utils.validate_topology() shard_0_master.create_db(shard_0_master.dbname) shard_0_replica.create_db(shard_0_master.dbname) shard_1_master.create_db(shard_0_master.dbname) shard_1_replica.create_db(shard_0_master.dbname) utils.run_vtctl('RebuildKeyspaceGraph %s' % TEST_KEYSPACE, auto_log=True) zkocc_server = utils.zkocc_start() shard_0_master.start_vttablet() shard_0_replica.start_vttablet() shard_1_master.start_vttablet() shard_1_replica.start_vttablet() utils.run_vtctl('SetReadWrite ' + shard_0_master.tablet_alias) utils.run_vtctl('SetReadWrite ' + shard_1_master.tablet_alias) utils.check_db_read_write(62344) for t in [shard_0_master, shard_0_replica]: t.reset_replication() utils.run_vtctl('ReparentShard -force test_keyspace/0 ' + shard_0_master.tablet_alias, auto_log=True) for t in [shard_1_master, shard_1_replica]: t.reset_replication() utils.run_vtctl('ReparentShard -force test_keyspace/1 ' + shard_1_master.tablet_alias, auto_log=True) setup_schema() shard_0_master.vquery("set vt_schema_reload_time=86400", path="test_keyspace/0") shard_1_master.vquery("set vt_schema_reload_time=86400", path="test_keyspace/1") shard_0_replica.vquery("set vt_schema_reload_time=86400", path="test_keyspace/0") shard_1_replica.vquery("set vt_schema_reload_time=86400", path="test_keyspace/1")
def setUpModule(): global master_start_position try: environment.topo_server().setup() # start mysql instance external to the test setup_procs = [master_tablet.init_mysql(), replica_tablet.init_mysql()] utils.wait_procs(setup_procs) # start a vtctld so the vtctl insert commands are just RPCs, not forks utils.Vtctld().start() # Start up a master mysql and vttablet logging.debug('Setting up tablets') utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) master_tablet.init_tablet('master', 'test_keyspace', '0') replica_tablet.init_tablet('replica', 'test_keyspace', '0') utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0']) utils.validate_topology() master_tablet.create_db('vt_test_keyspace') master_tablet.create_db('other_database') replica_tablet.create_db('vt_test_keyspace') replica_tablet.create_db('other_database') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) utils.VtGate().start() master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl(['SetReadWrite', master_tablet.tablet_alias]) utils.check_db_read_write(master_tablet.tablet_uid) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl(['InitShardMaster', 'test_keyspace/0', master_tablet.tablet_alias], auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 master_start_position = _get_master_current_position() master_tablet.mquery('vt_test_keyspace', _create_vt_insert_test) master_tablet.mquery('vt_test_keyspace', _create_vt_a) master_tablet.mquery('vt_test_keyspace', _create_vt_b) utils.run_vtctl(['ReloadSchema', master_tablet.tablet_alias]) utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) # wait for the master and slave tablet's ReloadSchema to have worked timeout = 10 while True: try: master_tablet.execute('select count(1) from vt_insert_test') replica_tablet.execute('select count(1) from vt_insert_test') break except: logging.exception('query failed') timeout = utils.wait_step('slave tablet having correct schema', timeout) # also re-run ReloadSchema on slave, it case the first one # didn't get the replicated table. utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) except: tearDownModule() raise
def _test_sanity(self): # Start up a master mysql and vttablet utils.run_vtctl(['CreateKeyspace', '-force', 'test_keyspace']) utils.run_vtctl(['createshard', '-force', 'test_keyspace/0']) tablet_62344.init_tablet('master', 'test_keyspace', '0', parent=False) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) utils.validate_topology() # if these statements don't run before the tablet it will wedge # waiting for the db to become accessible. this is more a bug than # a feature. tablet_62344.populate('vt_test_keyspace', self._create_vt_select_test, self._populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away. qr = tablet_62344.execute('select id, msg from vt_select_test') self.assertEqual(len(qr['rows']), 4, 'expected 4 rows in vt_select_test: %s' % str(qr)) self.assertEqual(qr['fields'][0]['name'], 'id') self.assertEqual(qr['fields'][1]['name'], 'msg') # test exclude_field_names to vttablet works as expected. qr = tablet_62344.execute('select id, msg from vt_select_test', execute_options='included_fields:TYPE_ONLY ') self.assertEqual(len(qr['rows']), 4, 'expected 4 rows in vt_select_test: %s' % str(qr)) self.assertNotIn('name', qr['fields'][0]) self.assertNotIn('name', qr['fields'][1]) # make sure direct dba queries work query_result = utils.run_vtctl_json( ['ExecuteFetchAsDba', '-json', tablet_62344.tablet_alias, 'select * from vt_test_keyspace.vt_select_test']) self.assertEqual( len(query_result['rows']), 4, 'expected 4 rows in vt_select_test: %s' % str(query_result)) self.assertEqual( len(query_result['fields']), 2, 'expected 2 fields in vt_select_test: %s' % str(query_result)) # check Ping / RefreshState / RefreshStateByShard utils.run_vtctl(['Ping', tablet_62344.tablet_alias]) utils.run_vtctl(['RefreshState', tablet_62344.tablet_alias]) utils.run_vtctl(['RefreshStateByShard', 'test_keyspace/0']) utils.run_vtctl(['RefreshStateByShard', '--cells=test_nj', 'test_keyspace/0']) # Quickly check basic actions. utils.run_vtctl(['SetReadOnly', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.run_vtctl(['SetReadWrite', tablet_62344.tablet_alias]) utils.check_db_read_write(62344) utils.validate_topology() utils.run_vtctl(['ValidateKeyspace', 'test_keyspace']) # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl(['ValidateShard', '-ping-tablets=false', 'test_keyspace/0']) tablet_62344.kill_vttablet()
def _test_sanity(self): # Start up a master mysql and vttablet utils.run_vtctl(['CreateKeyspace', '-force', 'test_keyspace']) utils.run_vtctl(['createshard', '-force', 'test_keyspace/0']) tablet_62344.init_tablet('master', 'test_keyspace', '0', parent=False) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace']) utils.validate_topology() srvShard = utils.run_vtctl_json( ['GetSrvShard', 'test_nj', 'test_keyspace/0']) self.assertEqual(srvShard['MasterCell'], 'test_nj') # if these statements don't run before the tablet it will wedge # waiting for the db to become accessible. this is more a bug than # a feature. tablet_62344.populate('vt_test_keyspace', self._create_vt_select_test, self._populate_vt_select_test) tablet_62344.start_vttablet() # make sure the query service is started right away result, _ = utils.run_vtctl([ 'Query', 'test_nj', 'test_keyspace', 'select * from vt_select_test' ], mode=utils.VTCTL_VTCTL, trap_output=True) rows = result.splitlines() self.assertEqual( len(rows), 5, "expected 5 rows in vt_select_test: %s %s" % (str(rows), result)) # make sure direct dba queries work query_result = utils.run_vtctl_json([ 'ExecuteFetch', '-want_fields', tablet_62344.tablet_alias, 'select * from vt_test_keyspace.vt_select_test' ]) self.assertEqual( len(query_result['Rows']), 4, "expected 4 rows in vt_select_test: %s" % str(query_result)) self.assertEqual( len(query_result['Fields']), 2, "expected 2 fields in vt_select_test: %s" % str(query_result)) # check Ping / RefreshState utils.run_vtctl(['Ping', tablet_62344.tablet_alias]) utils.run_vtctl(['RefreshState', tablet_62344.tablet_alias]) # Quickly check basic actions. utils.run_vtctl(['SetReadOnly', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.run_vtctl(['SetReadWrite', tablet_62344.tablet_alias]) utils.check_db_read_write(62344) utils.run_vtctl(['DemoteMaster', tablet_62344.tablet_alias]) utils.wait_db_read_only(62344) utils.validate_topology() utils.run_vtctl(['ValidateKeyspace', 'test_keyspace']) # not pinging tablets, as it enables replication checks, and they # break because we only have a single master, no slaves utils.run_vtctl( ['ValidateShard', '-ping-tablets=false', 'test_keyspace/0']) srvShard = utils.run_vtctl_json( ['GetSrvShard', 'test_nj', 'test_keyspace/0']) self.assertEqual(srvShard['MasterCell'], 'test_nj') tablet_62344.kill_vttablet() tablet_62344.init_tablet('idle') tablet_62344.scrap(force=True)
def setUpModule(): global master_start_position try: environment.topo_server().setup() # start mysql instance external to the test setup_procs = [master_tablet.init_mysql(), replica_tablet.init_mysql()] utils.wait_procs(setup_procs) # start a vtctld so the vtctl insert commands are just RPCs, not forks utils.Vtctld().start() # Start up a master mysql and vttablet logging.debug('Setting up tablets') utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) master_tablet.init_tablet('master', 'test_keyspace', '0') replica_tablet.init_tablet('replica', 'test_keyspace', '0') utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0']) utils.validate_topology() master_tablet.create_db('vt_test_keyspace') master_tablet.create_db('other_database') replica_tablet.create_db('vt_test_keyspace') replica_tablet.create_db('other_database') utils.VtGate().start() master_tablet.start_vttablet() replica_tablet.start_vttablet() utils.run_vtctl(['SetReadWrite', master_tablet.tablet_alias]) utils.check_db_read_write(master_tablet.tablet_uid) for t in [master_tablet, replica_tablet]: t.reset_replication() utils.run_vtctl(['InitShardMaster', 'test_keyspace/0', master_tablet.tablet_alias], auto_log=True) # reset counter so tests don't assert tablet.Tablet.tablets_running = 0 master_start_position = _get_master_current_position() master_tablet.mquery('vt_test_keyspace', _create_vt_insert_test) master_tablet.mquery('vt_test_keyspace', _create_vt_a) master_tablet.mquery('vt_test_keyspace', _create_vt_b) utils.run_vtctl(['ReloadSchema', master_tablet.tablet_alias]) utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) # wait for the master and slave tablet's ReloadSchema to have worked timeout = 10 while True: try: master_tablet.execute('select count(1) from vt_insert_test') replica_tablet.execute('select count(1) from vt_insert_test') break except protocols_flavor().client_error_exception_type(): logging.exception('query failed') timeout = utils.wait_step('slave tablet having correct schema', timeout) # also re-run ReloadSchema on slave, it case the first one # didn't get the replicated table. utils.run_vtctl(['ReloadSchema', replica_tablet.tablet_alias]) except: tearDownModule() raise