def set_up(self): try: environment.topo_server_setup() utils.wait_procs([t.init_mysql() for t in self.tablets]) utils.run_vtctl(['CreateKeyspace', self.keyspace]) utils.run_vtctl([ 'SetKeyspaceShardingInfo', '-force', self.keyspace, 'keyspace_id', 'uint64' ]) for t in self.tablets: t.init_tablet(t.type, keyspace=self.keyspace, shard=t.shard) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) for t in self.tablets: t.create_db('vt_' + self.keyspace) t.mquery(t.dbname, create_table) t.start_vttablet(wait_for_state=None) for t in self.tablets: t.wait_for_vttablet_state('SERVING') for t in self.tablets: if t.type == "master": utils.run_vtctl([ 'ReparentShard', '-force', self.keyspace + '/' + t.shard, t.tablet_alias ], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) self.vtgate_server, self.vtgate_port = utils.vtgate_start() vtgate_client = zkocc.ZkOccConnection( "localhost:%u" % self.vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client) except: self.shutdown() raise
def set_up(self): try: environment.topo_server_setup() utils.wait_procs([t.init_mysql() for t in self.tablets]) utils.run_vtctl(['CreateKeyspace', self.keyspace]) utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', self.keyspace, 'keyspace_id', 'uint64']) for t in self.tablets: t.init_tablet(t.type, keyspace=self.keyspace, shard=t.shard) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) for t in self.tablets: t.create_db('vt_' + self.keyspace) t.mquery(t.dbname, create_table) t.start_vttablet(wait_for_state=None) for t in self.tablets: t.wait_for_vttablet_state('SERVING') for t in self.tablets: if t.type == "master": utils.run_vtctl(['ReparentShard', '-force', self.keyspace+'/'+t.shard, t.tablet_alias], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) self.vtgate_server, self.vtgate_port = utils.vtgate_start() vtgate_client = zkocc.ZkOccConnection("localhost:%u" % self.vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client) except: self.shutdown() raise
def set_up(self): try: environment.topo_server().setup() utils.wait_procs([t.init_mysql() for t in self.tablets]) utils.run_vtctl(['CreateKeyspace', self.keyspace]) utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', self.keyspace, 'keyspace_id', 'uint64']) for t in self.tablets: t.init_tablet(t.type, keyspace=self.keyspace, shard=t.shard) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) for t in self.tablets: t.create_db('vt_' + self.keyspace) t.start_vttablet( wait_for_state=None, extra_args=['-queryserver-config-schema-reload-time', '1'], ) for t in self.tablets: t.wait_for_vttablet_state('SERVING') for t in self.tablets: if t.type == "master": utils.run_vtctl(['ReparentShard', '-force', self.keyspace+'/'+t.shard, t.tablet_alias], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) if self.schema: utils.run_vtctl(['ApplySchemaKeyspace', '-simple', '-sql', self.schema, self.keyspace]) if self.vschema: if self.vschema[0] == '{': utils.run_vtctl(['ApplyVSchema', "-vschema", self.vschema]) else: utils.run_vtctl(['ApplyVSchema', "-vschema_file", self.vschema]) self.vtgate_server, self.vtgate_port = utils.vtgate_start(cache_ttl='500s', vtport=self.vtgate_port) vtgate_client = zkocc.ZkOccConnection("localhost:%u" % self.vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client) except: self.shutdown() raise
def setup_tablets(): global vtgate_server global vtgate_port # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) utils.run_vtctl([ 'SetKeyspaceShardingInfo', '-force', 'test_keyspace', 'keyspace_id', 'uint64' ]) shard_0_master.init_tablet('master', keyspace='test_keyspace', shard='-80') shard_0_replica.init_tablet('replica', keyspace='test_keyspace', shard='-80') shard_1_master.init_tablet('master', keyspace='test_keyspace', shard='80-') shard_1_replica.init_tablet('replica', keyspace='test_keyspace', shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.create_db('vt_test_keyspace') t.mquery(shard_0_master.dbname, create_vt_insert_test) t.mquery(shard_0_master.dbname, create_vt_a) t.start_vttablet(wait_for_state=None) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl([ 'ReparentShard', '-force', 'test_keyspace/-80', shard_0_master.tablet_alias ], auto_log=True) utils.run_vtctl([ 'ReparentShard', '-force', 'test_keyspace/80-', shard_1_master.tablet_alias ], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) utils.check_srv_keyspace( 'test_nj', 'test_keyspace', 'Partitions(master): -80 80-\n' + 'Partitions(replica): -80 80-\n' + 'TabletTypes: master,replica') vtgate_server, vtgate_port = utils.vtgate_start() vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client)
def setup_tablets(): global vtgate_server global vtgate_port # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(['CreateKeyspace', KEYSPACE_NAME]) utils.run_vtctl([ 'SetKeyspaceShardingInfo', '-force', KEYSPACE_NAME, 'keyspace_id', 'uint64' ]) shard_0_master.init_tablet('master', keyspace=KEYSPACE_NAME, shard='-80') shard_0_replica.init_tablet('replica', keyspace=KEYSPACE_NAME, shard='-80') shard_1_master.init_tablet('master', keyspace=KEYSPACE_NAME, shard='80-') shard_1_replica.init_tablet('replica', keyspace=KEYSPACE_NAME, shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', KEYSPACE_NAME], auto_log=True) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.create_db('vt_test_keyspace') for create_table in create_tables: t.mquery(shard_0_master.dbname, create_table) t.start_vttablet(wait_for_state=None) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl([ 'ReparentShard', '-force', KEYSPACE_NAME + '/-80', shard_0_master.tablet_alias ], auto_log=True) utils.run_vtctl([ 'ReparentShard', '-force', KEYSPACE_NAME + '/80-', shard_1_master.tablet_alias ], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', KEYSPACE_NAME], auto_log=True) utils.check_srv_keyspace( 'test_nj', KEYSPACE_NAME, 'Partitions(master): -80 80-\n' + 'Partitions(replica): -80 80-\n' + 'TabletTypes: master,replica') vtgate_server, vtgate_port = utils.vtgate_start() # FIXME(shrutip): this should be removed once vtgate_cursor's # dependency on topology goes away. vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client)
def setup_tablets(): # Start up a master mysql and vttablet logging.debug('Setting up tablets') utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) utils.run_vtctl([ 'SetKeyspaceShardingInfo', '-force', 'test_keyspace', 'keyspace_id', 'uint64' ]) shard_0_master.init_tablet('master', keyspace='test_keyspace', shard='-80') shard_0_replica.init_tablet('replica', keyspace='test_keyspace', shard='-80') shard_1_master.init_tablet('master', keyspace='test_keyspace', shard='80-') shard_1_replica.init_tablet('replica', keyspace='test_keyspace', shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.create_db('vt_test_keyspace') t.mquery(shard_0_master.dbname, create_vt_insert_test) t.mquery(shard_0_master.dbname, create_vt_a) t.start_vttablet(wait_for_state=None) for t in [ shard_0_master, shard_0_replica, shard_1_master, shard_1_replica ]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl( ['InitShardMaster', 'test_keyspace/-80', shard_0_master.tablet_alias], auto_log=True) utils.run_vtctl( ['InitShardMaster', 'test_keyspace/80-', shard_1_master.tablet_alias], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) utils.check_srv_keyspace( 'test_nj', 'test_keyspace', 'Partitions(master): -80 80-\n' 'Partitions(rdonly): -80 80-\n' 'Partitions(replica): -80 80-\n') utils.VtGate().start() vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), 'test_nj', 30.0) topology.read_topology(vtgate_client)
def set_up(self): try: environment.topo_server().setup() utils.wait_procs([t.init_mysql() for t in self.tablets]) utils.run_vtctl(['CreateKeyspace', self.keyspace]) utils.run_vtctl([ 'SetKeyspaceShardingInfo', '-force', self.keyspace, 'keyspace_id', 'uint64' ]) for t in self.tablets: t.init_tablet(t.type, keyspace=self.keyspace, shard=t.shard) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) for t in self.tablets: t.create_db('vt_' + self.keyspace) t.start_vttablet( wait_for_state=None, extra_args=['-queryserver-config-schema-reload-time', '1'], ) for t in self.tablets: t.wait_for_vttablet_state('SERVING') for t in self.tablets: if t.type == "master": utils.run_vtctl([ 'ReparentShard', '-force', self.keyspace + '/' + t.shard, t.tablet_alias ], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', self.keyspace], auto_log=True) if self.schema: utils.run_vtctl([ 'ApplySchemaKeyspace', '-simple', '-sql', self.schema, self.keyspace ]) if self.vschema: if self.vschema[0] == '{': utils.run_vtctl(['ApplyVSchema', "-vschema", self.vschema]) else: utils.run_vtctl( ['ApplyVSchema', "-vschema_file", self.vschema]) self.vtgate_server, self.vtgate_port = utils.vtgate_start( cache_ttl='500s') vtgate_client = zkocc.ZkOccConnection( "localhost:%u" % self.vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client) except: self.shutdown() raise
def setup_tablets(): global vtgate_server global vtgate_port # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(['CreateKeyspace', KEYSPACE_NAME]) utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', KEYSPACE_NAME, 'keyspace_id', 'uint64']) shard_0_master.init_tablet('master', keyspace=KEYSPACE_NAME, shard='-80') shard_0_replica.init_tablet('replica', keyspace=KEYSPACE_NAME, shard='-80') shard_1_master.init_tablet('master', keyspace=KEYSPACE_NAME, shard='80-') shard_1_replica.init_tablet('replica', keyspace=KEYSPACE_NAME, shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', KEYSPACE_NAME], auto_log=True) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.create_db('vt_test_keyspace') for create_table in create_tables: t.mquery(shard_0_master.dbname, create_table) t.start_vttablet(wait_for_state=None) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl(['ReparentShard', '-force', KEYSPACE_NAME+'/-80', shard_0_master.tablet_alias], auto_log=True) utils.run_vtctl(['ReparentShard', '-force', KEYSPACE_NAME+'/80-', shard_1_master.tablet_alias], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', KEYSPACE_NAME], auto_log=True) utils.check_srv_keyspace('test_nj', KEYSPACE_NAME, 'Partitions(master): -80 80-\n' + 'Partitions(replica): -80 80-\n' + 'TabletTypes: master,replica') vtgate_server, vtgate_port = utils.vtgate_start() # FIXME(shrutip): this should be removed once vtgate_cursor's # dependency on topology goes away. vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client)
def setup_tablets(): global vtgate_server global vtgate_port # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', 'test_keyspace', 'keyspace_id', 'uint64']) shard_0_master.init_tablet('master', keyspace='test_keyspace', shard='-80') shard_0_replica.init_tablet('replica', keyspace='test_keyspace', shard='-80') shard_1_master.init_tablet('master', keyspace='test_keyspace', shard='80-') shard_1_replica.init_tablet('replica', keyspace='test_keyspace', shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.create_db('vt_test_keyspace') t.mquery(shard_0_master.dbname, create_vt_insert_test) t.mquery(shard_0_master.dbname, create_vt_a) t.start_vttablet(wait_for_state=None) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/-80', shard_0_master.tablet_alias], auto_log=True) utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/80-', shard_1_master.tablet_alias], auto_log=True) utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) utils.check_srv_keyspace('test_nj', 'test_keyspace', 'Partitions(master): -80 80-\n' + 'Partitions(replica): -80 80-\n' + 'TabletTypes: master,replica') vtgate_server, vtgate_port = utils.vtgate_start() vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client)
def setup_tablets(): # Start up a master mysql and vttablet logging.debug('Setting up tablets') utils.run_vtctl(['CreateKeyspace', 'test_keyspace']) utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', 'test_keyspace', 'keyspace_id', 'uint64']) shard_0_master.init_tablet('master', keyspace='test_keyspace', shard='-80') shard_0_replica.init_tablet('replica', keyspace='test_keyspace', shard='-80') shard_1_master.init_tablet('master', keyspace='test_keyspace', shard='80-') shard_1_replica.init_tablet('replica', keyspace='test_keyspace', shard='80-') utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.create_db('vt_test_keyspace') t.mquery(shard_0_master.dbname, create_vt_insert_test) t.mquery(shard_0_master.dbname, create_vt_a) t.start_vttablet(wait_for_state=None) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.wait_for_vttablet_state('SERVING') utils.run_vtctl( ['InitShardMaster', 'test_keyspace/-80', shard_0_master.tablet_alias], auto_log=True) utils.run_vtctl( ['InitShardMaster', 'test_keyspace/80-', shard_1_master.tablet_alias], auto_log=True) utils.run_vtctl( ['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True) utils.check_srv_keyspace('test_nj', 'test_keyspace', 'Partitions(master): -80 80-\n' 'Partitions(rdonly): -80 80-\n' 'Partitions(replica): -80 80-\n') utils.VtGate().start() vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), 'test_nj', 30.0) topology.read_topology(vtgate_client)
def setup_tablets(): global vtgate_server global vtgate_port # Start up a master mysql and vttablet logging.debug("Setting up tablets") utils.run_vtctl(["CreateKeyspace", "test_keyspace"]) utils.run_vtctl(["SetKeyspaceShardingInfo", "-force", "test_keyspace", "keyspace_id", "uint64"]) shard_0_master.init_tablet("master", keyspace="test_keyspace", shard="-80") shard_0_replica.init_tablet("replica", keyspace="test_keyspace", shard="-80") shard_1_master.init_tablet("master", keyspace="test_keyspace", shard="80-") shard_1_replica.init_tablet("replica", keyspace="test_keyspace", shard="80-") utils.run_vtctl(["RebuildKeyspaceGraph", "test_keyspace"], auto_log=True) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.create_db("vt_test_keyspace") t.mquery(shard_0_master.dbname, create_vt_insert_test) t.mquery(shard_0_master.dbname, create_vt_a) t.start_vttablet(wait_for_state=None) for t in [shard_0_master, shard_0_replica, shard_1_master, shard_1_replica]: t.wait_for_vttablet_state("SERVING") utils.run_vtctl(["ReparentShard", "-force", "test_keyspace/-80", shard_0_master.tablet_alias], auto_log=True) utils.run_vtctl(["ReparentShard", "-force", "test_keyspace/80-", shard_1_master.tablet_alias], auto_log=True) utils.run_vtctl(["RebuildKeyspaceGraph", "test_keyspace"], auto_log=True) utils.check_srv_keyspace( "test_nj", "test_keyspace", "Partitions(master): -80 80-\n" + "Partitions(replica): -80 80-\n" + "TabletTypes: master,replica", ) vtgate_server, vtgate_port = utils.vtgate_start() vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client)
def main(): env = TestEnv(options) if args and args[0] == 'setup': env.set_up() # prime the vtgate topology cache, so if the topo service goes away # when we exit this python script, the cache is already primed. vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), "test_nj", 30.0) topology.read_topology(vtgate_client) sys.stdout.write(json.dumps({ "port": utils.vtgate.port, }) + "\n") sys.stdout.flush() elif args and args[0] == 'teardown': env.shutdown() else: env.set_up() sys.stdout.write(json.dumps({ "port": utils.vtgate.port, }) + "\n") sys.stdout.flush() raw_input() env.shutdown()
def setUpModule(): global vtgate_server, vtgate_port logging.debug("in setUpModule") try: environment.topo_server().setup() setup_topology() # start mysql instance external to the test global __tablets setup_procs = [] for tablet in __tablets: setup_procs.append(tablet.init_mysql()) utils.wait_procs(setup_procs) create_db() start_tablets() vtgate_server, vtgate_port = utils.vtgate_start() # FIXME(shrutip): this should be removed once vtgate_cursor's # dependency on topology goes away. vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(vtgate_client) except: tearDownModule() raise
def setUp(self): self.vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), "test_nj", 30.0) topology.read_topology(self.vtgate_client) self.perform_insert(400)
# Parse args parser = argparse.ArgumentParser() parser.add_argument('--server', dest='server', default='localhost:15001') parser.add_argument('--timeout', dest='timeout', type=float, default='10.0') args = parser.parse_args() vtgate_addrs = {"_vt": [args.server]} # Connect conn = vtgatev2.connect(vtgate_addrs, args.timeout) # Read topology # This is a temporary work-around until the VTGate V2 client is topology-free. topoconn = zkocc.ZkOccConnection(args.server, 'test_cell', args.timeout) topology.read_topology(topoconn) topoconn.close() # Insert something. print('Inserting into master...') cursor = conn.cursor(cursorclass, conn, 'test_keyspace', 'master', keyranges=UNSHARDED, writable=True) cursor.begin() cursor.execute( "INSERT INTO test_table (msg) VALUES (%(msg)s)", {'msg': 'V is for speed'}) cursor.commit() # Read it back from the master. print('Reading from master...')
def setUp(self): self.vtgate_client = zkocc.ZkOccConnection(vtgate_socket_file, "test_nj", 30.0) topology.read_topology(self.vtgate_client)
def _populate_topo_cache(self): topology.read_topology(self.vtgate_client)
def setUp(self): self.vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) topology.read_topology(self.vtgate_client) self.perform_insert(400)
# Parse args parser = argparse.ArgumentParser() parser.add_argument('--server', dest='server', default='localhost:15001') parser.add_argument('--timeout', dest='timeout', type=float, default='10.0') args = parser.parse_args() vtgate_addrs = {"vt": [args.server]} # Connect conn = vtgatev2.connect(vtgate_addrs, args.timeout) # Read topology # This is a temporary work-around until the VTGate V2 client is topology-free. topoconn = zkocc.ZkOccConnection(args.server, 'test', args.timeout) topology.read_topology(topoconn) topoconn.close() # Insert something. print('Inserting into master...') cursor = conn.cursor('test_keyspace', 'master', keyranges=UNSHARDED, writable=True) cursor.begin() cursor.execute( "INSERT INTO test_table (msg) VALUES (%(msg)s)", {'msg': 'V is for speed'}) cursor.commit() # Read it back from the master. print('Reading from master...')
def setUp(self): self.vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), 'test_nj', 30.0) topology.read_topology(self.vtgate_client)