-
Notifications
You must be signed in to change notification settings - Fork 21
[MySQL] Automatic schema change handling #287
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
Conversation
…kage directly Added check for tablemap events
…tener class. Introduced a mechanism to limit the maximum size of the binlog processing queue, thus also limiting memory usage. This maximum processing queue size is configurable
# Conflicts: # modules/module-mysql/package.json
Cleaned up BinLogStream logs a bit
Simplified BinLogListener stopping mechanism
Added a few more defensive stopped checks to the binlog listener
… memory usage rather than number of events
… memory usage rather than number of events. Introduced a maximum timeout that the binlog processing queue can be paused before auto-resuming. This is to prevent the replication connection timing out.
Made SourceTable implement SourceEntityDescriptor interface
…trics instead of ignoring them. SourceTable. Moved MySQL table detail retrieval logic to utility function.
# Conflicts: # modules/module-mongodb-storage/src/storage/implementation/MongoBucketBatch.ts # modules/module-mongodb-storage/src/storage/implementation/MongoSyncBucketStorage.ts # modules/module-mongodb/src/replication/ChangeStream.ts # modules/module-mysql/package.json # modules/module-mysql/src/replication/BinLogStream.ts # modules/module-mysql/src/replication/zongji/BinLogListener.ts # modules/module-mysql/src/replication/zongji/zongji-utils.ts # modules/module-mysql/test/src/BinLogListener.test.ts # modules/module-postgres-storage/src/storage/PostgresSyncRulesStorage.ts # modules/module-postgres/src/replication/WalStream.ts # packages/service-core/src/storage/SourceTable.ts # pnpm-lock.yaml
Improved binlog table filtering Added extended type definitions for node-sql-parser package
Cleaned up MySQL tests in general and added a few new test utils
- Added more detections of constraint changes - Removed detection of create table statements since they can be detected and reacted to when row events are received for new tables - Added multiple extra test cases
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.
Pull Request Overview
Adds automatic handling of schema changes (DDL events) in MySQL replication and standardizes the use of a name
property instead of table
across sync-rules and storage modules.
- Renamed
SourceTableInterface.table
to.name
everywhere in sync-rules and service-core - Introduced
BinLogListener
logic to parse DDL statements and emit schema change events - Updated all storage and API layers (Postgres, MySQL, MongoDB) to use
table.name
andqualifiedName
Reviewed Changes
Copilot reviewed 41 out of 42 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
packages/sync-rules/src/…/SourceTableInterface.ts | Renamed table → name in interface |
packages/service-core/src/storage/SourceTable.ts | Refactored SourceTable to take an options object |
modules/module-mysql/src/replication/zongji/BinLogListener.ts | Added DDL parsing, schema change handling, restart logic |
modules/module-postgres-storage/src/storage/batch/PostgresBucketBatch.ts | Updated mapping to use table.name |
modules/module-mysql/test/src/BinLogStream.test.ts | Fixed missing await and test descriptions |
modules/module-mysql/src/utils/parser-utils.ts | Introduced DDL‐matching helper |
packages/service-core/src/metrics/open-telemetry/util.ts | Added service.version and JSON import of package.json |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (4)
packages/service-core/src/metrics/open-telemetry/util.ts:66
- Use the semantic key 'service.name' (per OpenTelemetry conventions) instead of 'service' for the service identifier.
['service']: 'PowerSync',
modules/module-mysql/test/src/BinLogStream.test.ts:16
- [nitpick] Typo in the test suite title: it should read 'BinLogStream tests' to match the class name.
describe('BigLogStream tests', () => {
packages/service-core/src/storage/SourceTable.ts:55
- [nitpick] The
hasReplicaIdentity
getter was removed; verify that no downstream code relies on it or reintroduce it if still used.
*/
modules/module-postgres-storage/src/storage/batch/PostgresBucketBatch.ts:467
- Confirm that the
table
object has aname
property; if it still usestable.table
, update the mapping to usetable.table
or rename the source field accordingly.
name: table.name,
… on the mysql database yet.
TableFilter creation is now internally handled in the BinLog listener Pause/unpause binlog listening now uses the same stop start functionality used for schema change handling.
Currently, when syncing from a MySQL database database schema changes are ignored. This is problematic when those changes affect tables that are in the defined sync rules. The work around for that has been to redeploy the sync rules, thereby triggering a full re-sync.
This change set adds functionality to automatically handle schema changes affecting tables in the sync rules by listening for and parsing DDL query binlog events.
The basic mechanism for this works as follows:
Parsing of the query SQL is accomplished by using the node-sql-parser package. This does introduce a limitation in that if the library can't parse the query, we cannot easily interpret the intended schema change either. If this is the case, some best effort pattern matching is done to check if the query is a schema change that affects one of the replicated tables and a warning is logged.
The following schema changes are detectable:
With the exception of Create Table, all of the schema events are detected by parsing the DDL statements received in the binlog query events. For Create table, these changes are picked up when row events are received for the new table.