strongduanmu opened a new issue #14777:
URL: https://github.com/apache/shardingsphere/issues/14777
When I am implementing a custom sharding algorithm using the `CLASS_BASED`
sharding algorithm, additional attribute definitions cannot be made.
```java
public final class CustomShardingAlgorithm implements
StandardShardingAlgorithm<Integer> {
private static final String SHARDING_COUNT = "sharding-count";
private Integer shardingCount;
@Getter
@Setter
private Properties props = new Properties();
@Override
public void init() {
Preconditions.checkArgument(props.containsKey(SHARDING_COUNT), "%s
can not be null.", SHARDING_COUNT);
shardingCount = Ints.tryParse(props.getProperty(SHARDING_COUNT));
Preconditions.checkArgument(null != shardingCount, "%s is not
valid.", SHARDING_COUNT);
}
@Override
public String doSharding(final Collection<String> availableTargetNames,
final PreciseShardingValue<Integer> shardingValue) {
for (String each : availableTargetNames) {
if (each.endsWith(String.valueOf(shardingValue.getValue() %
shardingCount))) {
return each;
}
}
return null;
}
@Override
public Collection<String> doSharding(final Collection<String>
availableTargetNames, final RangeShardingValue<Integer> shardingValue) {
return availableTargetNames;
}
@Override
public String getType() {
return "CUSTOM";
}
}
```
For example, in the CustomShardingAlgorithm algorithm, I want to specify the
number of shards through a custom attribute such as `sharding-count`, but the
current logic cannot obtain the `sharding-count` attribute from the props
attribute, because the `CLASS_BASED` sharding algorithm only performs algorithm
instantiation, without passing extra properties into the custom algorithm.
To simplify the use of the CLASS_BASED algorithm, I would like to be able to
support the configuration of custom properties.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]