예제 #1
0
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        shard_0_master.init_mysql(),
        shard_0_replica.init_mysql(),
        shard_0_ny_slave.init_mysql(),
        shard_1_master.init_mysql(),
        shard_1_slave1.init_mysql(),
        shard_1_slave2.init_mysql(),
        shard_1_ny_slave.init_mysql(),
        shard_1_rdonly.init_mysql(),
        shard_2_master.init_mysql(),
        shard_2_replica1.init_mysql(),
        shard_2_replica2.init_mysql(),
        shard_3_master.init_mysql(),
        shard_3_replica.init_mysql(),
        shard_3_rdonly.init_mysql(),
        ]
    utils.Vtctld().start()
    utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #2
0
 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
예제 #3
0
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [
            shard_0_master.init_mysql(),
            shard_0_replica.init_mysql(),
            shard_0_ny_slave.init_mysql(),
            shard_1_master.init_mysql(),
            shard_1_slave1.init_mysql(),
            shard_1_slave2.init_mysql(),
            shard_1_ny_slave.init_mysql(),
            shard_1_rdonly.init_mysql(),
            shard_2_master.init_mysql(),
            shard_2_replica1.init_mysql(),
            shard_2_replica2.init_mysql(),
            shard_3_master.init_mysql(),
            shard_3_replica.init_mysql(),
            shard_3_rdonly.init_mysql(),
        ]
        utils.Vtctld().start()
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #4
0
def setUpModule():
  try:
    environment.topo_server_setup()

  except:
    tearDownModule()
    raise
예제 #5
0
 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
예제 #6
0
파일: test_env.py 프로젝트: c0mpsc1/vitess
  def setUp(self):
    environment.topo_server_setup()

    utils.wait_procs([self.tablet.init_mysql()])
    self.tablet.mquery("", ["create database vt_test_keyspace", "set global read_only = off"])

    self.mysql_conn, mcu = self.tablet.connect('vt_test_keyspace')
    self.clean_sqls = []
    self.init_sqls = []
    clean_mode = False
    with open(os.path.join(self.vttop, "test", "test_data", "test_schema.sql")) as f:
      for line in f:
        line = line.rstrip()
        if line == "# clean":
          clean_mode = True
        if line=='' or line.startswith("#"):
          continue
        if clean_mode:
          self.clean_sqls.append(line)
        else:
          self.init_sqls.append(line)
    try:
      for line in self.init_sqls:
        mcu.execute(line, {})
    finally:
      mcu.close()

    utils.run_vtctl('CreateKeyspace -force test_keyspace')
    self.tablet.init_tablet('master', 'test_keyspace', '0')

    customrules = os.path.join(environment.tmproot, 'customrules.json')
    self.create_customrules(customrules)
    schema_override = os.path.join(environment.tmproot, 'schema_override.json')
    self.create_schema_override(schema_override)
    table_acl_config = os.path.join(environment.vttop, 'test', 'test_data', 'table_acl_config.json')
    self.tablet.start_vttablet(
            memcache=self.memcache,
            customrules=customrules,
            schema_override=schema_override,
            table_acl_config=table_acl_config,
            auth=True,
    )

    # FIXME(szopa): This is necessary here only because of a bug that
    # makes the qs reload its config only after an action.
    utils.run_vtctl('Ping ' + self.tablet.tablet_alias)

    for i in range(30):
      try:
        self.conn = self.connect()
        self.txlogger = utils.curl(self.url('/debug/txlog'), background=True, stdout=open(self.txlog_file, 'w'))
        self.txlog = framework.Tailer(open(self.txlog_file), flush=self.tablet.flush)
        self.log = framework.Tailer(open(os.path.join(environment.vtlogroot, 'vttablet.INFO')), flush=self.tablet.flush)
        break
      except dbexceptions.OperationalError:
        if i == 29:
          raise
        time.sleep(1)
    self.postSetup()
예제 #7
0
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
예제 #8
0
  def setUp(self):
    utils.wait_procs([self.tablet.init_mysql()])
    self.tablet.mquery("", ["create database vt_test_keyspace", "set global read_only = off"])

    self.mysql_conn, mcu = self.tablet.connect('vt_test_keyspace')
    with open(os.path.join(self.vttop, "test", "test_data", "test_schema.sql")) as f:
      self.clean_sqls = []
      self.init_sqls = []
      clean_mode = False
      for line in f:
        line = line.rstrip()
        if line == "# clean":
          clean_mode = True
        if line=='' or line.startswith("#"):
          continue
        if clean_mode:
          self.clean_sqls.append(line)
        else:
          self.init_sqls.append(line)
      try:
        for line in self.init_sqls:
          mcu.execute(line, {})
      finally:
        mcu.close()

    customrules = os.path.join(environment.tmproot, 'customrules.json')
    self.create_customrules(customrules)
    schema_override = os.path.join(environment.tmproot, 'schema_override.json')
    self.create_schema_override(schema_override)
    table_acl_config = os.path.join(environment.vttop, 'test', 'test_data', 'table_acl_config.json')

    if self.env == 'vttablet':
      environment.topo_server_setup()
      utils.run_vtctl('CreateKeyspace -force test_keyspace')
      self.tablet.init_tablet('master', 'test_keyspace', '0')
      self.tablet.start_vttablet(
              memcache=self.memcache,
              customrules=customrules,
              schema_override=schema_override,
              table_acl_config=table_acl_config,
              auth=True,
      )
    else:
      self.tablet.start_vtocc(
              memcache=self.memcache,
              customrules=customrules,
              schema_override=schema_override,
              table_acl_config=table_acl_config,
              auth=True,
              keyspace="test_keyspace", shard="0",
      )
    self.conn = self.connect()
    self.txlogger = utils.curl(self.url('/debug/txlog'), background=True, stdout=open(self.txlog_file, 'w'))
    self.txlog = framework.Tailer(open(self.txlog_file), flush=self.tablet.flush)
    self.log = framework.Tailer(open(os.path.join(environment.vtlogroot, '%s.INFO' % self.env)), flush=self.tablet.flush)
    self.querylog = Querylog(self)
예제 #9
0
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
예제 #10
0
파일: clone.py 프로젝트: rjammala/vitess
def setUpModule():
    try:
        environment.topo_server_setup()

        # start mysql instance external to the test
        setup_procs = [tablet_62344.init_mysql(), tablet_62044.init_mysql()]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #11
0
파일: vtctld_test.py 프로젝트: yyzi/vitess
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [t.init_mysql() for t in tablets]
        utils.wait_procs(setup_procs)
        vtctld.start()

    except:
        tearDownModule()
        raise
예제 #12
0
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [t.init_mysql() for t in tablets]
    utils.wait_procs(setup_procs)
    vtctld.start()

  except:
    tearDownModule()
    raise
예제 #13
0
파일: primecache.py 프로젝트: Abioy/vitess
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        master.init_mysql(),
        replica.init_mysql(),
        ]
    utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #14
0
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [
            master.init_mysql(),
            replica.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #15
0
파일: clone.py 프로젝트: yyzi/vitess
def setUpModule():
    try:
        environment.topo_server_setup()

        # start mysql instance external to the test
        setup_procs = [
            tablet_62344.init_mysql(),
            tablet_31981.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #16
0
def setUpModule():
  logging.debug("in setUpModule")
  try:
    environment.topo_server_setup()

    # start mysql instance external to the test
    setup_procs = [shard_0_master.init_mysql(),
                   shard_0_replica.init_mysql(),
                   shard_1_master.init_mysql(),
                   shard_1_replica.init_mysql()
                  ]
    utils.wait_procs(setup_procs)
    setup_tablets()
  except:
    tearDownModule()
    raise
예제 #17
0
파일: vtdb_test.py 프로젝트: yyzi/vitess
def setUpModule():
  logging.debug("in setUpModule")
  try:
    environment.topo_server_setup()

    # start mysql instance external to the test
    setup_procs = [shard_0_master.init_mysql(),
                   shard_0_replica.init_mysql(),
                   shard_1_master.init_mysql(),
                   shard_1_replica.init_mysql()
                  ]
    utils.wait_procs(setup_procs)
    setup_tablets()
  except:
    tearDownModule()
    raise
예제 #18
0
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [
            source_master.init_mysql(),
            source_replica.init_mysql(),
            source_rdonly.init_mysql(),
            destination_master.init_mysql(),
            destination_replica.init_mysql(),
            destination_rdonly.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #19
0
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        source_master.init_mysql(),
        source_replica.init_mysql(),
        source_rdonly.init_mysql(),
        destination_master.init_mysql(),
        destination_replica.init_mysql(),
        destination_rdonly.init_mysql(),

        ]
    utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #20
0
파일: schema.py 프로젝트: Abioy/vitess
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        shard_0_master.init_mysql(),
        shard_0_replica1.init_mysql(),
        shard_0_replica2.init_mysql(),
        shard_0_rdonly.init_mysql(),
        shard_0_backup.init_mysql(),
        shard_1_master.init_mysql(),
        shard_1_replica1.init_mysql(),
        ]
    utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #21
0
파일: schema.py 프로젝트: yyzi/vitess
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [
            shard_0_master.init_mysql(),
            shard_0_replica1.init_mysql(),
            shard_0_replica2.init_mysql(),
            shard_0_rdonly.init_mysql(),
            shard_0_backup.init_mysql(),
            shard_1_master.init_mysql(),
            shard_1_replica1.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #22
0
def setUpModule():
    try:
        if environment.topo_server_implementation == 'zookeeper':
            # this is a one-off test to make sure our zookeeper implementation
            # behaves with a server that is not DNS-resolveable
            environment.topo_server_setup(add_bad_host=True)
        else:
            environment.topo_server_setup()

        # start mysql instance external to the test
        setup_procs = [
            tablet_62344.init_mysql(),
            tablet_62044.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
    except:
        tearDownModule()
        raise
예제 #23
0
파일: clone.py 프로젝트: bigrats/vitess
def setUpModule():
  try:
    environment.topo_server_setup()

    # start mysql instance external to the test
    global setup_procs
    setup_procs = [
        tablet_62344.init_mysql(),
        tablet_31981.init_mysql(),
        ]
    if use_mysqlctld:
      tablet_62344.wait_for_mysql_socket()
      tablet_31981.wait_for_mysql_socket()
    else:
      utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #24
0
def setUpModule():
  try:
    if environment.topo_server_implementation == 'zookeeper':
      # this is a one-off test to make sure our zookeeper implementation
      # behaves with a server that is not DNS-resolveable
      environment.topo_server_setup(add_bad_host=True)
    else:
      environment.topo_server_setup()

    # start mysql instance external to the test
    setup_procs = [
        tablet_62344.init_mysql(),
        tablet_62044.init_mysql(),
        ]
    utils.wait_procs(setup_procs)
  except:
    tearDownModule()
    raise
예제 #25
0
def setUpModule():
    global vtgate_server
    global vtgate_port

    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(['RebuildKeyspaceGraph', 'test_keyspace'])
        utils.validate_topology()

        master_tablet.populate('vt_test_keyspace', create_vt_insert_test)
        replica_tablet.populate('vt_test_keyspace', create_vt_insert_test)

        vtgate_server, vtgate_port = utils.vtgate_start()

        master_tablet.start_vttablet(memcache=True, wait_for_state=None)
        replica_tablet.start_vttablet(memcache=True, wait_for_state=None)
        master_tablet.wait_for_vttablet_state('SERVING')
        replica_tablet.wait_for_vttablet_state('SERVING')

        utils.run_vtctl([
            'ReparentShard', '-force', 'test_keyspace/0',
            master_tablet.tablet_alias
        ],
                        auto_log=True)
        utils.validate_topology()

        # restart the replica tablet so the stats are reset
        replica_tablet.kill_vttablet()
        replica_tablet.start_vttablet(memcache=True)
    except:
        tearDownModule()
        raise
예제 #26
0
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        shard_0_master.init_mysql(),
        shard_0_replica.init_mysql(),
        shard_0_rdonly.init_mysql(),
        shard_1_master.init_mysql(),
        shard_1_replica.init_mysql(),
        shard_1_rdonly.init_mysql(),
        unsharded_master.init_mysql(),
        unsharded_replica.init_mysql(),
        unsharded_rdonly.init_mysql(),
        ]
    utils.wait_procs(setup_procs)
    setup_tablets()
  except:
    tearDownModule()
    raise
예제 #27
0
def setUpModule():
    try:
        environment.topo_server_setup()

        setup_procs = [
            shard_0_master.init_mysql(),
            shard_0_replica.init_mysql(),
            shard_0_rdonly.init_mysql(),
            shard_1_master.init_mysql(),
            shard_1_replica.init_mysql(),
            shard_1_rdonly.init_mysql(),
            unsharded_master.init_mysql(),
            unsharded_replica.init_mysql(),
            unsharded_rdonly.init_mysql(),
        ]
        utils.wait_procs(setup_procs)
        setup_tablets()
    except:
        tearDownModule()
        raise
예제 #28
0
def setUpModule():
  global vtgate_server
  global vtgate_port

  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(['RebuildKeyspaceGraph', 'test_keyspace'])
    utils.validate_topology()

    master_tablet.populate('vt_test_keyspace', create_vt_insert_test)
    replica_tablet.populate('vt_test_keyspace', create_vt_insert_test)

    vtgate_server, vtgate_port = utils.vtgate_start()

    master_tablet.start_vttablet(memcache=True, wait_for_state=None)
    replica_tablet.start_vttablet(memcache=True, wait_for_state=None)
    master_tablet.wait_for_vttablet_state('SERVING')
    replica_tablet.wait_for_vttablet_state('SERVING')

    utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/0',
                     master_tablet.tablet_alias], auto_log=True)
    utils.validate_topology()

    # restart the replica tablet so the stats are reset
    replica_tablet.kill_vttablet()
    replica_tablet.start_vttablet(memcache=True)
  except:
    tearDownModule()
    raise
