提交 61671472 编写于 作者: J Jacob Champion 提交者: Jacob Champion

isolation2: add a master-and-primary utility command

The '*U:' command flag will connect to the master and all primaries to
execute its query. The intended use case is for easy testing of
distributed catalog changes.
上级 9698d51f
......@@ -40,7 +40,7 @@ class SQLIsolationExecutor(object):
# The re.S flag makes the "." in the regex match newlines.
# When matched against a command in process_command(), all
# lines in the command are matched and sent as SQL query.
self.command_pattern = re.compile(r"^(-?\d+)([&\\<\\>Uq]*?)\:(.*)", re.S)
self.command_pattern = re.compile(r"^(-?\d+|[*])([&\\<\\>Uq]*?)\:(.*)", re.S)
if dbname:
self.dbname = dbname
else:
......@@ -258,6 +258,20 @@ class SQLIsolationExecutor(object):
self.processes[(name, utility_mode)].quit()
del self.processes[(name, utility_mode)]
def get_all_primary_contentids(self, dbname):
"""
Retrieves all primary content IDs (including the master). Intended for
use by *U queries.
"""
if not dbname:
dbname = self.dbname
con = pygresql.pg.connect(dbname=dbname)
result = con.query("SELECT content FROM gp_segment_configuration WHERE role = 'p'").getresult()
if len(result) == 0:
raise Exception("Invalid gp_segment_configuration contents")
return [int(content[0]) for content in result]
def process_command(self, command, output_file):
"""
Processes the given command.
......@@ -328,7 +342,13 @@ class SQLIsolationExecutor(object):
raise Exception("No query should be given on quit")
self.quit_process(output_file, process_name, dbname=dbname)
elif flag == "U":
self.get_process(output_file, process_name, utility_mode=True, dbname=dbname).query(sql.strip())
if process_name == '*':
process_names = [str(content) for content in self.get_all_primary_contentids(dbname)]
else:
process_names = [process_name]
for name in process_names:
self.get_process(output_file, name, utility_mode=True, dbname=dbname).query(sql.strip())
elif flag == "U&":
self.get_process(output_file, process_name, utility_mode=True, dbname=dbname).fork(sql.strip(), True)
elif flag == "U<":
......@@ -384,7 +404,10 @@ class SQLIsolationTestCase:
executing transactions. This is mainly used to test isolation behavior.
[<#>[flag]:] <sql> | ! <shell scripts or command>
#: just any integer indicating an unique session or content-id if followed by U
#: either an integer indicating an unique session, or a content-id if
followed by U (for utility-mode connections). In 'U' mode, the
content-id can alternatively be an asterisk '*' to perform a
utility-mode query on the master and all primaries.
flag:
&: expect blocking behavior
>: running in background without blocking
......@@ -392,8 +415,8 @@ class SQLIsolationTestCase:
q: quit the given session
U: connect in utility mode to primary contentid from gp_segment_configuration
U&: expect blocking behavior in utility mode
U<: join an existing utility mode session
U&: expect blocking behavior in utility mode (does not currently support an asterisk target)
U<: join an existing utility mode session (does not currently support an asterisk target)
An example is:
......@@ -477,6 +500,22 @@ class SQLIsolationTestCase:
2q: ---> Will quit the session established with test2db.
The subsequent 2: @db_name test: <sql> will open a new session with the database test and execute the sql against that session.
Catalog Modification:
Some tests are easier to write if it's possible to modify a system
catalog across the *entire* cluster. To perform a utility-mode query on
all segments and the master, you can use *U commands:
*U: SET allow_system_table_mods = 'DML';
*U: UPDATE pg_catalog.<table> SET <column> = <value> WHERE <cond>;
Since the number of query results returned by a *U command depends on
the developer's cluster configuration, it can be useful to wrap them in
a start_/end_ignore block. (Unfortunately, this also hides legitimate
failures; a better long-term solution is needed.)
Block/join flags are not currently supported with *U.
"""
def run_sql_file(self, sql_file, out_file = None, out_dir = None, optimizer = None):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册