Skip to content

Conversation

@chenshouye168
Copy link
Contributor

Modify the zookeeper and service-center registry code to be able to modify the state to support graceful application up and down.

discoveryManager.run();
// ensure can invoke services in AFTER_REGISTRY
registrationManager.updateMicroserviceInstanceStatus(MicroserviceInstanceStatus.UP);
// registrationManager.updateMicroserviceInstanceStatus(MicroserviceInstanceStatus.UP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not comment this statement. Add a configuration to support not update status to UP when service is registered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the code, only service-center implements this method, the other registry just return true, the initialization status to properties/yml inside, the default is true, the registration status is also true, I think it will not affect the compatibility of this line of code to remove!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Delete this line.

Comment on lines 181 to 185
if (instance.getHistoryStatus() == HistoryStatus.CURRENT
&& instance.getMicroserviceInstanceStatus() == MicroserviceInstanceStatus.UP) {
result.add(instance);
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non UP status should added to list. InstanceStatusDiscoveryFilter will handle status priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this filter.

this.microserviceInstanceStatus = discoveryInstance.getStatus();
}

public MicroserviceInstanceStatus getMicroserviceInstanceStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can delete method getMicroserviceInstanceStatus and use getStatus for all appearances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the 'getMicroserviceInstanceStatus' method has been added to the MicroserviceInstance class.,as getStatus().

