* refactor: refactor issue #4291 * fix: fixing the Naming consistency module could not start in cluster mode
This commit is contained in:
parent
c8d46a6046
commit
70a26959e3
@ -17,11 +17,15 @@
|
|||||||
package com.alibaba.nacos.naming.consistency.persistent;
|
package com.alibaba.nacos.naming.consistency.persistent;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
|
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
||||||
import com.alibaba.nacos.naming.consistency.Datum;
|
import com.alibaba.nacos.naming.consistency.Datum;
|
||||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.impl.BasePersistentServiceProcessor;
|
import com.alibaba.nacos.naming.consistency.persistent.impl.BasePersistentServiceProcessor;
|
||||||
|
import com.alibaba.nacos.naming.consistency.persistent.impl.PersistentServiceProcessor;
|
||||||
|
import com.alibaba.nacos.naming.consistency.persistent.impl.StandalonePersistentServiceProcessor;
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftConsistencyServiceImpl;
|
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftConsistencyServiceImpl;
|
||||||
import com.alibaba.nacos.naming.pojo.Record;
|
import com.alibaba.nacos.naming.pojo.Record;
|
||||||
|
import com.alibaba.nacos.sys.env.EnvUtil;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,11 +45,11 @@ public class PersistentConsistencyServiceDelegateImpl implements PersistentConsi
|
|||||||
private volatile boolean switchNewPersistentService = false;
|
private volatile boolean switchNewPersistentService = false;
|
||||||
|
|
||||||
public PersistentConsistencyServiceDelegateImpl(ClusterVersionJudgement versionJudgement,
|
public PersistentConsistencyServiceDelegateImpl(ClusterVersionJudgement versionJudgement,
|
||||||
RaftConsistencyServiceImpl oldPersistentConsistencyService,
|
RaftConsistencyServiceImpl oldPersistentConsistencyService, ProtocolManager protocolManager)
|
||||||
BasePersistentServiceProcessor newPersistentConsistencyService) {
|
throws Exception {
|
||||||
this.versionJudgement = versionJudgement;
|
this.versionJudgement = versionJudgement;
|
||||||
this.oldPersistentConsistencyService = oldPersistentConsistencyService;
|
this.oldPersistentConsistencyService = oldPersistentConsistencyService;
|
||||||
this.newPersistentConsistencyService = newPersistentConsistencyService;
|
this.newPersistentConsistencyService = createNewPersistentServiceProcessor(protocolManager, versionJudgement);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,4 +92,13 @@ public class PersistentConsistencyServiceDelegateImpl implements PersistentConsi
|
|||||||
private PersistentConsistencyService switchOne() {
|
private PersistentConsistencyService switchOne() {
|
||||||
return switchNewPersistentService ? newPersistentConsistencyService : oldPersistentConsistencyService;
|
return switchNewPersistentService ? newPersistentConsistencyService : oldPersistentConsistencyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BasePersistentServiceProcessor createNewPersistentServiceProcessor(ProtocolManager protocolManager,
|
||||||
|
ClusterVersionJudgement versionJudgement) throws Exception {
|
||||||
|
final BasePersistentServiceProcessor processor =
|
||||||
|
EnvUtil.getStandaloneMode() ? new StandalonePersistentServiceProcessor(versionJudgement)
|
||||||
|
: new PersistentServiceProcessor(protocolManager, versionJudgement);
|
||||||
|
processor.afterConstruct();
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,10 @@ public abstract class BasePersistentServiceProcessor extends RequestProcessor4CP
|
|||||||
throw new NacosRuntimeException(ex.getErrCode(), ex.getErrMsg());
|
throw new NacosRuntimeException(ex.getErrCode(), ex.getErrMsg());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
afterConstruct();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected void afterConstruct() {
|
public void afterConstruct() {
|
||||||
NotifyCenter.registerToPublisher(ValueChangeEvent.class, 16384);
|
NotifyCenter.registerToPublisher(ValueChangeEvent.class, 16384);
|
||||||
listenOldRaftClose();
|
listenOldRaftClose();
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,6 @@ import com.alibaba.nacos.naming.pojo.Record;
|
|||||||
import com.alibaba.nacos.naming.utils.Constants;
|
import com.alibaba.nacos.naming.utils.Constants;
|
||||||
import com.alibaba.nacos.sys.env.EnvUtil;
|
import com.alibaba.nacos.sys.env.EnvUtil;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -49,8 +47,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||||
@ConditionalOnProperty(value = "nacos.standalone", havingValue = "false")
|
|
||||||
@Service
|
|
||||||
public class PersistentServiceProcessor extends BasePersistentServiceProcessor {
|
public class PersistentServiceProcessor extends BasePersistentServiceProcessor {
|
||||||
|
|
||||||
private final CPProtocol protocol;
|
private final CPProtocol protocol;
|
||||||
@ -67,7 +63,7 @@ public class PersistentServiceProcessor extends BasePersistentServiceProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void afterConstruct() {
|
public void afterConstruct() {
|
||||||
super.afterConstruct();
|
super.afterConstruct();
|
||||||
this.protocol.addLogProcessors(Collections.singletonList(this));
|
this.protocol.addLogProcessors(Collections.singletonList(this));
|
||||||
this.protocol.protocolMetaData()
|
this.protocol.protocolMetaData()
|
||||||
|
@ -28,8 +28,6 @@ import com.alibaba.nacos.naming.consistency.persistent.ClusterVersionJudgement;
|
|||||||
import com.alibaba.nacos.naming.pojo.Record;
|
import com.alibaba.nacos.naming.pojo.Record;
|
||||||
import com.alibaba.nacos.naming.utils.Constants;
|
import com.alibaba.nacos.naming.utils.Constants;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -40,8 +38,6 @@ import java.util.List;
|
|||||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||||
@ConditionalOnProperty(value = "nacos.standalone", havingValue = "true")
|
|
||||||
@Service
|
|
||||||
public class StandalonePersistentServiceProcessor extends BasePersistentServiceProcessor {
|
public class StandalonePersistentServiceProcessor extends BasePersistentServiceProcessor {
|
||||||
|
|
||||||
public StandalonePersistentServiceProcessor(final ClusterVersionJudgement judgement) throws Exception {
|
public StandalonePersistentServiceProcessor(final ClusterVersionJudgement judgement) throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user