Skip to content

Commit

Permalink
Refactor refresh metadata after storage unit registered (#34028)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss authored Dec 12, 2024
1 parent d0adaa8 commit a7ef4be
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void registerStorageUnits(final String databaseName, final Map<String, Da
MetaDataContexts reloadMetaDataContexts = MetaDataContextsFactory.createBySwitchResource(databaseName, false,
switchingResource, originalMetaDataContexts, metaDataPersistService, metaDataContextManager.getComputeNodeInstanceContext());
metaDataPersistService.getDataSourceUnitService().persist(databaseName, toBeRegisteredProps);
afterStorageUnitsAltered(databaseName, originalMetaDataContexts, reloadMetaDataContexts);
afterStorageUnitsRegistered(databaseName, originalMetaDataContexts, reloadMetaDataContexts);
reloadMetaDataContexts.close();
} finally {
closeNewDataSources(newDataSources);
Expand Down Expand Up @@ -179,16 +179,20 @@ private Collection<String> getToBeDroppedResourceNames(final String databaseName
return toBeDroppedResourceNames.stream().filter(propsMap::containsKey).collect(Collectors.toList());
}

private void afterStorageUnitsAltered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) {
reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade()
.getSchema().alterByRuleAltered(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each));
private void afterStorageUnitsRegistered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) {
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseData().get(databaseName))
.ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> metaDataPersistService.getShardingSphereDataPersistService()
.persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), schemaName, schemaData)));
metaDataPersistService.persistReloadDatabaseByAlter(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName),
originalMetaDataContexts.getMetaData().getDatabase(databaseName));
}

private void afterStorageUnitsAltered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) {
reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade()
.getSchema().alterByRuleAltered(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each));
afterStorageUnitsRegistered(databaseName, originalMetaDataContexts, reloadMetaDataContexts);
}

private void afterStorageUnitsDropped(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) {
reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade()
.getSchema().alterByRuleDropped(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each));
Expand Down

0 comments on commit a7ef4be

Please sign in to comment.