From 9398d0d6d63135cc0239946a292fdf43e1f5a44c Mon Sep 17 00:00:00 2001 From: frf12 Date: Wed, 29 Jun 2022 11:10:02 +0800 Subject: [PATCH] v1.4.0 --- _cmd.py | 2 +- plugins/tpcc/3.1.0/build.py | 40 +++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/_cmd.py b/_cmd.py index 95d4da8..9fa11b7 100644 --- a/_cmd.py +++ b/_cmd.py @@ -910,7 +910,7 @@ class TestMajorCommand(MajorCommand): self.register_command(MySQLTestCommand()) self.register_command(SysBenchCommand()) self.register_command(TPCHCommand()) - # self.register_command(TPCCCommand()) + self.register_command(TPCCCommand()) class BenchMajorCommand(MajorCommand): diff --git a/plugins/tpcc/3.1.0/build.py b/plugins/tpcc/3.1.0/build.py index 7134161..8c052bd 100644 --- a/plugins/tpcc/3.1.0/build.py +++ b/plugins/tpcc/3.1.0/build.py @@ -42,6 +42,18 @@ def build(plugin_context, cursor, odp_cursor, *args, **kwargs): def local_execute_command(command, env=None, timeout=None): return LocalClient.execute_command(command, env, timeout, stdio) + def execute(cursor, query, args=None): + msg = query % tuple(args) if args is not None else query + stdio.verbose('execute sql: %s' % msg) + stdio.verbose("query: %s. args: %s" % (query, args)) + try: + cursor.execute(query, args) + return cursor.fetchone() + except: + msg = 'execute sql exception: %s' % msg + stdio.exception(msg) + raise Exception(msg) + def run_sql(sql_file, force=False): sql_cmd = "{obclient} -h{host} -P{port} -u{user}@{tenant} {password_arg} -A {db} {force_flag} < {sql_file}".format( obclient=obclient_bin, host=host, port=port, user=user, tenant=tenant_name, @@ -130,22 +142,30 @@ def build(plugin_context, cursor, odp_cursor, *args, **kwargs): stdio.exception('') return stdio.stop_loading('succeed') + # drop old tables bmsql_sql_path = kwargs.get('bmsql_sql_path', '') run_sql(sql_file=os.path.join(bmsql_sql_path, 'tableDrops.sql'), force=True) - retries = 300 - pending_free_count = -1 - while pending_free_count != 0 and retries > 0: - retries -= 1 - sql = 'select pending_free_count from oceanbase.__all_virtual_macro_block_marker_status' - stdio.verbose('execute sql: %s' % sql) - cursor.execute(sql) - ret = cursor.fetchone() - stdio.verbose('sql result: %s' % ret) - pending_free_count = ret.get('pending_free_count', 0) if ret else 0 + merge_version = execute(cursor, "select value from oceanbase.__all_zone where name='frozen_version'")['value'] + stdio.start_loading('Merge') + execute(cursor, 'alter system major freeze') + sql = "select value from oceanbase.__all_zone where name='frozen_version' and value != %s" % merge_version + while True: + if execute(cursor, sql): + break time.sleep(1) + while True: + if not execute(cursor, """select * from oceanbase.__all_zone + where name='last_merged_version' + and value != (select value from oceanbase.__all_zone where name='frozen_version' limit 1) + and zone in (select zone from oceanbase.__all_zone where name='status' and info = 'ACTIVE') + """): + break + time.sleep(5) + stdio.stop_loading('succeed') + # create new tables if not run_sql(sql_file=os.path.join(bmsql_sql_path, 'tableCreates.sql')): stdio.error('create tables failed') -- GitLab