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

Reduce Properties invocation in InlineShardingAlgorithm #13282

Merged
merged 3 commits into from Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,6 +39,8 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<

private static final String ALLOW_RANGE_QUERY_KEY = "allow-range-query-with-inline-sharding";

private String algorithmExpression;

private boolean allowRangeQuery;

@Getter
Expand All @@ -47,16 +49,14 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<

@Override
public void init() {
algorithmExpression = getAlgorithmExpression();
allowRangeQuery = isAllowRangeQuery();
}

private Closure<?> createClosure() {
private String getAlgorithmExpression() {
String expression = props.getProperty(ALGORITHM_EXPRESSION_KEY);
Preconditions.checkNotNull(expression, "Inline sharding algorithm expression cannot be null.");
String algorithmExpression = InlineExpressionParser.handlePlaceHolder(expression.trim());
Closure<?> result = new InlineExpressionParser(algorithmExpression).evaluateClosure().rehydrate(new Expando(), null, null);
result.setResolveStrategy(Closure.DELEGATE_ONLY);
return result;
return InlineExpressionParser.handlePlaceHolder(expression.trim());
}

private boolean isAllowRangeQuery() {
Expand All @@ -78,6 +78,12 @@ public Collection<String> doSharding(final Collection<String> availableTargetNam
throw new UnsupportedOperationException("Since the property of `" + ALLOW_RANGE_QUERY_KEY + "` is false, inline sharding algorithm can not tackle with range query.");
}

private Closure<?> createClosure() {
Closure<?> result = new InlineExpressionParser(algorithmExpression).evaluateClosure().rehydrate(new Expando(), null, null);
result.setResolveStrategy(Closure.DELEGATE_ONLY);
return result;
}

@Override
public String getType() {
return "INLINE";
Expand Down