• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tablet.mquery函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tablet.mquery函数的典型用法代码示例。如果您正苦于以下问题:Python mquery函数的具体用法?Python mquery怎么用?Python mquery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mquery函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _check_db_not_created

 def _check_db_not_created(self, tablet):
   # Broadly catch all exceptions, since the exception being raised
   # is internal to MySQL.  We're strictly checking the error message
   # though, so should be fine.
   with self.assertRaisesRegexp(
       Exception, '(1049, "Unknown database \'%s\'")' % db_name):
     tablet.mquery(db_name, 'show tables')
开发者ID:khanchan,项目名称:vitess,代码行数:7,代码来源:schema.py


示例2: _insert_values

  def _insert_values(self, tablet, id_offset, msg, keyspace_id, num_values):
    """Inserts values into MySQL along with the required routing comments.

    Args:
      tablet: the Tablet instance to modify.
      id: the value of `id` column.
      msg: the value of `msg` column.
      keyspace_id: the value of `keyspace_id` column.
    """

    # 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
    k = utils.uint64_to_hex(keyspace_id)
    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 '
              '/* vtgate:: keyspace_id:%s */' % (values_str, k),
              'commit'],
          write=True)
开发者ID:hadmagic,项目名称:vitess,代码行数:34,代码来源:worker.py


示例3: setUp

  def setUp(self):
    create_table = (
        'create table test (pk1 bigint, pk2 bigint, pk3 bigint, '
        'keyspace_id bigint, msg varchar(64), primary key (pk1, pk2, pk3)) '
        'Engine=InnoDB')
    destination_tablet.create_db('test_checkers')
    destination_tablet.mquery('test_checkers', create_table, True)
    for i, t in enumerate(source_tablets):
      t.create_db('test_checkers%s' % i)
      t.mquery('test_checkers%s' % i, create_table, True)

    destination_queries = []
    source_queries = [[] for t in source_tablets]
    for i in range(1, 400):
      query = (
          'insert into test (pk1, pk2, pk3, msg, keyspace_id) '
          "values (%s, %s, %s, 'message %s', %s)" % (i/100+1, i/10+1, i, i, i))
      destination_queries.append(query)
      source_queries[i % 2].append(query)
    for i in range(1100, 1110):
      query = (
          'insert into test (pk1, pk2, pk3, msg, keyspace_id) '
          "values (%s, %s, %s, 'message %s', %s)" % (i/100+1, i/10+1, i, i, i))
      source_queries[0].append(query)

    destination_tablet.mquery('test_checkers', destination_queries, write=True)
    for i, (tablet, queries) in enumerate(zip(source_tablets, source_queries)):
      tablet.mquery('test_checkers%s' % i, queries, write=True)
    self.c = self.make_checker()
开发者ID:richarwu,项目名称:vitess,代码行数:29,代码来源:checkers_test.py


示例4: _backfill_keyspace_id

 def _backfill_keyspace_id(self, tablet):
   tablet.mquery('vt_test_keyspace', [
       'begin',
       'update resharding1 set keyspace_id=0x1000000000000000 where id=1',
       'update resharding1 set keyspace_id=0x9000000000000000 where id=2',
       'update resharding1 set keyspace_id=0xD000000000000000 where id=3',
       'commit'
       ], write=True)
开发者ID:chengc017,项目名称:vitess,代码行数:8,代码来源:initial_sharding.py


示例5: _insert_value

 def _insert_value(self, tablet, table, id, msg, keyspace_id):
   k = utils.uint64_to_hex(keyspace_id)
   tablet.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, id, msg, keyspace_id, k, id),
        'commit'],
       write=True)
开发者ID:richarwu,项目名称:vitess,代码行数:10,代码来源:initial_sharding.py


示例6: _insert_value

 def _insert_value(self, tablet, table, id, msg, keyspace_id):
   if keyspace_id_type == keyrange_constants.KIT_BYTES:
     k = base64.b64encode(pack_keyspace_id(keyspace_id))
   else:
     k = "%u" % keyspace_id
   tablet.mquery('vt_test_keyspace', [
       'begin',
       'insert into %s(id, msg, keyspace_id) values(%u, "%s", 0x%x) /* EMD keyspace_id:%s user_id:%u */' % (table, id, msg, keyspace_id, k, id),
       'commit'
       ], write=True)
开发者ID:c0mpsc1,项目名称:vitess,代码行数:10,代码来源:resharding.py


示例7: _backfill_keyspace_id

 def _backfill_keyspace_id(self, tablet):
     tablet.mquery(
         "vt_test_keyspace",
         [
             "begin",
             "update resharding1 set keyspace_id=0x1000000000000000 where id=1",
             "update resharding1 set keyspace_id=0x9000000000000000 where id=2",
             "update resharding1 set keyspace_id=0xD000000000000000 where id=3",
             "commit",
         ],
         write=True,
     )
开发者ID:kingpro,项目名称:vitess,代码行数:12,代码来源:initial_sharding.py


示例8: _insert_value

 def _insert_value(self, tablet, table, id, msg, keyspace_id):
     k = utils.uint64_to_hex(keyspace_id)
     tablet.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, id, msg, keyspace_id, k, id),
             "commit",
         ],
         write=True,
     )
开发者ID:hadoop835,项目名称:vitess,代码行数:13,代码来源:resharding.py


示例9: _insert_value

  def _insert_value(self, tablet, id, msg, keyspace_id):
    """Inserts a value in the MySQL database along with the required routing comments.

    Args:
      tablet - the Tablet instance to insert into
      id - the value of `id` column
      msg - the value of `msg` column
      keyspace_id - the value of `keyspace_id` column
    """
    k = "%u" % keyspace_id
    tablet.mquery('vt_test_keyspace', [
        'begin',
        'insert into worker_test(id, msg, keyspace_id) values(%u, "%s", 0x%x) /* EMD keyspace_id:%s user_id:%u */' % (id, msg, keyspace_id, k, id),
        'commit'
        ], write=True)
开发者ID:OpsHA,项目名称:vitess,代码行数:15,代码来源:worker.py


示例10: _check_tables

 def _check_tables(self, tablet, expectedCount):
     tables = tablet.mquery(db_name, "show tables")
     self.assertEqual(
         len(tables),
         expectedCount,
         "Unexpected table count on %s (not %d): got tables: %s" % (tablet.tablet_alias, expectedCount, str(tables)),
     )
开发者ID:springlee,项目名称:vitess,代码行数:7,代码来源:schema.py


示例11: _check_values

 def _check_values(self, tablet, dbname, table, first, count):
     logging.debug("Checking %d values from %s/%s starting at %d", count, dbname, table, first)
     rows = tablet.mquery(dbname, "select id, msg from %s where id>=%d order by id limit %d" % (table, first, count))
     self.assertEqual(count, len(rows), "got wrong number of rows: %d != %d" % (len(rows), count))
     for i in xrange(count):
         self.assertEqual(first + i, rows[i][0], "invalid id[%d]: %d != %d" % (i, first + i, rows[i][0]))
         self.assertEqual(
             "value %d" % (first + i), rows[i][1], "invalid msg[%d]: 'value %d' != '%s'" % (i, first + i, rows[i][1])
         )
开发者ID:payintel,项目名称:vitess,代码行数:9,代码来源:vertical_split.py


示例12: _check_vt_insert_test

 def _check_vt_insert_test(self, tablet, index):
     # wait until it gets the data
     timeout = 10.0
     while True:
         result = tablet.mquery("vt_test_keyspace", "select msg from vt_insert_test where id=%d" % index)
         if len(result) == 1:
             break
         timeout = utils.wait_step(
             "waiting for replication to catch up on %s" % tablet.tablet_alias, timeout, sleep_time=0.1
         )
开发者ID:afrolovskiy,项目名称:vitess,代码行数:10,代码来源:reparent.py


示例13: check_value

def check_value(tablet, table, id, msg, keyspace_id, should_be_here=True):
  result = tablet.mquery('vt_test_keyspace', 'select id, msg, keyspace_id from %s where id=%u' % (table, id))
  if should_be_here:
    if len(result) != 1:
      raise utils.TestError("Missing row in tablet %s for id=%u, keyspace_id=%x" % (tablet.tablet_alias, id, keyspace_id))
    result = result[0]
    if result[0] != id or result[1] != msg or result[2] != keyspace_id:
      raise utils.TestError("Row mismatch in tablet %s for id=%u, keyspace_id=%x: %s" % (tablet.tablet_alias, id, keyspace_id, str(result)))
  else:
    if len(result) != 0:
      raise utils.TestError("Extra row in tablet %s for id=%u, keyspace_id=%x: %s" % (tablet.tablet_alias, id, keyspace_id, str(result[0])))
开发者ID:andredurao,项目名称:golang-stuff,代码行数:11,代码来源:resharding.py


示例14: _insert_values

  def _insert_values(self, tablet, id_offset, msg, keyspace_id, num_values):
    """Inserts values in the MySQL database along with the required routing comments.

    Args:
      tablet - the Tablet instance to insert into
      id - the value of `id` column
      msg - the value of `msg` column
      keyspace_id - the value of `keyspace_id` column
    """
    k = "%u" % keyspace_id
    values_str = ''
    for i in xrange(num_values):
      if i != 0:
        values_str += ','
      values_str += '(%u, "%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)
开发者ID:haoqoo,项目名称:vitess,代码行数:20,代码来源:worker.py