예제 #29
0
파일: mysqlctl.py 프로젝트: bigrats/vitess
def setUpModule():
  try:
    environment.topo_server_setup()
    utils.Vtctld().start()

    setup_procs = [
        master_tablet.init_mysql(),
        replica_tablet.init_mysql(),
        ]
    utils.wait_procs(setup_procs)

    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.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True)

    master_tablet.create_db('vt_test_keyspace')
    replica_tablet.create_db('vt_test_keyspace')
  except:
    tearDownModule()
    raise
예제 #30
0
파일: mysqlctl.py 프로젝트: mydaisy2/vitess
def setUpModule():
    try:
        environment.topo_server_setup()
        utils.Vtctld().start()

        setup_procs = [
            master_tablet.init_mysql(),
            replica_tablet.init_mysql(),
        ]
        utils.wait_procs(setup_procs)

        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.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'],
                        auto_log=True)

        master_tablet.create_db('vt_test_keyspace')
        replica_tablet.create_db('vt_test_keyspace')
    except:
        tearDownModule()
        raise
예제 #31
0
파일: test_env.py 프로젝트: yyzi/vitess
    def setUp(self):
        environment.topo_server_setup()

        utils.wait_procs([self.tablet.init_mysql()])
        self.tablet.mquery(
            "",
            ["create database vt_test_keyspace", "set global read_only = off"])

        self.mysql_conn, mcu = self.tablet.connect('vt_test_keyspace')
        self.clean_sqls = []
        self.init_sqls = []
        clean_mode = False
        with open(
                os.path.join(self.vttop, "test", "test_data",
                             "test_schema.sql")) as f:
            for line in f:
                line = line.rstrip()
                if line == "# clean":
                    clean_mode = True
                if line == '' or line.startswith("#"):
                    continue
                if clean_mode:
                    self.clean_sqls.append(line)
                else:
                    self.init_sqls.append(line)
        try:
            for line in self.init_sqls:
                mcu.execute(line, {})
        finally:
            mcu.close()

        utils.run_vtctl('CreateKeyspace -force test_keyspace')
        self.tablet.init_tablet('master', 'test_keyspace', '0')

        customrules = os.path.join(environment.tmproot, 'customrules.json')
        self.create_customrules(customrules)
        schema_override = os.path.join(environment.tmproot,
                                       'schema_override.json')
        self.create_schema_override(schema_override)
        table_acl_config = os.path.join(environment.vttop, 'test', 'test_data',
                                        'table_acl_config.json')
        self.tablet.start_vttablet(
            memcache=self.memcache,
            customrules=customrules,
            schema_override=schema_override,
            table_acl_config=table_acl_config,
            auth=True,
        )

        # FIXME(szopa): This is necessary here only because of a bug that
        # makes the qs reload its config only after an action.
        utils.run_vtctl('Ping ' + self.tablet.tablet_alias)

        for i in range(30):
            try:
                self.conn = self.connect()
                self.txlogger = utils.curl(self.url('/debug/txlog'),
                                           background=True,
                                           stdout=open(self.txlog_file, 'w'))
                self.txlog = framework.Tailer(open(self.txlog_file),
                                              flush=self.tablet.flush)
                self.log = framework.Tailer(open(
                    os.path.join(environment.vtlogroot, 'vttablet.INFO')),
                                            flush=self.tablet.flush)
                break
            except dbexceptions.OperationalError:
                if i == 29:
                    raise
                time.sleep(1)
        self.postSetup()
예제 #32
0
파일: binlog.py 프로젝트: miffa/vitess
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        src_master.init_mysql(),
        src_replica.init_mysql(),
        dst_master.init_mysql(),
        dst_replica.init_mysql(),
        ]
    utils.Vtctld().start()
    utils.wait_procs(setup_procs)

    # Set up binlog stream from shard 0 to shard 1.
    # Modeled after initial_sharding.py.
    utils.run_vtctl(['CreateKeyspace', 'test_keyspace'])
    utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', 'test_keyspace',
                     'keyspace_id', keyrange_constants.KIT_UINT64])

    src_master.init_tablet('master', 'test_keyspace', '0')
    src_replica.init_tablet('replica', 'test_keyspace', '0')

    utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0'])
    utils.validate_topology()

    utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True)

    src_master.create_db('vt_test_keyspace')
    src_master.start_vttablet(wait_for_state=None)
    src_replica.create_db('vt_test_keyspace')
    src_replica.start_vttablet(wait_for_state=None)

    src_master.wait_for_vttablet_state('SERVING')
    src_replica.wait_for_vttablet_state('SERVING')

    utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/0',
                     src_master.tablet_alias], auto_log=True)

    # Create schema
    logging.debug("Creating schema...")
    create_table = '''create table test_table(
        id bigint auto_increment,
        keyspace_id bigint(20) unsigned,
        msg varchar(64),
        primary key (id),
        index by_msg (msg)
        ) Engine=InnoDB'''

    utils.run_vtctl(['ApplySchemaKeyspace',
                     '-simple',
                     '-sql=' + create_table,
                     'test_keyspace'], auto_log=True)

    # Create destination shard.
    dst_master.init_tablet('master', 'test_keyspace', '1')
    dst_replica.init_tablet('replica', 'test_keyspace', '1')
    dst_master.start_vttablet(wait_for_state='NOT_SERVING')
    dst_replica.start_vttablet(wait_for_state='NOT_SERVING')

    utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/1',
                     dst_master.tablet_alias], auto_log=True)
    utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True)

    # Start binlog stream from src_replica to dst_master.
    logging.debug("Starting binlog stream...")
    utils.run_vtctl(['MultiSnapshot', src_replica.tablet_alias], auto_log=True)
    src_replica.wait_for_binlog_server_state("Enabled")
    utils.run_vtctl(['ShardMultiRestore', '-strategy=populateBlpCheckpoint',
                     'test_keyspace/1', src_replica.tablet_alias], auto_log=True)
    dst_master.wait_for_binlog_player_count(1)

    # Wait for dst_replica to be ready.
    dst_replica.wait_for_binlog_server_state("Enabled")
  except:
    tearDownModule()
    raise
