• nacos源码分析


    D: ewWorkSpace acos-2.0.0-bugfix amingsrcmainjavacomalibaba acos amingconsistencyephemeraldistroDistroConsistencyServiceImpl.java


    /**

    *一种称为Distro的一致性协议算法

    *<p>使用distro算法将数据划分为多个块。每个Nacos服务器节点负责

    *一块数据。每个数据块都由其负责的服务器生成、删除和同步。所以每

    *Nacos服务器只处理总服务数据的一个子集的写入。

    *同时每个Nacos服务器都接收到其他Nacos服务器的数据同步,所以每个Nacos服务器最终都会有一套完整的数据。

    */

    @Override
    public void put(String key, Record value) throws NacosException {
    onPut(key, value);
    // If upgrade to 2.0.X, do not sync for v1.
    if (ApplicationUtils.getBean(UpgradeJudgement.class).isUseGrpcFeatures()) {
    return;
    }
    distroProtocol.sync(new DistroKey(key, KeyBuilder.INSTANCE_LIST_KEY_PREFIX), DataOperation.CHANGE,
    globalConfig.getTaskDispatchPeriod() / 2);
    }


    D: ewWorkSpace acos-2.0.0-bugfixcoresrcmainjavacomalibaba acoscoredistributeddistroDistroProtocol.java
    /**
    * Start to sync data to all remote server.
    * 开始将数据同步到所有远程服务器
    * @param distroKey distro key of sync data
    * @param action the action of data operation
    * @param delay delay time for sync
    */
    public void sync(DistroKey distroKey, DataOperation action, long delay) {
    for (Member each : memberManager.allMembersWithoutSelf()) {
    syncToTarget(distroKey, action, each.getAddress(), delay);
    }
    }

    服务注册

    D: ewWorkSpace acos-2.0.0-bugfix amingsrcmainjavacomalibaba acos amingcorev2upgradedoublewriteexecuteDoubleWriteInstanceChangeToV2Task.java
    instanceOperator.registerInstance(namespace, serviceName, instance);
    D: ewWorkSpace acos-2.0.0-bugfix amingsrcmainjavacomalibaba acos amingcoreInstanceOperatorClientImpl.java
    /**
    * This method creates {@code IpPortBasedClient} if it don't exist.
    */
    @Override
    public void registerInstance(String namespaceId, String serviceName, Instance instance) {
    boolean ephemeral = instance.isEphemeral();//Ephemeral 短暂的,临时的
    String clientId = IpPortBasedClient.getClientId(instance.toInetAddr(), ephemeral);
    createIpPortClientIfAbsent(clientId, ephemeral);
    Service service = getService(namespaceId, serviceName, ephemeral);
    clientOperationService.registerInstance(service, instance, clientId);
    }
    D: ewWorkSpace acos-2.0.0-bugfix amingsrcmainjavacomalibaba acos amingcorev2serviceimplEphemeralClientOperationServiceImpl.java
    @Override
    public void registerInstance(Service service, Instance instance, String clientId) {
    Service singleton = ServiceManager.getInstance().getSingleton(service);
    Client client = clientManager.getClient(clientId);
    InstancePublishInfo instanceInfo = getPublishInfo(instance);
    client.addServiceInstance(singleton, instanceInfo);
    client.setLastUpdatedTime();
    NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, clientId));
    NotifyCenter
    .publishEvent(new MetadataEvent.InstanceMetadataEvent(singleton, instanceInfo.getMetadataId(), false));
    }


    D: ewWorkSpace acos-2.0.0-bugfix amingsrcmainjavacomalibaba acos amingcoreServiceManager.java

  • 相关阅读:
    MRO C3算法 super的运用
    约束 抛异常
    反射
    Ubuntu
    Vim
    Vim
    Arithmetic
    Docker-常用命令
    Docker
    Docker-LAMP开发环境
  • 原文地址:https://www.cnblogs.com/wueryuan/p/14931208.html
Copyright © 2020-2023  润新知