Comments (2)
The business supports global data centers, so routing enforcement based on the user's country is implemented in AOP aspects. However, some issues have been identified. For instance, Data Center A is configured with read-write separation. Forced routing might direct traffic to a secondary node, but if the current operation is a write operation, ShardingSphere may execute the write operation on the secondary node despite the enforced routing. Therefore, considering read-write separation, compatibility with read-write operations should be ensured. Currently, compatibility with ReadwriteSplittingSQLRouter has been implemented. The code is as follows:
public final class ShardingReadwriteSplittingSQLRouter implements SQLRouter {
@Override
public RouteContext createRouteContext(QueryContext queryContext, RuleMetaData ruleMetaData, ShardingSphereDatabase shardingSphereDatabase, ReadwriteSplittingRule rule, ConfigurationProperties configurationProperties, ConnectionContext connectionContext) {
RouteContext result = new RouteContext();
ReadwriteSplittingDataSourceRule singleDataSourceRule = rule.getSingleDataSourceRule();
String dataSourceName = (new ReadwriteSplittingDataSourceRouter(singleDataSourceRule, connectionContext)).route(queryContext.getSqlStatementContext(), queryContext.getHintValueContext());
result.getRouteUnits().add(new RouteUnit(new RouteMapper(singleDataSourceRule.getName(), dataSourceName), Collections.emptyList()));
return result;
}
@Override
public void decorateRouteContext(RouteContext routeContext, QueryContext queryContext, ShardingSphereDatabase database, ReadwriteSplittingRule rule, ConfigurationProperties props, ConnectionContext connectionContext) {
Collection<RouteUnit> toBeRemoved = new LinkedList<>();
Collection<RouteUnit> toBeAdded = new LinkedList<>();
for (RouteUnit each : routeContext.getRouteUnits()) {
String dataSourceName = each.getDataSourceMapper().getLogicName();
Optional<ReadwriteSplittingDataSourceRule> dataSourceRule = rule.findDataSourceRule(dataSourceName);
if (dataSourceRule.isEmpty()) {
Map<String, ReadwriteSplittingDataSourceRule> dataSourceMappers = rule.getDataSourceRules();
for (Map.Entry<String, ReadwriteSplittingDataSourceRule> dataSourceMapper : dataSourceMappers.entrySet()) {
if (dataSourceMapper.getValue().getDisabledDataSourceNames().contains(dataSourceName)) {
dataSourceRule = rule.findDataSourceRule(dataSourceMapper.getKey());
if (dataSourceRule.isPresent()) {
toBeRemoved.add(each);
String actualDataSourceName = (new ReadwriteSplittingDataSourceRouter(dataSourceRule.get(), connectionContext)).route(queryContext.getSqlStatementContext(), queryContext.getHintValueContext());
toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers()));
}
}
}
} else {
if (dataSourceRule.get().getName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) {
toBeRemoved.add(each);
String actualDataSourceName = (new ReadwriteSplittingDataSourceRouter(dataSourceRule.get(), connectionContext)).route(queryContext.getSqlStatementContext(), queryContext.getHintValueContext());
toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers()));
}
}
}
routeContext.getRouteUnits().removeAll(toBeRemoved);
routeContext.getRouteUnits().addAll(toBeAdded);
}
@Override
public int getOrder() {
return ReadwriteSplittingOrder.ORDER + 2;
}
@Override
public Class<ReadwriteSplittingRule> getTypeClass() {
return ReadwriteSplittingRule.class;
}
from shardingsphere.
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
from shardingsphere.
Related Issues (20)
- Class name: org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration changed in document
- hintManager.addTableShardingValue ,No effect HOT 2
- Sudden CPU idle alarm caused by shardingshpere-proxy HOT 2
- Refactor data collection for pg_namespace and pg_class tables
- Why does the running mode no longer support nacos since version 5.4.1? HOT 1
- ConditionValueInOperatorGenerator not excluding the case of not in HOT 1
- Missing dependencies HOT 2
- encounter NullPointerException when start springboot project HOT 1
- can not query information_schema.COLUMNS return empty HOT 1
- Could a closed issue via github action stale close be reopened by community ?
- connect blocked in Standalone mode HOT 6
- Refactor package of IntegrationTestCases
- I can’t find 5.5.0 version jar on https://mvnrepository.com/ HOT 3
- Having trouble setting user session variables when connecting to a MySQL server through ShardingSphere Proxy
- with java api to create shardingSphereDatasource ,logic_table will not in logic_db -> schemas->tables HOT 8
- how to config PostgreSQL default schema name HOT 2
- adapt to a custom connection pool HOT 11
- executeBatch not support xa transaction HOT 4
- Single Table Schema Issues in PostgreSQL 5.5.0 HOT 7
- Recursive query logic table times error:Table or view 'tmp' does not exist. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shardingsphere.