Skip to content

Commit

Permalink
fix tabledump and analyze parameter (#340)
Browse files Browse the repository at this point in the history
* table dump print pretty result

* Fix regression testing bugs

* Fix regression testing bugs

* Optimize logs

* Optimize logs

* Optimize logs

* fix: gather tabledump

* fix: gather tabledump

* fix analyze flt_trace offline

* remove duplicate code & optimize log

* remove duplicate code & optimize log

* fix: command auto-completion

* fix: command auto-completion

* fix: command auto-completion

* fix analyze_parameter/analyze_variable log

* add gathering scenario sql

* fix tabledump and analyze parameter

* fix tabledump and analyze parameter
  • Loading branch information
Teingi authored Jul 17, 2024
1 parent e563a69 commit 8b1b275
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion handler/analyzer/analyze_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def analyze_parameter_default(self):
report_default_tb.add_row([row[1], row[2], row[3], row[4], tenant_id, row[6], row[11], row[7]])
fp.write(report_default_tb.get_string() + "\n")
self.stdio.print(report_default_tb.get_string())
self.stdio.print("Analyze parameter default finished. For more details, please run cmd '" + Fore.YELLOW + " cat {0}' ".format(file_name) + Style.RESET_ALL)
self.stdio.print("Analyze parameter default finished. For more details, please run cmd '" + Fore.YELLOW + " cat {0} ".format(file_name) + Style.RESET_ALL + "'")
else:
if self.parameter_file_name is None:
self.stdio.error("the version of OceanBase is lower than 4.2.2, an initialization parameter file must be provided to find non-default values")
Expand Down
38 changes: 22 additions & 16 deletions handler/gather/gather_tabledump.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def init(self):
self.table = Util.get_option(options, 'table')
user = Util.get_option(options, 'user')
password = Util.get_option(options, 'password')
if not (self.database and self.database and user and password):
self.stdio.error("option --database/--table/--user/--password not found, please provide")
if not (self.database and self.table and user):
self.stdio.error("option --database/--table/--user not found, please provide")
return False
store_dir_option = Util.get_option(options, 'store_dir')
if store_dir_option is not None and store_dir_option != './':
Expand Down Expand Up @@ -100,27 +100,31 @@ def handle(self):
if not self.init():
self.stdio.error('init failed')
return False
self.execute()
if not self.is_innner:
excute_status = self.execute()
if not self.is_innner and excute_status:
self.__print_result()

def execute(self):
try:
self.version = get_observer_version(self.context)
self.__get_table_schema()
if self.version == "4.0.0.0" or StringUtils.compare_versions_greater(self.version, "4.0.0.0"):
self.__get_table_info()
else:
self.__get_table_info_v3()
if self.__get_table_schema():
if self.version == "4.0.0.0" or StringUtils.compare_versions_greater(self.version, "4.0.0.0"):
return self.__get_table_info()
else:
return self.__get_table_info_v3()
except Exception as e:
self.stdio.error("report sql result to file: {0} failed, error: {1}".format(self.file_name, e))
self.stdio.error("report sql result failed, error: {0}".format(e))

def __get_table_schema(self):
sql = "show create table " + self.database + "." + self.table
columns, result = self.tenant_connector.execute_sql_return_columns_and_data(sql)
if result is None or len(result) == 0:
self.stdio.verbose("excute sql: {0}, result is None".format(sql))
self.__report(sql, columns, result)
try:
sql = "show create table " + self.database + "." + self.table
columns, result = self.tenant_connector.execute_sql_return_columns_and_data(sql)
if result is None or len(result) == 0:
self.stdio.verbose("excute sql: {0}, result is None".format(sql))
self.__report(sql, columns, result)
return True
except Exception as e:
self.stdio.error("show create table error {0}".format(e))

def __get_table_info(self):
try:
Expand Down Expand Up @@ -172,6 +176,7 @@ def __get_table_info(self):
return
self.stdio.print("data size {0}".format(result))
self.__report(query_data, columns, result)
return True

except Exception as e:
self.stdio.error("getTableInfo execute Exception: {0}".format(e).strip())
Expand Down Expand Up @@ -203,6 +208,7 @@ def __get_table_info_v3(self):
return
self.stdio.print("table count {0}".format(result))
self.__report(query_count, columns, result)
return True

except Exception as e:
self.stdio.error("getTableInfo execute Exception: {0}".format(e).strip())
Expand All @@ -215,7 +221,7 @@ def __report(self, sql, column_names, data):
f.write('\n\n' + 'obclient > ' + sql + '\n')
f.write(formatted_table)
except Exception as e:
self.stdio.error("report sql result to file: {0} failed, error: ".format(self.file_name))
self.stdio.error("report sql result to file: {0} failed, error:{1} ".format(self.file_name, e))

def __extract_string(self, s):
if '@' in s:
Expand Down

0 comments on commit 8b1b275

Please sign in to comment.