-
Notifications
You must be signed in to change notification settings - Fork 80
DBZ-947 SQL Server snapshot.locking.modes overhaul #38
Conversation
Related pull request: #36 |
} | ||
LOGGER.info("Executing schema locking"); | ||
} else if (connectorConfig.getSnapshotLockingMode() == SnapshotLockingMode.EXCLUSIVE) { | ||
LOGGER.info("Executing schema locking"); |
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.
Taking locks here is misleading, since it suggests they are taken only for schema snapshot. I believe we should introduce yet another template method.
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.
Yes, that's a good point. Can you file a JIRA issue so we can track it separately?
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.
Hum, no, I think I'm taking that back. Before this PR, these locks should indeed only have been held while taking the schema snapshot, by virtue of a savepoint. Which makes me wonder why you removed it here?
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.
Rollback to savepoint makes no sense.
In both SNAPSHOT and R_R mode no locks are taken - no rollback needed.
For EXCLUSIVE, we want to keep locks until the end of transaction - rollback must not be executed.
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.
I meant that taking exclusive lock in lockTablesForSchemaSnapshot
is misleading.
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.
For EXCLUSIVE, we want to keep locks until the end of transaction - rollback must not be executed.
I think the original idea was to keep the lock only for the time of taking the schema snapshot. At least that was my motivation for the Oracle connector, which is where @jpechane copied this from. Then the actual data snapshot would be taken using R_R semantics, which indeed seems to be missing still, when looking at the master branch. @jpechane Correct me please, if I'm wrong.
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.
Yes, on master in EXCLUSIVE data snapshot is taken in database default isolation level.
I suggested to keep the locks during data snapshot as well due to this scenario: https://issues.jboss.org/browse/DBZ-947?focusedCommentId=13651038&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13651038
To be honest, even having seen the logs, I still have no idea why the build failed. |
@grzegorz8 Unfortunately the build here will fail till the related PR gets merged. |
@grzegorz8 There is a conflict now after #36 was applied :-( |
@jpechane Rebase done. |
Hey @grzegorz8, where are we with this one? On first thought I'm having doubts of using READ_COMITTED for snaphotting, as it may lead to concurrent changes being missed. What's the motivation for adding this in addition to REPEATABLE_READ? |
I'm waiting for review and suggestions how to structure the code (e.g. do we need to introduce a new template method for taking locks for the entire snapshot, not only for schema snapshot?). Regarding isolation level, I know that Debezium tries to deliver consistent snapshot, which in fact is feasible with neither READ COMMITTED nor REPEATABLE READ in case of SQL Server. I presented an example for RR here: https://issues.jboss.org/browse/DBZ-947?focusedCommentId=13651038&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13651038 In addition, I encountered cases when blocking other transactions is unacceptable for DB owner, so read committed fits this case well. |
@jpechane @gunnarmorling The PR has been updated according to the suggestions here https://issues.jboss.org/browse/DBZ-947?focusedCommentId=13658596&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13658596 |
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.
@grzegorz8 A few more comments inline. My key questions are:
- Do why need to keep
NONE
at all? - Should
CONSISTENT
be renamed toREPEATABLE_READ
and be the new default?
My answers would be "no", "yes" and "yes" :)
...nector-sqlserver/src/main/java/io/debezium/connector/sqlserver/SqlServerConnectorConfig.java
Outdated
Show resolved
Hide resolved
...server/src/main/java/io/debezium/connector/sqlserver/SqlServerSnapshotChangeEventSource.java
Outdated
Show resolved
Hide resolved
} | ||
LOGGER.info("Executing schema locking"); | ||
} else if (connectorConfig.getSnapshotLockingMode() == SnapshotLockingMode.EXCLUSIVE) { | ||
LOGGER.info("Executing schema locking"); |
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.
Yes, that's a good point. Can you file a JIRA issue so we can track it separately?
debezium-connector-sqlserver/src/test/java/io/debezium/connector/sqlserver/SnapshotIT.java
Outdated
Show resolved
Hide resolved
I'm not insisting. I'll remove it.
I'll do that. |
Was just talking to @jpechane a bit, and also re-read your comment above about |
@gunnarmorling I believe I have solved all your suggestions (except |
Hey @grzegorz8, nope, no issues I think, I only was busy with some conference travel and other work recently. I'll get back to this one next week. Unless anything else pops up, the change will be part of the next 0.9.x release. Sorry for the delay and thanks your patience. |
Unfortunately, I haven't understood deep enough how read committed works before. It DOES take shared locks, but on very short periods. Deadlocks might occur, though.
I need to rethink usefulness of |
I woonder how deadlock is possible - is it because we are snapshotting two tables and another TX is accessing those two tables but in the opposite order? |
@jpechane In this case I was fetching one huge table only (it failed after ~4 hours). I've read that while reading table in read committed a read lock or either individual row or a page is acquired. I'm trying now to track down the exact scenario. |
Hey @grzegorz8 and @jpechane, it seems this one still needs some more work? Anything specific we should discuss? |
@gunnarmorling Yeah, I'd still give it a couple of more rounds. If the locks are on raw/page level then even on table level if a concurrent process will read two rows in different order than Debezium we can end in a deadlock. |
Ok, thanks for the heads-up. I'll assign the issue to 0.9-next then. |
@gunnarmorling I doubt we can do anything about deadlocks. We can either decide to get rid of If we leave it, we should document tradeoffs between consistency and locking of each mode and mention that the best choice is SNAPSHOT isolation level and if it's not an option for a user, the user should accept disadvantages of other isolation level modes. |
Hi, could you please look at locking hints (https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-2017) - maybe |
@gunnarmorling @jpechane Let's try to conclude what to do with this :)
|
The property is replaced with snapshot.isolation.mode. Exclusive mode: In order to provide a consistent snapshot, exclusive locks are taken on all monitored tables during entire snapshot process duration. Snapshot mode: The initial snapshot is executed in snapshot transaction isolation level. This guarantees consistent snapshot as long as DDL statements are not executed. In addition, neither table locks nor row-level locks are acquired. Repeatable read mode: The initial snapshot is executed in repeatable read transaction level. Since phantom reads can occur, it does not fully guarantee consistency.
@grzegorz8 @gunnarmorling Based up the current observations I think dropping |
@jpechane How should |
@grzegorz8 none would be read _uncomitted. |
@jpechane Ok, I'll add that. Should I name it |
@jpechane @gunnarmorling How about this PR. If the overall idea of the PR is not good for you, let me create separate tasks (and PRs) for bugs fixes here: |
@grzegorz8 Nobody is saying that the overall idea is not good. I understand this takes a little bit long already but as you've pointed before - not everything works as we all expected. To speed things up how baout having a chat or hangout session where we agree upon final solution? I think it is better than pushing back and forth. @gunnarmorling Do you agree? |
@jpechane I understand this is rather low-priority task if we consider other improvements, bugs or upcoming release candidate. |
Yes, good idea with having a chat, so to agree on the way forward. And sorry for the delay, there's just (too) much going on. Would Friday morning, e.g. 10:00 a.m. CET, work for the two of you? |
@gunnarmorling Fine for me! |
Could it be 10:30, please? |
Yes, of course. I'll send an invite with a Google Hangouts link.
|
@gunnarmorling Thanks! |
Sent an invite to your Google address. |
@grzegorz8 Can you close this PR and open a new one against the main repository (after tomorrow's call, I reckon)? In the course of moving the SQL Server connector out of "Incubating" state, we've moved the connector over there. Thanks! |
…on_loops_after_rollback_1 to master Squashed commit of the following: commit 123bcc651acef2a31ab81dc07a337bf996857833 Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 16 13:14:45 2020 -0700 DSOPS-101, mining session loops after rollback commit 4343d84e1477fb0ad15730fd48ff587ae49aea2a Merge: 996c0c0f 0536eab Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 16 13:13:49 2020 -0700 Merge branch 'master' into DSOPS-101_session_loops_after_rollback_1 commit 0536eab Merge: 76f9f80 e30cfbd Author: AndreyIg <gnyiny@gmail.com> Date: Thu Mar 12 13:31:51 2020 -0700 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 996c0c0ff4c7989eb2469a8c2486de6f80e44484 Author: AndreyIg <gnyiny@gmail.com> Date: Thu Mar 12 13:11:16 2020 -0700 DSOPS-101_session_loops_after_rollback commit f49ae0bb1e205f7dce13c1ea342262cdd0b57ee8 Merge: 59b65a1b 76f9f80 Author: AndreyIg <gnyiny@gmail.com> Date: Thu Mar 12 13:04:47 2020 -0700 Merge branch 'master' into DSOPS-101_session_loops_after_rollback commit 76f9f80 Merge: 77e567e af6f8a3 Author: AndreyIg <gnyiny@gmail.com> Date: Wed Mar 11 12:33:09 2020 -0700 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 59b65a1ba27436e75774593d35a76a1379b5e830 Merge: ddd3c186 77e567e Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 9 12:08:39 2020 -0700 Merge branch 'master' into DSOPS-101_session_loops_after_rollback commit 77e567e Merge: 8e3d922 0585b2b Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 9 12:07:58 2020 -0700 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit ddd3c1867ca7fd5aea6f0d54c8b431e8bc6648f1 Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 9 11:16:49 2020 -0700 DSOPS-101, mining session loops after rollback commit 8e3d922 Merge: a98bb75 d4bc528 Author: AndreyIg <gnyiny@gmail.com> Date: Sat Mar 7 04:26:18 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit a98bb75 Merge: c78c368 a23eb5a Author: AndreyIg <gnyiny@gmail.com> Date: Sat Mar 7 04:12:31 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit c78c368 Merge: 90bcc19 4619fcd Author: AndreyIg <gnyiny@gmail.com> Date: Fri Mar 6 06:52:42 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 90bcc19 Merge: b5d1ea7 3e3aeea Author: AndreyIg <gnyiny@gmail.com> Date: Mon Mar 2 14:31:07 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit b5d1ea7 Merge: 9686041 51f0dcb Author: AndreyIg <gnyiny@gmail.com> Date: Wed Feb 26 17:17:38 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 9686041 Merge: 926c648 4996a49 Author: AndreyIg <gnyiny@gmail.com> Date: Wed Feb 26 12:02:35 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 926c648 Merge: 92140a3 829206c Author: AndreyIg <gnyiny@gmail.com> Date: Wed Feb 26 10:49:29 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 92140a3 Merge: 9fa48df 15a6c6c Author: AndreyIg <gnyiny@gmail.com> Date: Tue Feb 25 18:14:58 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 9fa48df Merge: d3da472 27eb9af Author: AndreyIg <gnyiny@gmail.com> Date: Fri Feb 14 16:11:29 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit d3da472 Merge: 86f3f65 081731f Author: AndreyIg <gnyiny@gmail.com> Date: Mon Feb 3 16:18:33 2020 -0800 Merge branch 'master' of http://git.navis.lan/scm/n4fra/debezium commit 86f3f65 Author: AndreyIg <gnyiny@gmail.com> Date: Mon Feb 3 16:02:43 2020 -0800 DSCON-117, DBConnector exception while incremental loading - revert This reverts commit c3a6023. ... and 19 more commits
https://issues.jboss.org/browse/DBZ-947
Exclusive mode: In order to provide a consistent snapshot, exclusive locks
are taken on all monitored tables during entire snapshot process duration.
Snapshot mode: The initial snapshot is executed in snapshot transaction
isolation level. This guarantees consistent snapshot as long as DDL
statements are not executed. In addition, neither table locks nor
row-level locks are acquired.
Repeatable read mode: The initial snapshot is executed in repeatable read
transaction level. Since phantom reads can occur, it does not fully
guarantee consistency.
None mode: Neither table locks nor row-level locks are taken. This way
other transactions are not affected by initial snapshot process.
However, snapshot consistency is not guaranteed. In addition, DDL
statements must not be executed during the snapshot.