From a7ef4beffdab12ae154c40078810e7f7a10905ad Mon Sep 17 00:00:00 2001 From: Haoran Meng Date: Thu, 12 Dec 2024 18:42:41 +0800 Subject: [PATCH] Refactor refresh metadata after storage unit registered (#34028) --- .../ClusterMetaDataManagerPersistService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java index c2da0ec039206..38d026812dceb 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java @@ -125,7 +125,7 @@ public void registerStorageUnits(final String databaseName, final Map 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))); @@ -189,6 +187,12 @@ private void afterStorageUnitsAltered(final String databaseName, final MetaDataC 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));