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

Gateway - Add GatewayCurrentStateCache for gateway service #2895

Merged
merged 5 commits into from
Sep 4, 2024

Conversation

xyuanlu
Copy link
Contributor

@xyuanlu xyuanlu commented Aug 29, 2024

Issues

  • My PR addresses the following Helix issues and references them in the PR description:

#2821

Description

This pull request introduces a caching mechanism for the Helix Gateway service. The main changes include:

  1. Addition of a new GatewayCurrentStateCache class in GatewayCurrentStateCache.java, which manages caching of current and target states for instances in a cluster.

  2. Modification of GatewayServiceManager.java to incorporate the new caching functionality:

    • A new _currentStateCacheMap is added to store GatewayCurrentStateCache objects for each cluster.
    • A new method getCurrentStateCache(String clusterName) is introduced to retrieve or create a cache for a given cluster.

Test

A new test class TestGatewayCurrentStateCache.java has been added with the following tests:

Changes that Break Backward Compatibility

N/A

Documentation

N/A

Created with Palmier

@xyuanlu xyuanlu marked this pull request as ready for review August 29, 2024 17:11
Comment on lines 134 to 138
currentMap.get(instance).entrySet().stream().forEach(e -> {
if (currentState.get(e.getKey()) != null) {
e.setValue(currentState.get(e.getKey()));
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why update the entry of the diff map? That's tmp object.

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 are updating the currentMap, with diff map value.

@xyuanlu xyuanlu force-pushed the gatewayservice-4 branch 4 times, most recently from bd7865d to bc8698f Compare September 2, 2024 23:00
Comment on lines 77 to 94
public void updateCacheWithCurrentStateDiff(Map<String, Map<String, Map<String, String>>> currentStateDiff) {
for (String instance : currentStateDiff.keySet()) {
Map<String, Map<String, String>> currentStateDiffMap = currentStateDiff.get(instance);
_currentStateMap.computeIfAbsent(instance, k -> new ShardStateMap(new HashMap<>()))
.updateShardStateMapWithDiff(currentStateDiffMap);
}
}

/**
* Update the target state with the changed target state maps.
* All existing target states remains the same
* @param targetStateChangeMap
*/
public void updateTargetStateWithDiff(String instance, Map<String, Map<String, String>> targetStateChangeMap) {
_targetStateMap.computeIfAbsent(instance, k -> new ShardStateMap(new HashMap<>()))
.updateShardStateMapWithDiff(targetStateChangeMap);
}
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 2?

Copy link
Contributor Author

@xyuanlu xyuanlu Sep 3, 2024

Choose a reason for hiding this comment

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

They update different maps

Copy link
Contributor

Choose a reason for hiding this comment

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

Or let's combine? Have the second one as a private wrapper function. So the first one can do:

for (xxxxx) {
private func on each instance
}

Because I think the logic of codes are almost same.

Comment on lines 77 to 94
public void updateCacheWithCurrentStateDiff(Map<String, Map<String, Map<String, String>>> currentStateDiff) {
for (String instance : currentStateDiff.keySet()) {
Map<String, Map<String, String>> currentStateDiffMap = currentStateDiff.get(instance);
_currentStateMap.computeIfAbsent(instance, k -> new ShardStateMap(new HashMap<>()))
.updateShardStateMapWithDiff(currentStateDiffMap);
}
}

/**
* Update the target state with the changed target state maps.
* All existing target states remains the same
* @param targetStateChangeMap
*/
public void updateTargetStateWithDiff(String instance, Map<String, Map<String, String>> targetStateChangeMap) {
_targetStateMap.computeIfAbsent(instance, k -> new ShardStateMap(new HashMap<>()))
.updateShardStateMapWithDiff(targetStateChangeMap);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Or let's combine? Have the second one as a private wrapper function. So the first one can do:

for (xxxxx) {
private func on each instance
}

Because I think the logic of codes are almost same.

@xyuanlu
Copy link
Contributor Author

xyuanlu commented Sep 4, 2024

This change is ready to be merged. Approved by @junkaixue
Commit message: Gateway - Add GatewayCurrentStateCache for gateway

This pull request introduces a caching mechanism for the Helix Gateway service. The main changes include:

Addition of a new GatewayCurrentStateCache class in GatewayCurrentStateCache.java, which manages caching of current and target states for instances in a cluster.

@xyuanlu xyuanlu merged commit 85d93a0 into apache:helix-gateway-service Sep 4, 2024
1 check passed
asfgit pushed a commit that referenced this pull request Sep 6, 2024
This pull request introduces a caching mechanism for the Helix Gateway service. The main changes include:

Addition of a new GatewayCurrentStateCache class in GatewayCurrentStateCache.java, which manages caching of current and target states for instances in a cluster.
asfgit pushed a commit that referenced this pull request Sep 8, 2024
This pull request introduces a caching mechanism for the Helix Gateway service. The main changes include:

Addition of a new GatewayCurrentStateCache class in GatewayCurrentStateCache.java, which manages caching of current and target states for instances in a cluster.
asfgit pushed a commit that referenced this pull request Sep 18, 2024
This pull request introduces a caching mechanism for the Helix Gateway service. The main changes include:

Addition of a new GatewayCurrentStateCache class in GatewayCurrentStateCache.java, which manages caching of current and target states for instances in a cluster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants