Skip to content

Commit

Permalink
Refactor QualifiedDataSourceStatusService (#31188)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored May 9, 2024
1 parent 12e9e74 commit 359e4f2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void checkBeforeUpdate(final AlterReadwriteSplittingStorageUnitStatusSta
private void updateStatus(final ContextManager contextManager, final AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
DataSourceState status = sqlStatement.isEnable() ? DataSourceState.ENABLED : DataSourceState.DISABLED;
new QualifiedDataSourceStatusService(contextManager.getMetaDataContexts().getPersistService().getRepository())
.changeMemberQualifiedDataSourceStatus(database.getName(), sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status);
.changeStatus(database.getName(), sqlStatement.getRuleName(), sqlStatement.getStorageUnitName(), status);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class QualifiedDataSourceStatusService {
*
* @return qualified data source status
*/
public Map<String, QualifiedDataSourceStatus> loadQualifiedDataSourceStatus() {
public Map<String, QualifiedDataSourceStatus> loadStatus() {
Collection<String> qualifiedDataSourceNodes = repository.getChildrenKeys(QualifiedDataSourceNode.getRootPath());
Map<String, QualifiedDataSourceStatus> result = new HashMap<>(qualifiedDataSourceNodes.size(), 1F);
qualifiedDataSourceNodes.forEach(each -> {
Expand All @@ -58,16 +58,16 @@ public Map<String, QualifiedDataSourceStatus> loadQualifiedDataSourceStatus() {
}

/**
* Change member qualified data source status.
* Change qualified data source status.
*
* @param databaseName database name
* @param groupName group name
* @param storageUnitName storage unit name
* @param dataSourceState data source state
*/
public void changeMemberQualifiedDataSourceStatus(final String databaseName, final String groupName, final String storageUnitName, final DataSourceState dataSourceState) {
public void changeStatus(final String databaseName, final String groupName, final String storageUnitName, final DataSourceState dataSourceState) {
QualifiedDataSourceStatus status = new QualifiedDataSourceStatus(dataSourceState);
repository.persist(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(new QualifiedDataSource(databaseName, groupName, storageUnitName)),
YamlEngine.marshal(new YamlQualifiedDataSourceStatusSwapper().swapToYamlConfiguration(status)));
repository.persist(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(
new QualifiedDataSource(databaseName, groupName, storageUnitName)), YamlEngine.marshal(new YamlQualifiedDataSourceStatusSwapper().swapToYamlConfiguration(status)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ContextManager build(final ContextManagerBuilderParameter param) throws S
}
MetaDataPersistService persistService = new MetaDataPersistService(repository);
MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(
persistService, param, instanceContext, registryCenter.getQualifiedDataSourceStatusService().loadQualifiedDataSourceStatus());
persistService, param, instanceContext, registryCenter.getQualifiedDataSourceStatusService().loadStatus());
ContextManager result = new ContextManager(metaDataContexts, instanceContext);
setContextManagerAware(result);
registerOnline(registryCenter, param, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class QualifiedDataSourceStatusServiceTest {
private ClusterPersistRepository repository;

@Test
void assertLoadDisabledDataSources() {
void assertLoadStatus() {
List<String> disabledDataSources = Arrays.asList("replica_query_db.readwrite_ds.replica_ds_0", "other_schema.other_ds.other_ds0");
when(repository.getChildrenKeys(anyString())).thenReturn(disabledDataSources);
assertDoesNotThrow(() -> new QualifiedDataSourceStatusService(repository).loadQualifiedDataSourceStatus());
assertDoesNotThrow(() -> new QualifiedDataSourceStatusService(repository).loadStatus());
}
}

0 comments on commit 359e4f2

Please sign in to comment.