You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/06/28 01:58:57 UTC
[GitHub] [shardingsphere] natehuangting commented on issue #18430: Queries and updates without shard keys are not allowed
natehuangting commented on issue #18430:
URL: https://github.com/apache/shardingsphere/issues/18430#issuecomment-1168122045
I have designed the audit scheme as follows.
The first is configuration, like ShardingShpereAlgorithm, only type and props, so it can also be defined using ShardingShpereAlgorithm.
I thought of two configuration methods, scheme 1 is more brief, scheme 2 is more readable.It should be noted that the algorithm will only be defined and used only once in the Sharding configuration.
scheme 1
```
rules:
- !SHARDING
audits:
- type: SHARDING_KEY_CHECK
props:
allow-hint-without_sharding_key: true
- type: SHARDING_KEY_CHECK
props:
allow-hint-without_sharding_key: true
```
Scheme 2
```
rules:
- !SHARDING
auditAlgorithms:
default_audit1:
type: SHARDING_KEY_CHECK
props:
allow-hint-without_sharding_key: true
default_audit2:
type: SHARDING_KEY_CHECK
props:
allow-hint-without_sharding_key: true
audits:
- default_audit1
- default_audit2
```
```
package org.apache.shardingsphere.sharding.yaml.config;
public final class YamlShardingRuleConfiguration implements YamlRuleConfiguration {
private Collection<YamlShardingSphereAlgorithmConfiguration> audits = new LinkedList<>();
}
```
The second is ShardingAuditAlgorithm, like ShardingAlgorithm, ShardingAuditAlgorithm is also a subclass of ShardingSphereAlgorithm.
<img width="297" alt="image" src="https://user-images.githubusercontent.com/26433395/176070140-87075b21-dce1-4e59-953e-4a5abc5d98f1.png">
```
package org.apache.shardingsphere.sharding.spi;
public final class ShardingAuditChecker implements SQLChecker<ShardingRule> {
@Override
public boolean check(final String databaseName, final Grantee grantee, final ShardingRule rule) {
return true;
}
@Override
public SQLCheckResult check(final SQLStatement sqlStatement, final List<Object> parameters, final Grantee grantee,
final String currentDatabase, final Map<String, ShardingSphereDatabase> databases,
final ShardingRule rule) {
for (ShardingAuditAlgorithm shardingAuditCheckAlgorithm : rule.getShardingAuditAlgorithms()) {
SQLCheckResult sqlCheckResult = shardingAuditCheckAlgorithm.check(sqlStatement, parameters, grantee, currentDatabase, databases, rule);
if (!sqlCheckResult.isPassed()) {
return sqlCheckResult;
}
}
return new SQLCheckResult(true, "");
}
@Override
public boolean check(final Grantee grantee, final ShardingRule rule) {
return true;
}
@Override
public boolean check(final Grantee grantee, final BiPredicate<Object, Object> validator, final Object cipher,
final ShardingRule rule) {
return true;
}
@Override
public int getOrder() {
return ShardingAuditOrder.ORDER;
}
@Override
public Class<ShardingRule> getTypeClass() {
return ShardingRule.class;
}
}
```
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org