strongduanmu opened a new issue, #17715:
URL: https://github.com/apache/shardingsphere/issues/17715
## Feature Request
### Is your feature request related to a problem?
No
### Describe the feature you would like.
There are two problems in the existing metadata renew logic:
1. The following putAll method is used in the renew logic to update the
metadata in memory, which makes us need to control the concurrency of the
metadata;
```java
private void refreshMetaDataContext(final String databaseName, final
Map<String, DataSourceProperties> dataSourceProps) throws SQLException {
MetaDataContexts changedMetaDataContext =
buildChangedMetaDataContextWithAddedDataSource(metaDataContexts.getMetaDataMap().get(databaseName),
dataSourceProps);
metaDataContexts.getMetaDataMap().putAll(changedMetaDataContext.getMetaDataMap());
metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContext.getOptimizerContext().getFederationMetaData().getDatabases());
metaDataContexts.getOptimizerContext().getParserContexts().putAll(changedMetaDataContext.getOptimizerContext().getParserContexts());
metaDataContexts.getOptimizerContext().getPlannerContexts().putAll(changedMetaDataContext.getOptimizerContext().getPlannerContexts());
renewTransactionContext(databaseName,
metaDataContexts.getMetaData(databaseName).getResource());
}
```
2. The `databaseMap` in the `MetaDataContextsBuilder` contains the system
database and the normal database, and maintaining them in one object will lead
to the cost of understanding and unnecessary execution logic when renewing
metadata;
In order to solve these two problems, we need to optimize the logic of renew.
First, the databaseMap in MetaDataContextsBuilder is divided into normal
database and system database. The normal database needs to be rebuilt by renew,
but the system database does not need to be rebuilt.
Secondly, in the renew logic, do not use the putAll method to update, but
directly replace the new object with a new one, and add volatile to the object
to remove unnecessary synchronization locks.
--
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]