Skip to content

Commit db0c69a

Browse files
authored
Fixed the potential NPE in clear all cache on local (apache#16378)
1 parent dd18e71 commit db0c69a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
import org.apache.iotdb.mpp.rpc.thrift.IDataNodeRPCService.Processor;
3636
import org.apache.iotdb.rpc.DeepCopyRpcTransportFactory;
3737

38+
import java.util.concurrent.atomic.AtomicReference;
39+
3840
public class DataNodeInternalRPCService extends ThriftService
3941
implements DataNodeInternalRPCServiceMBean {
4042

4143
private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
4244
private static final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig();
4345

44-
private DataNodeInternalRPCServiceImpl impl;
46+
private final AtomicReference<DataNodeInternalRPCServiceImpl> impl = new AtomicReference<>();
4547

4648
private DataNodeInternalRPCService() {}
4749

@@ -51,11 +53,10 @@ public ServiceType getID() {
5153
}
5254

5355
@Override
54-
public void initTProcessor()
55-
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
56-
impl = new DataNodeInternalRPCServiceImpl();
56+
public void initTProcessor() {
57+
impl.compareAndSet(null, new DataNodeInternalRPCServiceImpl());
5758
initSyncedServiceImpl(null);
58-
processor = new Processor<>(impl);
59+
processor = new Processor<>(impl.get());
5960
}
6061

6162
@Override
@@ -108,7 +109,8 @@ public int getBindPort() {
108109
}
109110

110111
public DataNodeInternalRPCServiceImpl getImpl() {
111-
return impl;
112+
impl.compareAndSet(null, new DataNodeInternalRPCServiceImpl());
113+
return impl.get();
112114
}
113115

114116
private static class DataNodeInternalRPCServiceHolder {

0 commit comments

Comments
 (0)