[Refactor] Make sure the singleton thread is safe (#5428)
The following class org.apache.doris.clone.ColocateTableBalancer org.apache.doris.common.proc.ProcService org.apache.doris.rpc.BackendServiceProxy org.apache.doris.common.util.ProfileManager org.apache.doris.qe.HelpModule org.apache.doris.common.publish.ClusterStatePublisher is not safe in multiple thread environment. This PR is to implement a secure singleton mode. The class org.apache.doris.common.publish.ClusterStatePublisher singleton method is not used.
This commit is contained in:
@ -62,10 +62,14 @@ public class ColocateTableBalancer extends MasterDaemon {
|
||||
super("colocate group clone checker", intervalMs);
|
||||
}
|
||||
|
||||
private static ColocateTableBalancer INSTANCE = null;
|
||||
private static volatile ColocateTableBalancer INSTANCE = null;
|
||||
public static ColocateTableBalancer getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ColocateTableBalancer(CHECK_INTERVAL_MS);
|
||||
synchronized (ColocateTableBalancer.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ColocateTableBalancer(CHECK_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ import org.apache.logging.log4j.Logger;
|
||||
// proc service entry
|
||||
public final class ProcService {
|
||||
private static final Logger LOG = LogManager.getLogger(ProcService.class);
|
||||
private static ProcService INSTANCE;
|
||||
private static volatile ProcService INSTANCE;
|
||||
|
||||
private BaseProcDir root;
|
||||
|
||||
@ -154,7 +154,11 @@ public final class ProcService {
|
||||
|
||||
public static ProcService getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ProcService();
|
||||
synchronized (ProcService.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ProcService();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ import java.util.concurrent.ExecutorService;
|
||||
// This class intend to publish the state of cluster to backends.
|
||||
public class ClusterStatePublisher {
|
||||
private static final Logger LOG = LogManager.getLogger(ClusterStatePublisher.class);
|
||||
private static ClusterStatePublisher INSTANCE;
|
||||
private static volatile ClusterStatePublisher INSTANCE;
|
||||
|
||||
private ExecutorService executor = ThreadPoolManager.newDaemonFixedThreadPool(5, 256, "cluster-state-publisher", true);
|
||||
|
||||
@ -52,7 +52,11 @@ public class ClusterStatePublisher {
|
||||
|
||||
public static ClusterStatePublisher getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ClusterStatePublisher(Catalog.getCurrentSystemInfo());
|
||||
synchronized (ClusterStatePublisher.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ClusterStatePublisher(Catalog.getCurrentSystemInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
*/
|
||||
public class ProfileManager {
|
||||
private static final Logger LOG = LogManager.getLogger(ProfileManager.class);
|
||||
private static ProfileManager INSTANCE = null;
|
||||
private static volatile ProfileManager INSTANCE = null;
|
||||
private static final int ARRAY_SIZE = 100;
|
||||
// private static final int TOTAL_LEN = 1000 * ARRAY_SIZE ;
|
||||
public static final String QUERY_ID = "Query ID";
|
||||
@ -80,7 +80,11 @@ public class ProfileManager {
|
||||
|
||||
public static ProfileManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ProfileManager();
|
||||
synchronized (ProfileManager.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ProfileManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -301,7 +301,11 @@ public class HelpModule {
|
||||
// whether need reload ZipFile
|
||||
public static HelpModule getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new HelpModule();
|
||||
synchronized (HelpModule.class) {
|
||||
if (instance == null) {
|
||||
instance = new HelpModule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -59,7 +59,7 @@ public class BackendServiceProxy {
|
||||
// TODO(zc): use TNetworkAddress,
|
||||
private Map<TNetworkAddress, PBackendService> serviceMap;
|
||||
|
||||
private static BackendServiceProxy INSTANCE;
|
||||
private static volatile BackendServiceProxy INSTANCE;
|
||||
|
||||
static {
|
||||
int javaRuntimeVersion = JdkUtils.getJavaVersionAsInteger(System.getProperty("java.version"));
|
||||
@ -76,7 +76,11 @@ public class BackendServiceProxy {
|
||||
|
||||
public static BackendServiceProxy getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new BackendServiceProxy();
|
||||
synchronized (BackendServiceProxy.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new BackendServiceProxy();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import org.apache.doris.qe.MultiLoadMgr;
|
||||
|
||||
// Execute environment, used to save other module, need to singleton
|
||||
public class ExecuteEnv {
|
||||
private volatile static ExecuteEnv INSTANCE;
|
||||
private static volatile ExecuteEnv INSTANCE;
|
||||
private MultiLoadMgr multiLoadMgr;
|
||||
private ConnectScheduler scheduler;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user