From 9ed27709439de06abce2303a3f4f1f27725b1142 Mon Sep 17 00:00:00 2001 From: SanmuWangZJU Date: Sat, 10 Feb 2024 10:18:24 +0000 Subject: [PATCH] [CP] [OBCDC] Provide obcdc compatible info --- cmake/RPM.cmake | 2 + rpm/oceanbase-ce-cdc-build.sh | 1 + tools/upgrade/gen_obcdc_compatiable_info.py | 82 +++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100755 tools/upgrade/gen_obcdc_compatiable_info.py diff --git a/cmake/RPM.cmake b/cmake/RPM.cmake index d3ccfd953..aad20a962 100644 --- a/cmake/RPM.cmake +++ b/cmake/RPM.cmake @@ -178,6 +178,7 @@ if(OB_BUILD_OPENSOURCE) install( FILES ${PROJECT_SOURCE_DIR}/src/logservice/libobcdc/tests/libobcdc.conf + ${PROJECT_SOURCE_DIR}/tools/upgrade/obcdc_compatiable_ob_info.yaml DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} COMPONENT cdc ) @@ -185,6 +186,7 @@ else() install( FILES ${PROJECT_SOURCE_DIR}/src/logservice/libobcdc/tests/libobcdc.conf + ${PROJECT_SOURCE_DIR}/tools/upgrade/obcdc_compatiable_ob_info.yaml ${PROJECT_SOURCE_DIR}/src/logservice/libobcdc/tests/timezone_info.conf DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} COMPONENT cdc diff --git a/rpm/oceanbase-ce-cdc-build.sh b/rpm/oceanbase-ce-cdc-build.sh index b3515ccc1..79b8b28ad 100644 --- a/rpm/oceanbase-ce-cdc-build.sh +++ b/rpm/oceanbase-ce-cdc-build.sh @@ -11,6 +11,7 @@ TOP_DIR=`pwd`/../ echo "[BUILD] args: TOP_DIR=${TOP_DIR} PROJECT_NAME=${PROJECT_NAME} VERSION=${VERSION} RELEASE=${RELEASE}" cd ${TOP_DIR} +./tools/upgrade/gen_obcdc_compatiable_info.py ./build.sh clean ./build.sh \ rpm \ diff --git a/tools/upgrade/gen_obcdc_compatiable_info.py b/tools/upgrade/gen_obcdc_compatiable_info.py new file mode 100755 index 000000000..07012e458 --- /dev/null +++ b/tools/upgrade/gen_obcdc_compatiable_info.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# RUN THIS SCRIPT AFTER oceanbase_upgrade_dep.yml MODIFIED +# +# PREPARE: install yaml with `pip install PyYaml` before run this script +# RUN: run this script in tools/upgrade/ directory + +import yaml +import os + +def get_yaml(filename): + yaml_data = None + with open(filename, 'r', encoding='utf-8') as f: + yaml_data = yaml.safe_load(f) + return yaml_data + +def dump_to_yaml_obj(content): + return yaml.safe_dump(content, explicit_start=True, explicit_end=True, default_flow_style=False, encoding="utf-8") + +def write_yaml_to_file(content, filename): + with open(filename, 'w',) as f : + yaml.safe_dump(content, f, explicit_start=True, explicit_end=True, default_flow_style=False, encoding="utf-8") + print('Dump yaml format data to file successfully. File path: {0}'.format(filename)) + +def collect_can_upgrade_from(target_ver): + target_set = set() + target_set.add(target_ver) + if target_ver in can_upgrade_from_map.keys(): + can_upgrade_to_target_set = can_upgrade_from_map[target_ver] + for target in can_upgrade_to_target_set: + target_set.update(collect_can_upgrade_from(target)) + return target_set + + +if __name__ == '__main__': + dir_path = os.path.dirname(os.path.realpath(__file__)) + ob_upgrade_deps_file = dir_path + "/oceanbase_upgrade_dep.yml" + obcdc_compatiable_info_file = dir_path + "/obcdc_compatiable_ob_info.yaml" + ob_upgrade_deps = get_yaml(ob_upgrade_deps_file) + support_ob_versions = [] + cur_ob_version = '' + + # key: upgraded_to_version + # value: direct_upgrade_from_version_set + can_upgrade_from_map = {} + detect_cur_ob_ver_succ = False + + if ob_upgrade_deps is not None: + for ob_ver in ob_upgrade_deps: + cur_ver = str(ob_ver['version']) + if 'can_be_upgraded_to' not in ob_ver.keys(): + if detect_cur_ob_ver_succ: + print("duplicate detect cur_ob_version, last_detect_version: {cur_ob_version}, current_decect_info: {ob_ver}") + break + else: + detect_cur_ob_ver_succ = True + cur_ob_version = cur_ver + if can_upgrade_to not in can_upgrade_from_map.keys(): + can_upgrade_from_set = set() + can_upgrade_from_map[can_upgrade_to] = can_upgrade_from_set + else: + can_upgrade_to_list = list(ob_ver['can_be_upgraded_to']) + for can_upgrade_to in can_upgrade_to_list: + if can_upgrade_to not in can_upgrade_from_map.keys(): + can_upgrade_from_set = set() + can_upgrade_from_set.add(cur_ver) + can_upgrade_from_map[can_upgrade_to] = can_upgrade_from_set + else: + can_upgrade_from_map[can_upgrade_to].add(cur_ver) + + + if detect_cur_ob_ver_succ: + can_upgrade_from_set = can_upgrade_from_map[cur_ob_version] + can_upgrade_from_set.update(collect_can_upgrade_from(cur_ob_version)) + res_map = {} + res_list = [] + res_map["compatiable_ob_version"] = sorted(list(can_upgrade_from_set)) + res_map["obcdc_version"] = cur_ob_version + res_list.append(res_map) + print(dump_to_yaml_obj(res_list)) + write_yaml_to_file(res_list, obcdc_compatiable_info_file)