[improve][broker]Use cursor.isActive instead to judge if cursor is active - #19159
Conversation
|
@gaozhangmin Please add the following content to your PR description and select a checkbox: |
| public void activateCursor(ManagedCursor cursor) { | ||
| synchronized (activeCursors) { | ||
| if (activeCursors.get(cursor.getName()) == null) { | ||
| if (!cursor.isActive()) { |
There was a problem hiding this comment.
If change like this, I think it's better like
if (!cursor.isActive()) {
Position positionForOrdering = config.isCacheEvictionByMarkDeletedPosition()
? cursor.getMarkDeletedPosition()
: cursor.getReadPosition();
if (positionForOrdering == null) {
positionForOrdering = PositionImpl.EARLIEST;
}
synchronized (activeCursors) {
activeCursors.add(cursor, positionForOrdering);
}
}
There was a problem hiding this comment.
Just for reference, this change ultimately relies on a call to this method:
We don't want to change the scope of the synchronized block, as far as I can tell.
michaeljmarshall
left a comment
There was a problem hiding this comment.
I do not think we should have made this change. The ManagedCursor can have alternate implementations, and I think the meaning of activating a cursor in the ledger is not necessarily the same as the whether the cursor views itself as active. For example, if the cursor had its own view of activity that diverges, we could get into odd conditions.
| public void activateCursor(ManagedCursor cursor) { | ||
| synchronized (activeCursors) { | ||
| if (activeCursors.get(cursor.getName()) == null) { | ||
| if (!cursor.isActive()) { |
There was a problem hiding this comment.
If any refactoring were to be made, I think we should have switched to use the ManagedLedgerImpl#isCursorActive method.
…or is active (apache#19159)" This reverts commit 78ea7f0.
|
I didn't see any follow up on my comments, so I propose a fix here: #19322 |
Motivation
When a cursor is activated, use
cursor.isActiveinstead ofactiveCursors.get(cursor.getName()) == nullto judge cursor's status. more readable.Modifications
Use cursor.isActive instead to judge if cursor is active
Verifying this change
(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:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
gaozhangmin#7