示例15: _check_values

 def _check_values(self, tablet, dbname, table, first, count):
   logging.debug('Checking %u values from %s/%s starting at %u', count, dbname,
                 table, first)
   rows = tablet.mquery(dbname, 'select id, msg from %s where id>=%u order by id limit %u' % (table, first, count))
   self.assertEqual(count, len(rows), 'got wrong number of rows: %u != %u' %
                    (len(rows), count))
   for i in xrange(count):
     self.assertEqual(first + i, rows[i][0], 'invalid id[%u]: %u != %u' %
                      (i, first + i, rows[i][0]))
     self.assertEqual('value %u' % (first + i), rows[i][1],
                      "invalid msg[%u]: 'value %u' != '%s'" %
                      (i, first + i, rows[i][1]))
开发者ID:afrolovskiy,项目名称:vitess,代码行数:12,代码来源:vertical_split.py


示例16: _insert_values

  def _insert_values(self, tablet, id_offset, msg, keyspace_id, num_values):
    """Inserts values into MySQL along with the required routing comments.

    Args:
      tablet: the Tablet instance to modify.
      id: the value of `id` column.
      msg: the value of `msg` column.
      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)
开发者ID:fengshao0907,项目名称:vitess,代码行数:22,代码来源:worker.py


示例17: direct_batch_write

def direct_batch_write(count, tablet):
  """Writes a number of rows directly to MySQL on a tablet.

  This is significantly faster than do_writes(), but it works by bypassing the
  entire VtTablet layer, and batches all the inserts into a single round-trip.
  This can cause unexpected behavior, so should be used sparingly.
  """
  master_conn = get_connection(db_type='master')
  master_conn.begin()
  master_conn._execute('delete from vt_insert_test', {})
  master_conn.commit()
  kid_list = shard_kid_map[master_conn.shard]
  values_str = ''
  for x in xrange(count):
    if x != 0:
      values_str += ','
    keyspace_id = kid_list[count%len(kid_list)]
    values_str += '("test %s", "%s")' % (x, keyspace_id)
  tablet.mquery('vt_test_keyspace', [
        'begin',
        'insert into vt_insert_test(msg, keyspace_id) values%s' % values_str,
        'commit'
        ], write=True)
开发者ID:fengshao0907,项目名称:vitess,代码行数:23,代码来源:vtdb_test.py


示例18: setUp

  def setUp(self):
    source_create_table = "create table test (pk1 bigint, k2 bigint, k3 bigint, keyspace_id bigint, msg varchar(64), primary key (pk1)) Engine=InnoDB"
    destination_create_table = "create table test_lookup (pk1_lookup bigint, msg_lookup varchar(64), primary key (pk1_lookup)) Engine=InnoDB"
    destination_tablet.create_db("test_checkers")
    destination_tablet.mquery("test_checkers", destination_create_table, True)

    for i, t in enumerate(source_tablets):
      t.create_db("test_checkers%s" % i)
      t.mquery("test_checkers%s" % i, source_create_table, True)

    destination_queries = []
    source_queries = [[] for t in source_tablets]
    for i in range(1, 400):
      destination_queries.append("insert into test_lookup (pk1_lookup, msg_lookup) values (%s, 'message %s')" % (i, i))
      source_queries[i % 2].append("insert into test (pk1, k2, k3, msg, keyspace_id) values (%s, %s, %s, 'message %s', %s)" % (i, i, i, i, i))
    for i in range(1100, 1110):
      query = "insert into test (pk1, k2, k3, msg, keyspace_id) values (%s, %s, %s, 'message %s', %s)" % (i, i, i, i, i)
      source_queries[0].append(query)

    destination_tablet.mquery("test_checkers", destination_queries, write=True)
    for i, (tablet, queries) in enumerate(zip(source_tablets, source_queries)):
      tablet.mquery("test_checkers%s" % i, queries, write=True)
    self.c = self.make_checker(destination_table_name="test_lookup", source_table_name="test", source_column_map={'pk1_lookup': 'pk1', 'msg_lookup': 'msg'})
开发者ID:Eric-Chen,项目名称:vitess,代码行数:23,代码来源:checkers_test.py


示例19: _insert_value

 def _insert_value(self, tablet, table, id, msg, keyspace_id):
   tablet.mquery('vt_test_keyspace', [
       'begin',
       'insert into %s(id, msg, keyspace_id) values(%u, "%s", 0x%x) /* EMD keyspace_id:%u user_id:%u */' % (table, id, msg, keyspace_id, keyspace_id, id),
       'commit'
       ], write=True)
开发者ID:billhongs,项目名称:vitess,代码行数:6,代码来源:resharding.py


示例20: check_tables

def check_tables(tablet, expectedCount):
    tables = tablet.mquery("vt_test_keyspace", "show tables")
    if len(tables) != expectedCount:
        raise utils.TestError(
            "Unexpected table count on %s (not %u): %s" % (tablet.tablet_alias, expectedCount, str(tables))
        )
开发者ID:Eric-Chen,项目名称:vitess,代码行数:6,代码来源:schema.py



注:本文中的tablet.mquery函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tablib.Dataset类代码示例发布时间:2022-05-27
下一篇:
Python tablet.kill_tablets函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap