-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Transaction] Transaction buffer stable position and lowWaterMark implementation. #9195
[Transaction] Transaction buffer stable position and lowWaterMark implementation. #9195
Conversation
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.
Overall looks good, left some comments please take a look.
@@ -1774,6 +1774,11 @@ public void asyncReadEntry(PositionImpl position, ReadEntryCallback callback, Ob | |||
} | |||
|
|||
private void internalReadFromLedger(ReadHandle ledger, OpReadEntry opReadEntry) { | |||
|
|||
if (opReadEntry.readPosition.compareTo(opReadEntry.maxPosition) > 0) { |
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.
The maxPostion of the OpReadEntry might be null?
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.
it not be null
@@ -1789,6 +1794,11 @@ private void internalReadFromLedger(ReadHandle ledger, OpReadEntry opReadEntry) | |||
lastEntryInLedger = ledger.getLastAddConfirmed(); | |||
} | |||
|
|||
// can read max position entryId | |||
if (ledger.getId() == opReadEntry.maxPosition.getLedgerId()) { |
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.
Same as the above comment
@@ -84,6 +84,5 @@ message MarkersMessageIdData { | |||
|
|||
|
|||
/// --- Transaction marker --- | |||
message TxnCommitMarker { | |||
repeated MarkersMessageIdData message_id = 1; | |||
message TxnMarker { |
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.
If not useful, please remove it from the proto.
|
||
@Override | ||
public PositionImpl getMaxReadPosition() { | ||
return PositionImpl.latest; |
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.
Why the in-memory transaction buffer returns latest?
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.
in-memory didn't need stable position logical, I don't change it.
@@ -58,6 +63,12 @@ public TopicTransactionBuffer(PersistentTopic topic) { | |||
topic.getManagedLedger().asyncAddEntry(buffer, new AsyncCallbacks.AddEntryCallback() { | |||
@Override | |||
public void addComplete(Position position, Object ctx) { | |||
if (!ongoingTxns.containsKey(txnId)) { | |||
ongoingTxns.put(txnId, (PositionImpl) position); | |||
PositionImpl firstPosition = ongoingTxns.get(ongoingTxns.firstKey()); |
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.
The LinkedMap will throw NoSuchElementException while the map is empty. And I think the LinkedMap is not a thread-safe container?
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, it not a thread-safe container, i lock all logical what change this map.
|
||
private final LinkedMap<TxnID, PositionImpl> ongoingTxns = new LinkedMap<>(); | ||
|
||
private final LinkedMap<TxnID, PositionImpl> aborts = new LinkedMap<>(); |
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.
Why this also need LinkedMap ? Please give comment for these two maps especially the value of the map, I think the first map is the min message position of the transaction and the second map is the max message position of the transaction?
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.
When we handle lowWaterMark, we should get the first entry of the map to compare the txnID with lowWaterMark. And ongoingTxns is ordered, so we should get the first key position become the maxReadPosition.
} | ||
} | ||
|
||
void changeMaxReadPosition(TxnID txnID) { |
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.
void changeMaxReadPosition(TxnID txnID) { | |
void updateMaxReadPosition(TxnID txnID) { |
private volatile PositionImpl maxReadPosition = PositionImpl.latest; | ||
|
||
private final LinkedMap<TxnID, PositionImpl> ongoingTxns = new LinkedMap<>(); | ||
|
||
private final LinkedMap<TxnID, PositionImpl> aborts = new LinkedMap<>(); |
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.
Is there any test coverage? We'd better to add some unit test to make sure the data should be removed correctly to avoid memory lead and make the maxReadPosition is correct.
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 have add the LowWaterMarkTest. Add the abort and commit MaxReadPosition Test.
.enableTransaction(true) | ||
.build(); | ||
|
||
Thread.sleep(1000 * 3); |
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.
Please try to avoid use sleep 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.
OK
/pulsarbot run-failure-checks |
@congbobo184 @codelipenghui Master seems to still be broken after this change:
|
Thanks @merlimat, we will take a look soon. |
@merlimat #9229 (comment) have solved this problem.
|
Motivation
Transaction buffer stable position and lowWaterMark implementation.
implement
Details view streamnative/community#3
Verifying this change
Add the tests for it
Does this pull request potentially affect one of the following parts:
If yes was chosen, please highlight the changes
Dependencies (does it add or upgrade a dependency): (no)
The public API: (no)
The schema: (no)
The default values of configurations: (no)
The wire protocol: (yes)
The rest endpoints: (no)
The admin cli options: (no)
Anything that affects deployment: (no)