Skip to content

Commit

Permalink
[CELEBORN-1516] DynamicConfigServiceFactory should support singleton
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
DynamicConfigServiceFactory supports singleton.

### Why are the changes needed?
Improve code.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Existing UTs.

Closes #2635 from leixm/singleton.

Authored-by: Xianming Lei <[email protected]>
Signed-off-by: Shuang <[email protected]>
(cherry picked from commit d5b124d)
Signed-off-by: Shuang <[email protected]>
  • Loading branch information
leixm authored and RexXiong committed Jul 19, 2024
1 parent 176486b commit f62b5db
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
import org.apache.celeborn.common.CelebornConf;

public class DynamicConfigServiceFactory {
private static volatile ConfigService _INSTANCE;

public static ConfigService getConfigService(CelebornConf celebornConf) throws IOException {
if (celebornConf.dynamicConfigStoreBackend().isEmpty()) {
return null;
} else {
String configStoreBackend = celebornConf.dynamicConfigStoreBackend().get();
// celeborn.dynamicConfig.store.backend checks value with FS, DB.
if ("FS".equals(configStoreBackend)) {
return new FsConfigServiceImpl(celebornConf);
} else {
return new DbConfigServiceImpl(celebornConf);
}

if (_INSTANCE == null) {
synchronized (DynamicConfigServiceFactory.class) {
if (_INSTANCE == null) {
String configStoreBackend = celebornConf.dynamicConfigStoreBackend().get();
if ("FS".equals(configStoreBackend)) {
_INSTANCE = new FsConfigServiceImpl(celebornConf);
} else {
_INSTANCE = new DbConfigServiceImpl(celebornConf);
}
}
}
}

return _INSTANCE;
}
}

0 comments on commit f62b5db

Please sign in to comment.