예제 #33
0
파일: binlog.py 프로젝트: chenwr0108/vitess
def setUpModule():
  try:
    environment.topo_server_setup()

    setup_procs = [
        src_master.init_mysql(),
        src_replica.init_mysql(),
        dst_master.init_mysql(),
        dst_replica.init_mysql(),
        ]
    utils.Vtctld().start()
    utils.wait_procs(setup_procs)

    # Set up binlog stream from shard 0 to shard 1.
    # Modeled after initial_sharding.py.
    utils.run_vtctl(['CreateKeyspace', 'test_keyspace'])
    utils.run_vtctl(['SetKeyspaceShardingInfo', '-force', 'test_keyspace',
                     'keyspace_id', keyrange_constants.KIT_UINT64])

    src_master.init_tablet('master', 'test_keyspace', '0')
    src_replica.init_tablet('replica', 'test_keyspace', '0')

    utils.run_vtctl(['RebuildShardGraph', 'test_keyspace/0'])
    utils.validate_topology()

    utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True)

    src_master.create_db('vt_test_keyspace')
    src_master.start_vttablet(wait_for_state=None)
    src_replica.create_db('vt_test_keyspace')
    src_replica.start_vttablet(wait_for_state=None)

    src_master.wait_for_vttablet_state('SERVING')
    src_replica.wait_for_vttablet_state('SERVING')

    utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/0',
                     src_master.tablet_alias], auto_log=True)

    # Create schema
    logging.debug("Creating schema...")
    create_table = '''create table test_table(
        id bigint auto_increment,
        keyspace_id bigint(20) unsigned,
        msg varchar(64),
        primary key (id),
        index by_msg (msg)
        ) Engine=InnoDB'''

    utils.run_vtctl(['ApplySchemaKeyspace',
                     '-simple',
                     '-sql=' + create_table,
                     'test_keyspace'], auto_log=True)

    # Create destination shard.
    dst_master.init_tablet('master', 'test_keyspace', '1')
    dst_replica.init_tablet('replica', 'test_keyspace', '1')
    dst_master.start_vttablet(wait_for_state='NOT_SERVING')
    dst_replica.start_vttablet(wait_for_state='NOT_SERVING')

    utils.run_vtctl(['ReparentShard', '-force', 'test_keyspace/1',
                     dst_master.tablet_alias], auto_log=True)
    utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'], auto_log=True)

    # Start binlog stream from src_replica to dst_master.
    logging.debug("Starting binlog stream...")
    utils.run_vtctl(['MultiSnapshot', src_replica.tablet_alias], auto_log=True)
    src_replica.wait_for_binlog_server_state("Enabled")
    utils.run_vtctl(['ShardMultiRestore', '-strategy=-populate_blp_checkpoint',
                     'test_keyspace/1', src_replica.tablet_alias], auto_log=True)
    dst_master.wait_for_binlog_player_count(1)

    # Wait for dst_replica to be ready.
    dst_replica.wait_for_binlog_server_state("Enabled")
  except:
    tearDownModule()
    raise