Search in sources :

Example 1 with ServiceChangeV1Task

use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task in project nacos by alibaba.

the class AsyncServicesCheckTask method deleteV2Service.

private void deleteV2Service(com.alibaba.nacos.naming.core.v2.pojo.Service serviceV2) {
    if (upgradeJudgement.isUseGrpcFeatures()) {
        return;
    }
    String namespace = serviceV2.getNamespace();
    String serviceName = serviceV2.getGroupedServiceName();
    boolean ephemeral = serviceV2.isEphemeral();
    String key = ServiceChangeV1Task.getKey(namespace, serviceName, ephemeral);
    ServiceChangeV1Task task = new ServiceChangeV1Task(namespace, serviceName, ephemeral, DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
    doubleWriteDelayTaskEngine.addTask(key, task);
}
Also used : ServiceChangeV1Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task)

Example 2 with ServiceChangeV1Task

use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task in project nacos by alibaba.

the class AsyncServicesCheckTask method checkService.

private void checkService(String namespace, String fullServiceName, Service serviceV1, ServiceStorage serviceStorage) {
    if (upgradeJudgement.isUseGrpcFeatures()) {
        return;
    }
    String groupName = NamingUtils.getGroupName(serviceV1.getName());
    String serviceName = NamingUtils.getServiceName(fullServiceName);
    com.alibaba.nacos.naming.core.v2.pojo.Service serviceV2 = com.alibaba.nacos.naming.core.v2.pojo.Service.newService(namespace, groupName, serviceName);
    ServiceInfo serviceInfo = serviceStorage.getData(serviceV2);
    if (serviceV1.allIPs().size() != serviceInfo.getHosts().size()) {
        boolean isEphemeral = serviceV1.allIPs(false).isEmpty();
        String key = ServiceChangeV1Task.getKey(namespace, fullServiceName, isEphemeral);
        ServiceChangeV1Task task = new ServiceChangeV1Task(namespace, fullServiceName, isEphemeral, DoubleWriteContent.INSTANCE);
        doubleWriteDelayTaskEngine.addTask(key, task);
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceChangeV1Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task)

Example 3 with ServiceChangeV1Task

use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task in project nacos by alibaba.

the class DoubleWriteServiceRemovalToV2Task method run.

@Override
public void run() {
    try {
        InstanceOperatorClientImpl instanceOperator = ApplicationUtils.getBean(InstanceOperatorClientImpl.class);
        ClientServiceIndexesManager clientServiceIndexesManager = ApplicationUtils.getBean(ClientServiceIndexesManager.class);
        ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
        ServiceInfo serviceInfo = serviceStorage.getPushData(service);
        for (Instance instance : serviceInfo.getHosts()) {
            instanceOperator.removeInstance(service.getNamespace(), service.getName(), instance);
        }
        int count = 0;
        while (!clientServiceIndexesManager.getAllClientsRegisteredService(service).isEmpty() && count < MAX_WAIT_TIMES) {
            TimeUnit.MILLISECONDS.sleep(100);
            count += 1;
        }
        clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
        ServiceManager.getInstance().removeSingleton(service);
        serviceStorage.removeData(service);
        NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, true));
    } catch (Exception e) {
        if (Loggers.SRV_LOG.isDebugEnabled()) {
            Loggers.SRV_LOG.debug("Double write removal of {} from 1 to 2 failed", service, e);
        }
        ServiceChangeV1Task retryTask = new ServiceChangeV1Task(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral(), DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
        retryTask.setTaskInterval(INTERVAL);
        String taskKey = ServiceChangeV1Task.getKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
        ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceStorage(com.alibaba.nacos.naming.core.v2.index.ServiceStorage) Instance(com.alibaba.nacos.api.naming.pojo.Instance) MetadataEvent(com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent) ClientServiceIndexesManager(com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager) ServiceChangeV1Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task) InstanceOperatorClientImpl(com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)

Aggregations

ServiceChangeV1Task (com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 InstanceOperatorClientImpl (com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)1 MetadataEvent (com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent)1 ClientServiceIndexesManager (com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager)1 ServiceStorage (com.alibaba.nacos.naming.core.v2.index.ServiceStorage)1