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

[improve][broker][PIP-195] Make bucket merge operation asynchronous #19873

Merged
merged 4 commits into from
Mar 25, 2023

Conversation

coderzc
Copy link
Member

@coderzc coderzc commented Mar 21, 2023

PIP: #16763

Motivation & Modifications

  • Make bucket merge operation asynchronous.
  • Optimize the logic of selecting bucket, find two adjacent buckets with the min schedule time and the least number of indexes to merge, avoid preload indexes that have not expired for a long time.
  • Add min_schedule_timestamp in SnapshotSegmentMetadata (It is also used later to implement lazy load)
  • Fix leak in snapshotSegmentLastIndexTable

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 21, 2023
@mattisonchao mattisonchao self-requested a review March 21, 2023 07:33
@coderzc coderzc self-assigned this Mar 21, 2023
@coderzc coderzc requested a review from codelipenghui March 21, 2023 07:37
@coderzc coderzc added this to the 3.0.0 milestone Mar 21, 2023
@coderzc coderzc added area/broker type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Mar 21, 2023
@coderzc coderzc force-pushed the improve/bucket_delayed_async_merge branch 4 times, most recently from b2f9f49 to 3cc918d Compare March 22, 2023 10:10
@coderzc coderzc force-pushed the improve/bucket_delayed_async_merge branch from 3cc918d to f854c59 Compare March 22, 2023 10:14
private volatile List<DelayedMessageIndexBucketSnapshotFormat.SnapshotSegment> snapshotSegments;
private List<DelayedMessageIndexBucketSnapshotFormat.SnapshotSegment> snapshotSegments;

boolean merging = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

the variable merging should be modified with volatile.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because all the read and write of merging is in synchronized block.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are right, the document of J2SE describes this feature like this:

Intrinsic Locks and Synchronization

Synchronization is built around an internal entity known as the intrinsic lock or monitor lock. (The API specification often refers to this entity simply as a "monitor.") Intrinsic locks play a role in both aspects of synchronization: enforcing exclusive access to an object's state and establishing happens-before relationships that are essential to visibility.

Synchronized Methods

Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

@@ -341,18 +339,24 @@ public synchronized boolean addMessage(long ledgerId, long entryId, long deliver
private synchronized CompletableFuture<Void> asyncMergeBucketSnapshot() {
List<ImmutableBucket> values = immutableBuckets.asMapOfRanges().values().stream().toList();
long minNumberMessages = Long.MAX_VALUE;
long minScheduleTimestampSum = Long.MAX_VALUE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is variable minScheduleTimestampSum unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used in line-356

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it helps to find the first segment, right?

Copy link
Member Author

@coderzc coderzc Mar 23, 2023

Choose a reason for hiding this comment

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

Oh, it is used to find the bucket which the min scheduled time of the next segment to merge, avoid preload indexes that have not expired for a long time.

@coderzc coderzc force-pushed the improve/bucket_delayed_async_merge branch from 541ec76 to 133887f Compare March 23, 2023 03:29
@coderzc coderzc force-pushed the improve/bucket_delayed_async_merge branch from 8f5006b to 22c6b41 Compare March 24, 2023 11:09
@coderzc coderzc force-pushed the improve/bucket_delayed_async_merge branch from 22c6b41 to e2260cc Compare March 24, 2023 15:43
@coderzc coderzc merged commit 8081ee2 into apache:master Mar 25, 2023
@coderzc coderzc deleted the improve/bucket_delayed_async_merge branch March 25, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-not-needed Your PR changes do not impact docs type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants