Skip to content
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

Add its own commit loop which resolves partition offsets conflicts #27

Merged
merged 13 commits into from
Jun 11, 2021

Conversation

mosyp
Copy link
Contributor

@mosyp mosyp commented Jun 8, 2021

Fixes #25

Here's log from tests right after the new consumer is added to the group:

2021-06-10T16:36:16 [INFO] - WORKER-1: Delta write for version 5 has completed in 602071 microseconds
2021-06-10T16:36:16 [INFO] - WORKER-2: Starting run loop.
2021-06-10T16:36:17 [INFO] - WORKER-1: Delta write for version 6 has completed in 516716 microseconds
2021-06-10T16:36:17 [INFO] - WORKER-1: REBALANCE - Received new partition assignment list [1, 0]
2021-06-10T16:36:17 [INFO] - WORKER-2: REBALANCE - Received new partition assignment list [2, 3]
2021-06-10T16:36:17 [INFO] - WORKER-2: Resetting state with partitions: [3, 2]
2021-06-10T16:36:17 [INFO] - WORKER-2: Seeking consumer to 3:9
2021-06-10T16:36:17 [INFO] - WORKER-2: Seeking consumer to 2:10
2021-06-10T16:36:17 [INFO] - WORKER-1: Resetting state with partitions: [1, 0]
2021-06-10T16:36:17 [INFO] - WORKER-1: Seeking consumer to 1:12
2021-06-10T16:36:17 [INFO] - WORKER-1: Seeking consumer to 0:25
2021-06-10T16:36:17 [INFO] - WORKER-2: Conflict offset for partition 3: state=8, delta=10
2021-06-10T16:36:17 [INFO] - WORKER-2: Conflict offset for partition 2: state=9, delta=11
2021-06-10T16:36:17 [INFO] - WORKER-2: Resetting state with partitions: [3, 2]
2021-06-10T16:36:17 [INFO] - WORKER-2: Seeking consumer to 3:11
2021-06-10T16:36:17 [INFO] - WORKER-2: Seeking consumer to 2:12
2021-06-10T16:36:18 [INFO] - WORKER-1: Delta write for version 7 has completed in 601173 microseconds
2021-06-10T16:36:19 [INFO] - WORKER-1: Delta write for version 8 has completed in 718753 microseconds
2021-06-10T16:36:19 [INFO] - WORKER-1: Delta write for version 9 has completed in 653510 microseconds
2021-06-10T16:36:20 [INFO] - WORKER-2: Delta write for version 10 has completed in 2585776 microseconds
2021-06-10T16:36:20 [INFO] - WORKER-1: Delta write for version 11 has completed in 1145232 microseconds
2021-06-10T16:36:21 [INFO] - WORKER-2: Delta write for version 12 has completed in 873619 microseconds

So what do we see here. Before, the WORKER-1 had all 4 partition, after introducing the WORKER-2, we've got first to have 0 and 1, second 2 and 3.

On rebalance, we clear all pending state and seek the consumers to the offsets from delta.

However you might notice that WORKER-2 is seeked twice. That's due to the distributive nature, first seek it to 3:9,2:10, because delta log versions are 3:8,2:9 (notice +1, because we seek to the next message). But then when WORKER-2 tries to do a commit it founds that the delta store is actually 3:10,2:11 now. That is because of WORKER-1 committed version 6 right in between/before rebalance (note that we first load a table and then subscribe a consumer, so there's a time gap).
But that's okay since WORKER-2 notices that (e.g. updated delta offsets) and seek its consumer to 3:11,2:12.
Right after that, WORKER-1 cannot write data to partitions 2,3 so no more conflicts are possible and hence both WORKER-1 and WORKER-2 are making commits to the delta without any conflicts or any other issues in parallel

@mosyp mosyp force-pushed the new-writer-and-commit-loop branch from b2bcd38 to 9d38903 Compare June 10, 2021 11:21
@mosyp mosyp requested review from xianwill, houqp and rtyler June 10, 2021 13:52
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Christian Williams <[email protected]>
src/lib.rs Show resolved Hide resolved
Copy link
Member

@houqp houqp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me overall 👍

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved

// TODO if the new assignment is only an addition of partitions we don't need to reset state
if partition_assignment.rebalance.is_some() {
let partitions = partition_assignment.rebalance.as_ref().unwrap().clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this unwrap and clone can be avoided if we refactor how we check and reset partition assignments. but since this is not in the hot path, the overhead should be minor, so we can do the clean in future PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so this took me a while. Yes I don't need clone, but I couldn't make it compile otherwise.

The errors I was getting is something like cannot borrow as the immutable because it's already borrowed a mutable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, to workaround that, we need to combine the rebalance check and partition_assignment.reset_with into a single method.

@mosyp mosyp force-pushed the new-writer-and-commit-loop branch from c4bd2c2 to 9ac5f16 Compare June 11, 2021 09:14
@xianwill xianwill merged commit 011fb18 into delta-io:main Jun 11, 2021
@mosyp mosyp deleted the new-writer-and-commit-loop branch July 13, 2021 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add commit loop with conflict resolution for txn actions
3 participants