Comment on lines 145 to 149
if (scConfigurationProperties.isEnableElegantUpDown()){
microserviceInstance.setStatus(MicroserviceInstanceStatus.STARTING);
}else {
microserviceInstance.setStatus(MicroserviceInstanceStatus.UP);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do not need this modification. Users can configure initial status to STARTING when need elegant up down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,have removed

Comment on lines 177 to 183
public boolean isEnableElegantUpDown() {
return enableElegantUpDown;
}

public void setEnableElegantUpDown(boolean enableElegantUpDown) {
this.enableElegantUpDown = enableElegantUpDown;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, maybe do not need this modification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,have removed

Comment on lines 79 to 85
org.apache.servicecomb.service.center.client.model.DataCenterInfo dataCenterInfo = microserviceInstance.getDataCenterInfo();
if (dataCenterInfo != null) {
return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(),
microserviceInstance.getDataCenterInfo().getRegion(),
microserviceInstance.getDataCenterInfo().getAvailableZone());
}
return new DataCenterInfo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When DataCenterInfo is null? Can we add a fix to register DataCenterInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,have removed, Setting the initial value on DataCenterProperties
image

Comment on lines 198 to 203
public MicroserviceInstance getLatestMicroserviceInstance() {
MicroserviceInstance latestInstance = serviceCenterClient.getMicroserviceInstance(microserviceInstance.getServiceId(),
microserviceInstance.getInstanceId());
microserviceInstance.setStatus(latestInstance.getStatus());
return latestInstance;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is used to externally query the latest instance state, and when the warm-up function updates the instance state, only the instance state that is STARTING can be updated to UP.

Comment on lines 196 to 201
public MicroserviceInstanceStatus getStatus() {
return status;
}

public void setStatus(MicroserviceInstanceStatus status) {
this.status = status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add getStatus to MicroserviceInstance and force all implementations provide status information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the 'getMicroserviceInstanceStatus' method has been added to the MicroserviceInstance class.,as getStatus().

Comment on lines 235 to 245
public ZookeeperInstance getZookeeperInstance(){
try {
ServiceInstance<ZookeeperInstance> zkInstance = dis.queryForInstance(instance.getName(), instance.getId());
if (zkInstance != null){
return zkInstance.getPayload();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is used to externally query the latest instance state, and when the warm-up function updates the instance state, only the instance state that is STARTING can be updated to UP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,remove

Comment on lines 198 to 209
this.instance.getPayload().setStatus(status);
try {
if (status == MicroserviceInstanceStatus.UP){
dis.updateService(instance);
}
if (status == MicroserviceInstanceStatus.DOWN){
dis.registerService(instance);
}
} catch (Exception e){
throw new IllegalStateException(e);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use registerService when Down?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has been changed to updateService()

}else {
zookeeperInstance.setStatus(MicroserviceInstanceStatus.UP);
}
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use initialstatus, do not need isEnableElegantUpDown

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,have removed

microserviceInstance.getDataCenterInfo().getRegion(),
microserviceInstance.getDataCenterInfo().getAvailableZone());
org.apache.servicecomb.service.center.client.model.DataCenterInfo dataCenterInfo = microserviceInstance.getDataCenterInfo();
if (dataCenterInfo != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can init DataCenterInfo when init MicroserviceInstance, so that not need this modification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`t need it ,have removed, Setting the initial value on DataCenterProperties

public MicroserviceInstanceStatus getStatus() {
return instance.isEnabled() ? MicroserviceInstanceStatus.UP : MicroserviceInstanceStatus.DOWN;
if (instance.isEnabled()){
return MicroserviceInstanceStatus.valueOf(instance.getMetadata().get(NacosConst.NACOS_STATUS));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance.getMetadata().get(NacosConst.NACOS_STATUS maybe null for old versions instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version will definitely have status in metadata, so Returns up if status is not found in the old version in metadata.

Comment on lines 166 to 173
public String getInitialStatus() {
return initialStatus;
}

public void setInitialStatus(String initialStatus) {
this.initialStatus = initialStatus;
}
}
Copy link
Contributor

@liubao68 liubao68 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use common configration servicecomb.instance.initialStatus, see SC how to read it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nacos,ZK,ServiceCenter has used common configration servicecomb.instance.initialStatus

Comment on lines 136 to 149
if (MicroserviceInstanceStatus.UP == status){
instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.UP.name());
namingService.registerInstance(nacosRegistrationInstance.getServiceName(),
nacosRegistrationInstance.getApplication(), instance);
}
if (MicroserviceInstanceStatus.DOWN == status){
instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.DOWN.name());
namingService.deregisterInstance(nacosRegistrationInstance.getServiceName(),
nacosRegistrationInstance.getApplication(), instance);
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about update to other status? like TESTING?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, Instance status equal DOWN to exec 'deregisterInstance()' method, the other exec 'registerInstance()'

* This is the core service registration interface. <br/>
*/
public interface Registration<R extends RegistrationInstance> extends SPIEnabled, SPIOrder, LifeCycle {
public interface Registration<R extends MicroserviceInstance> extends SPIEnabled, SPIOrder, LifeCycle {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why made this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don`r need method 'getnitialStatus()' and 'getReadyStatus()'

return instance.isEnabled() ? MicroserviceInstanceStatus.UP : MicroserviceInstanceStatus.DOWN;
if (instance.isEnabled()) {
String instanceStatus = instance.getMetadata().get(NacosConst.NACOS_STATUS);
if (StringUtils.isBlank(instanceStatus)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be isEmpty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U said "instance.getMetadata().get(NacosConst.NACOS_STATUS maybe null for old versions instance." before,so i do it .

Comment on lines 136 to 148
if (MicroserviceInstanceStatus.DOWN == status) {
instance.getMetadata().put(NacosConst.NACOS_STATUS, MicroserviceInstanceStatus.DOWN.name());
namingService.deregisterInstance(nacosRegistrationInstance.getServiceName(),
nacosRegistrationInstance.getApplication(), instance);
} else {
instance.getMetadata().put(NacosConst.NACOS_STATUS, status.name());
namingService.registerInstance(nacosRegistrationInstance.getServiceName(),
nacosRegistrationInstance.getApplication(), instance);
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever status, update. No need to check status. Will registerInstance cause two instances? If Nacos do not support update status, maybe we can not use this feature for nacos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nacos register Instance again ,old instance will be covery. For Down, just deregister instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better only set status, do not deregister instance.

Comment on lines 79 to 81
return new DataCenterInfo(microserviceInstance.getDataCenterInfo().getName(),
microserviceInstance.getDataCenterInfo().getRegion(),
microserviceInstance.getDataCenterInfo().getAvailableZone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seams nothing changed, but format is wrong .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it`s changed

@liubao68 liubao68 merged commit 0668f63 into apache:master Jan 13, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants