fix: rollback when AnalyticDB create zhparser failed (#24260)

Co-authored-by: xiaozeyu <xiaozeyu.xzy@alibaba-inc.com>
This commit is contained in:
8bitpd 2025-08-21 15:00:26 +08:00 committed by GitHub
parent 738aaee101
commit a183b2affb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -105,9 +105,11 @@ class AnalyticdbVectorBySql:
conn.close()
self.pool = self._create_connection_pool()
with self._get_cursor() as cur:
conn = cur.connection
try:
cur.execute("CREATE EXTENSION IF NOT EXISTS zhparser;")
except Exception as e:
conn.rollback()
raise RuntimeError(
"Failed to create zhparser extension. Please ensure it is available in your AnalyticDB."
) from e
@ -115,6 +117,7 @@ class AnalyticdbVectorBySql:
cur.execute("CREATE TEXT SEARCH CONFIGURATION zh_cn (PARSER = zhparser)")
cur.execute("ALTER TEXT SEARCH CONFIGURATION zh_cn ADD MAPPING FOR n,v,a,i,e,l,x WITH simple")
except Exception as e:
conn.rollback()
if "already exists" not in str(e):
raise e
cur.execute(