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-192: Added VersionId in ServiceUnitStateData #19620

Merged
merged 2 commits into from
Mar 1, 2023

Conversation

heesung-sn
Copy link
Contributor

@heesung-sn heesung-sn commented Feb 24, 2023

Master Issue: #16691

Motivation

There is a possible edge case where bundle ownership could be negatively impacted by delayed commands in the new load balancer.

Let's say a (network-partitioned) broker has a delayed ServiceUnitStateChannel and triggers a transfer or unload command based on it. This transfer or unload command should be rejected as it is from an outdated context.

To reject this outdated transition, I propose versionId in ServiceUnitStateData, which monotonically increases for its subsequent state changes until tombstoned. ServiceUnitStateCompactionStrategy can reject messages with older versions than the previous ones(assert prev+1 == cur).

After this PR,
... Owned(versionId=50) -> Transfer_Assigned(versionId=45) // invalid
... Owned(versionId=50) -> Transfer_Assigned(versionId=51) // valid

Modifications

This PR

  • Added versionId in ServiceUnitStateData

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • *Updated unit tests.

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
  • Anything that affects deployment

Documentation

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

We will have separate PRs to update the Doc later.

Matching PR in forked repository

PR in forked repository: heesung-sn#33

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Feb 24, 2023
@Demogorgon314 Demogorgon314 changed the title [broker][improve] PIP-192 Added VersionId in ServiceUnitStateData [improve][broker] PIP-192: Added VersionId in ServiceUnitStateData Feb 24, 2023
@Demogorgon314 Demogorgon314 self-requested a review February 24, 2023 01:41
}

public static ServiceUnitState state(ServiceUnitStateData data) {
return data == null ? ServiceUnitState.Init : data.state();
}

public static long versionId(ServiceUnitStateData data) {
return data == null ? 0 : data.versionId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the VERSION_ID_INIT as the default value?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

@heesung-sn heesung-sn Feb 27, 2023

Choose a reason for hiding this comment

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

No. VERSION_ID_INIT is 1, and for the null data, it needs to be zero in order to make the first non-null version be 1( 0 + 1).

We can return VERSION_ID_INIT - 1(which is zero) if null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that too. Then, we don't need to call versionId(data) since we already did the null check.

    private long getNextVersionId(String serviceUnit) {
        var data = tableview.get(serviceUnit);
        return getNextVersionId(data);
    }

    private long getNextVersionId(ServiceUnitStateData data) {
        return data == null ? VERSION_ID_INIT : data.getVersionId() + 1;
    }

Updated the code.

Nevertheless, if this is the first version(child bundle creation), we can pass the VERSION_ID_INIT without calling getNextVersionId(null). It looks redundant to call getNextVersionId(null) to get VERSION_ID_INIT.

ServiceUnitStateData next = new ServiceUnitStateData(Owned, data.broker(), VERSION_ID_INIT);
or
ServiceUnitStateData next = new ServiceUnitStateData(Owned, data.broker(), getNextVersionId(null));

}

public static ServiceUnitState state(ServiceUnitStateData data) {
return data == null ? ServiceUnitState.Init : data.state();
}

public static long versionId(ServiceUnitStateData data) {
return data == null ? 0 : data.versionId();
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +56 to +58
if (from != null && from.versionId() + 1 != to.versionId()) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to filter out the invalidate data when reading from the topic? Otherwise, we might get an inconsistent data view with the compacted data.

Copy link
Contributor Author

@heesung-sn heesung-sn Feb 27, 2023

Choose a reason for hiding this comment

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

Yes, when reading msgs from the table views or strategic compaction, we do apply this same strategy to filter out invalid states.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, got it. The table view also apply this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@heesung-sn heesung-sn force-pushed the pip-192-bsc-versionid branch from 4bdec08 to 715139d Compare February 27, 2023 19:33
Comment on lines +56 to +58
if (from != null && from.versionId() + 1 != to.versionId()) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, got it. The table view also apply this change.

@Technoboy- Technoboy- added this to the 3.0.0 milestone Feb 28, 2023
@Technoboy- Technoboy- added ready-to-test type/feature The PR added a new feature or issue requested a new feature area/broker labels Feb 28, 2023
@Technoboy- Technoboy- merged commit a12f554 into apache:master Mar 1, 2023
@heesung-sn heesung-sn deleted the pip-192-bsc-versionid branch April 2, 2024 17:44
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 ready-to-test type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants