Skip to content

Commit

Permalink
Fix invalid version exception after data source unit altered
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss committed Dec 26, 2024
1 parent ad02d16 commit db11b18
Showing 1 changed file with 2 additions and 8 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);
afterStorageUnitsRegistered(databaseName, originalMetaDataContexts, reloadMetaDataContexts);
afterStorageUnitsAltered(databaseName, originalMetaDataContexts, reloadMetaDataContexts);
reloadMetaDataContexts.close();
} finally {
closeNewDataSources(newDataSources);
Expand Down Expand Up @@ -179,20 +179,14 @@ private Collection<String> getToBeDroppedResourceNames(final String databaseName
return toBeDroppedResourceNames.stream().filter(propsMap::containsKey).collect(Collectors.toList());
}

private void afterStorageUnitsRegistered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) {
private void afterStorageUnitsAltered(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 db11b18

Please sign in to comment.