Skip to content

[improve][broker]Use cursor.isActive instead to judge if cursor is active - #19159

Merged
gaozhangmin merged 1 commit into
apache:masterfrom
gaozhangmin:managedcursor
Jan 11, 2023
Merged

[improve][broker]Use cursor.isActive instead to judge if cursor is active#19159
gaozhangmin merged 1 commit into
apache:masterfrom
gaozhangmin:managedcursor

Conversation

@gaozhangmin

@gaozhangmin gaozhangmin commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

Motivation

When a cursor is activated, use cursor.isActive instead of activeCursors.get(cursor.getName()) == null to judge cursor's status. more readable.

Modifications

Use cursor.isActive instead to judge if cursor is active

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

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

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

Matching PR in forked repository

gaozhangmin#7

@github-actions

github-actions Bot commented Jan 9, 2023

Copy link
Copy Markdown

@gaozhangmin Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@gaozhangmin gaozhangmin changed the title Use cursor.isActive instead to judge if cursor is active [improve][broker]Use cursor.isActive instead to judge if cursor is active Jan 9, 2023
@gaozhangmin gaozhangmin self-assigned this Jan 9, 2023
@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Jan 9, 2023
public void activateCursor(ManagedCursor cursor) {
synchronized (activeCursors) {
if (activeCursors.get(cursor.getName()) == null) {
if (!cursor.isActive()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);
     }
}          

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for reference, this change ultimately relies on a call to this method:

public boolean isCursorActive(ManagedCursor cursor) {
return activeCursors.get(cursor.getName()) != null;
}

We don't want to change the scope of the synchronized block, as far as I can tell.

@gaozhangmin
gaozhangmin merged commit 78ea7f0 into apache:master Jan 11, 2023

@michaeljmarshall michaeljmarshall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If any refactoring were to be made, I think we should have switched to use the ManagedLedgerImpl#isCursorActive method.

michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request Jan 25, 2023
@michaeljmarshall

Copy link
Copy Markdown
Member

I didn't see any follow up on my comments, so I propose a fix here: #19322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants