Repository navigation
fix(runtime): make concurrent OceanBase replica startup idempotent #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tsukikage7
wants to merge
13
commits into
oceanbase:master
Choose a base branch
from
Tsukikage7:fix/concurrent-runtime-startup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37418f3
fix(runtime): make OceanBase replica startup idempotent
Tsukikage7 c8a0730
Merge remote-tracking branch 'upstream/master' into fix/concurrent-ru…
Tsukikage7 9b00be8
Merge remote-tracking branch 'upstream/master' into repair/pr1957-202…
Tsukikage7 a233ed4
test(runtime): preserve managed schema and native startup contracts
Tsukikage7 02d7149
test(desktop): cover reported development CLI versions
Tsukikage7 1de5909
docs(storage): review concurrent startup persistence compatibility
Tsukikage7 4748ad6
fix(startup): preserve provisioned DML-only schema access
Tsukikage7 c430184
merge: sync master and verify DML-only Access startup
Tsukikage7 e0b2135
merge: sync master and address concurrent startup review
Tsukikage7 8cabe99
test(oceanbase): verify native vector startup on unquoted DDL
Tsukikage7 b4b85c7
Merge upstream/master into fix/concurrent-runtime-startup
Tsukikage7 0477e98
chore: sync concurrent startup fix with master
hidb4ai 59f39f8
chore: integrate master Atomic Memory updates
hidb4ai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/powercontext/builtin/persistence/oceanbase/schema.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright (c) 2026 OceanBase. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Native idempotent OceanBase vector-index DDL.""" | ||
|
|
||
| import asyncio | ||
| import re | ||
| import time | ||
|
|
||
| from pyobvector import VectorIndex | ||
| from sqlalchemy.exc import DBAPIError, SQLAlchemyError | ||
| from sqlalchemy.ext.asyncio import AsyncConnection | ||
|
|
||
|
|
||
| def _parameters(value: str) -> dict[str, str]: | ||
| return { | ||
| key.strip().lower(): setting.strip().lower() | ||
| for part in value.split(",") | ||
| if "=" in part | ||
| for key, setting in [part.split("=", 1)] | ||
| } | ||
|
|
||
|
|
||
| def _matching_definition(definition: str, quoted_name: str, quoted_column: str, parameters: str) -> bool: | ||
| match = re.search( | ||
| r"^\s*VECTOR\s+(?:KEY|INDEX)\s+" + quoted_name + r"\s*\(\s*" + quoted_column + r"\s*\)\s+WITH\s*\(([^)]*)\)", | ||
| definition, | ||
| re.IGNORECASE | re.MULTILINE, | ||
| ) | ||
| if match and all(_parameters(match[1]).get(key) == value for key, value in _parameters(parameters).items()): | ||
| return True | ||
| if re.search( | ||
| r"^\s*(?:(?:UNIQUE|FULLTEXT|VECTOR|SPATIAL)\s+)?(?:KEY|INDEX)\s+" + quoted_name + r"\s*\(", | ||
| definition, | ||
| re.IGNORECASE | re.MULTILINE, | ||
| ): | ||
| message = "An existing OceanBase vector index does not match its native column or parameters" | ||
| raise SQLAlchemyError(message) | ||
| return False | ||
|
|
||
|
|
||
| async def create_vector_index(connection: AsyncConnection, index: VectorIndex, /) -> None: | ||
| table, name = index.table, index.name | ||
| if table is None or name is None: | ||
| message = "A native vector index must have a name and bound table" | ||
| raise ValueError(message) | ||
| preparer = connection.dialect.identifier_preparer | ||
| columns = tuple(index.columns) | ||
| column = columns[0] | ||
| quoted_name = re.escape(preparer.quote_identifier(name)) | ||
| quoted_column = re.escape(preparer.quote_identifier(column.name)) | ||
|
|
||
| async def existing_matches() -> bool: | ||
| result = await connection.exec_driver_sql(f"SHOW CREATE TABLE {preparer.format_table(table)}") | ||
| row = result.first() | ||
| definition = "" if row is None else str(row[1]) | ||
| # STATISTICS exposes hidden BTREE auxiliary columns for VECTOR indexes. | ||
| return _matching_definition(definition, quoted_name, quoted_column, index.params or "") | ||
|
|
||
| # 4.4.2.1 rejects another VECTOR index on the column before honoring | ||
| # IF NOT EXISTS. Revalidate only that exact duplicate-column race. | ||
| if await existing_matches(): | ||
| return | ||
| parameters = "" if index.params is None else f" WITH ({index.params})" | ||
| names = ", ".join(preparer.format_column(value) for value in columns) | ||
| try: | ||
| await connection.exec_driver_sql( | ||
| f"CREATE VECTOR INDEX IF NOT EXISTS {preparer.format_index(index)} " | ||
| f"ON {preparer.format_table(table)} ({names}){parameters}" | ||
| ) | ||
| except DBAPIError as error: | ||
| original = error.orig | ||
| if ( | ||
| original is None | ||
| or not original.args | ||
| or original.args[0] != 1235 | ||
| or not str(original.args[1] if len(original.args) > 1 else "") | ||
| .lower() | ||
| .startswith("create vector index on column has vector index is not supported") | ||
| ): | ||
| raise | ||
| # The native column reservation becomes visible before its logical | ||
| # index DDL. Wait for the competing creation's metadata to settle, | ||
| # using the tenant's existing query timeout; never replay CREATE. | ||
| result = await connection.exec_driver_sql("SELECT @@ob_query_timeout") | ||
| deadline = time.monotonic() + max(0, int(result.scalar_one())) / 1_000_000 | ||
| while True: | ||
| if await existing_matches(): | ||
| return | ||
| remaining = deadline - time.monotonic() | ||
| if remaining <= 0: | ||
| raise | ||
| await asyncio.sleep(min(0.1, remaining)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Recognize unquoted native index definitions
With
sql_quote_show_create=OFF, OceanBase returnsVECTOR KEY ix_pc_atomic_memory_current_embedding (embedding) ..., so these mandatory quoted patterns never match the existing index. Reinitialization then issues CREATE again and fails with 1235, aborting Atomic Memory initialization. On real OceanBase CE 4.3.5.5, the completeOceanBaseAtomicMemoryIndex(profile).initialize(connection)succeeds at merge base5032075, fails atc4301849against the same provisioned database with this session setting, and succeeds again after only restoringsql_quote_show_create=ON. Please support both valid SHOW CREATE forms, or normalize the setting while preserving the caller's session state, so compatible existing indexes remain reusable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified on
8cabe99af6c59f27b2189479bee87b784c87423aagainst native OceanBase CE 4.4.2.1: the live regression confirms unquoted SHOW CREATE output and successful Atomic Memory reinitialization withsql_quote_show_create=OFF. Concurrent and repeated native-vector initialization also passed. This finding is fixed.