Skip to content

Commit

Permalink
Merge pull request #6415 from drmingdrmer/2-fix-openraft
Browse files Browse the repository at this point in the history
chore(metasrv): explain why "join" not work in log
  • Loading branch information
BohuTANG authored Jul 3, 2022
2 parents abb3428 + 0d5e1d7 commit 295480b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
4 changes: 2 additions & 2 deletions metasrv/src/meta_service/raftmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl MetaNode {
// Try to join a cluster only when this node is just created.
// Joining a node with log has risk messing up the data in this node and in the target cluster.
if self.is_opened() {
tracing::info!("meta node is opened");
tracing::info!("meta node is already initialized, skip joining it to a cluster");
return Ok(());
}

Expand All @@ -555,7 +555,7 @@ impl MetaNode {
let advertise_endpoint = conf.raft_api_advertise_host_endpoint();
#[allow(clippy::never_loop)]
for addr in addrs {
tracing::info!("try to join cluster accross {}...", addr);
tracing::info!("try to join cluster via {}...", addr);

let conn_res = RaftServiceClient::connect(format!("http://{}", addr)).await;
let mut raft_client = match conn_res {
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup/dev_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ if [[ "$INSTALL_DEV_TOOLS" == "true" ]]; then

# sqllogic clickhouse dependencies
# a temp hack only to make logic test work on click house as quickly as possible
# we need another way to support session on clickhouse-sqlalchemy
python3 -m pip install https://github.com/youngsofun/clickhouse-sqlalchemy/archive/a116e3162c699c12e63a689385b547f639c13018.zip
# we need another way to support session on clickhouse-sqlalchemy
python3 -m pip install https://github.com/youngsofun/clickhouse-sqlalchemy/archive/a116e3162c699c12e63a689385b547f639c13018.zip
fi

if [[ "$INSTALL_CODEGEN" == "true" ]]; then
Expand Down
20 changes: 15 additions & 5 deletions tests/logictest/clickhouse_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@

default_database = "default"


class ClickhouseConnector():

def connect(self, host, port, user="root",password="", database=default_database):
self._uri = "clickhouse+http://{}:{}@{}:{}/{}".format(user,password,host,port,database)
def connect(self,
host,
port,
user="root",
password="",
database=default_database):
self._uri = "clickhouse+http://{}:{}@{}:{}/{}".format(
user, password, host, port, database)
log.debug(self._uri)
e = environs.Env()
self._additonal_headers = dict()
if os.getenv("CLICKHOUSE_ADDITIONAL_HEADERS") is not None:
headers = e.dict("CLICKHOUSE_ADDITIONAL_HEADERS")
for key in headers:
self._additonal_headers["header__" + key] = headers[key]
self._engine = create_engine(self._uri, connect_args=self._additonal_headers)
self._engine = create_engine(self._uri,
connect_args=self._additonal_headers)
self._session = None

def query_with_session(self,statement):
def query_with_session(self, statement):

def parseSQL(sql):
# for cases like:
Expand All @@ -30,7 +38,8 @@ def parseSQL(sql):
# https://stackoverflow.com/questions/49902843/avoid-parameter-binding-when-executing-query-with-sqlalchemy/49913328#49913328
if '"' in sql:
if '\'' in sql:
return sql.replace('"', '\\\"').replace(':','\\:') # " -> \" : -> \\:
return sql.replace('"', '\\\"').replace(
':', '\\:') # " -> \" : -> \\:
return sql.replace('"', '\'')
else:
return sql # do nothing
Expand All @@ -53,6 +62,7 @@ def fetch_all(self, statement):
cursor.close()
return data_list


# if __name__ == '__main__':
# from config import clickhouse_config
# connector = ClickhouseConnector()
Expand Down
22 changes: 15 additions & 7 deletions tests/logictest/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,51 @@
from http_connector import HttpConnector, format_result
from config import http_config

target_dir="./"
target_dir = "./"

http_client = HttpConnector()
http_client.connect(**http_config)


def run(source_file, target_path="."):
if not os.path.isfile(source_file):
print("{} not a file".format(source_file))
return
print("Source file: {}".format(source_file))
case_name = os.path.basename(source_file)
print("Case name: {}".format(case_name))
out = open("{}/{}".format(target_path,case_name),mode="w+", encoding='UTF-8')
out = open("{}/{}".format(target_path, case_name),
mode="w+",
encoding='UTF-8')

statement = list()
f = open(source_file, encoding='UTF-8')
for line in f.readlines():
if line.startswith("--"): # ignore comments
continue
if line.startswith("statement"):
if len(statement) != 0:
if len(statement) != 0:
sql = "".join(statement[1:])
# print("Get a sql: {}".format(sql))
try:
http_results = format_result(http_client.fetch_all(sql))
query_options = http_client.get_query_option()
if query_options:
statement[0] = statement[0].strip() + " " + query_options + "\n"
statement[0] = statement[0].strip(
) + " " + query_options + "\n"
except Exception as err:
print("Get query results error, with msg: {}".format(str(err)))
print("Get query results error, with msg: {}".format(
str(err)))

# print(query_options)
# print(http_results)

if "query" not in statement[0]:
pass
elif len(http_results) == 0:
out.write("-- auto generated, statement query get no results\n") # manual check
out.write(
"-- auto generated, statement query get no results\n"
) # manual check
statement[0] = "statement query skipped\n"
else:
statement.append("----\n")
Expand All @@ -62,5 +69,6 @@ def run(source_file, target_path="."):
f.close()
out.close()


if __name__ == '__main__':
fire.Fire(run)
fire.Fire(run)
2 changes: 2 additions & 0 deletions tests/logictest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'database': 'default',
}


def config_from_env():
mysql_host = os.getenv("QUERY_MYSQL_HANDLER_HOST")
if mysql_host is not None:
Expand Down Expand Up @@ -67,4 +68,5 @@ def config_from_env():
mysql_config['user'] = mysql_user
http_config['user'] = mysql_user


config_from_env()
18 changes: 14 additions & 4 deletions tests/logictest/logictest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
result_regex = r"^----\s*(?P<label>.*)?$"
condition_regex = r"^(skipif\s+(?P<skipDatabase>.*))|(onlyif\s+(?P<onlyDatabase>.*))$"


# return the statement type
# `None` represent that the current format is not a statement type
def get_statement_type(line):
return re.match(state_regex, line, re.MULTILINE | re.IGNORECASE)


def get_result_label(line):
return re.match(result_regex, line, re.MULTILINE | re.IGNORECASE)


def get_statement_condition(line):
return re.match(condition_regex, line, re.IGNORECASE)
return re.match(condition_regex, line, re.IGNORECASE)


# return false if the line is not empty
def is_empty_line(line):
Expand Down Expand Up @@ -200,7 +204,10 @@ def get_statements(suite_path, suite_name):
if condition_matched.group("skipDatabase") is not None:
runs_on.remove(condition_matched.group("skipDatabase"))
if condition_matched.group("onlyDatabase") is not None:
runs_on = {x for x in runs_on if x == condition_matched.group("onlyDatabase")}
runs_on = {
x for x in runs_on
if x == condition_matched.group("onlyDatabase")
}
condition_matched = None
log.debug("runs_on: {}".format(runs_on))
if s.type == "query" and s.query_type is not None:
Expand Down Expand Up @@ -290,7 +297,9 @@ def execute(self):

def execute_statement(self, statement):
if self.kind not in statement.runs_on:
log.info("Skip execute statement with {} SuiteRunner, only runs on {}".format(self.kind, statement.runs_on))
log.info(
"Skip execute statement with {} SuiteRunner, only runs on {}".
format(self.kind, statement.runs_on))
return
if self.show_query_on_execution:
log.info("executing statement, type {}\n{}\n".format(
Expand Down Expand Up @@ -332,7 +341,8 @@ def assert_execute_query(self, statement):
try:
f = format_value(actual, len(statement.s_type.query_type))
except Exception:
assert "{} statement type is query but get no result".format(statement)
assert "{} statement type is query but get no result".format(
statement)
assert statement.results is not None and len(
statement.results) > 0, "No result found {}".format(statement)
hasResult = False
Expand Down
1 change: 1 addition & 0 deletions tests/logictest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def run(pattern=".*"):
http.set_label("clickhouse")
http.run_sql_suite()


if __name__ == '__main__':
fire.Fire(run)

0 comments on commit 295480b

Please sign in to comment.