Search in sources :

Example 6 with DistroKey

use of com.alibaba.nacos.core.distributed.distro.entity.DistroKey in project nacos by alibaba.

the class DistroDataStorageImpl method getDatumSnapshot.

@Override
public DistroData getDatumSnapshot() {
    Map<String, Datum> result = dataStore.getDataMap();
    byte[] dataContent = ApplicationUtils.getBean(Serializer.class).serialize(result);
    DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_SNAPSHOT, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
    return new DistroData(distroKey, dataContent);
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 7 with DistroKey

use of com.alibaba.nacos.core.distributed.distro.entity.DistroKey in project nacos by alibaba.

the class DistroDataStorageImpl method getVerifyData.

@Override
public List<DistroData> getVerifyData() {
    // If upgrade to 2.0.X, do not verify for v1.
    if (ApplicationUtils.getBean(UpgradeJudgement.class).isUseGrpcFeatures()) {
        return Collections.emptyList();
    }
    Map<String, String> keyChecksums = new HashMap<>(64);
    for (String key : dataStore.keys()) {
        if (!distroMapper.responsible(KeyBuilder.getServiceName(key))) {
            continue;
        }
        Datum datum = dataStore.get(key);
        if (datum == null) {
            continue;
        }
        keyChecksums.put(key, datum.value.getChecksum());
    }
    if (keyChecksums.isEmpty()) {
        return Collections.emptyList();
    }
    DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_CHECKSUM, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
    DistroData data = new DistroData(distroKey, ApplicationUtils.getBean(Serializer.class).serialize(keyChecksums));
    data.setType(DataOperation.VERIFY);
    return Collections.singletonList(data);
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) HashMap(java.util.HashMap) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) UpgradeJudgement(com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 8 with DistroKey

use of com.alibaba.nacos.core.distributed.distro.entity.DistroKey in project nacos by alibaba.

the class DistroClientDataProcessor method getDatumSnapshot.

@Override
public DistroData getDatumSnapshot() {
    List<ClientSyncData> datum = new LinkedList<>();
    for (String each : clientManager.allClientId()) {
        Client client = clientManager.getClient(each);
        if (null == client || !client.isEphemeral()) {
            continue;
        }
        datum.add(client.generateSyncData());
    }
    ClientSyncDatumSnapshot snapshot = new ClientSyncDatumSnapshot();
    snapshot.setClientSyncDataList(datum);
    byte[] data = ApplicationUtils.getBean(Serializer.class).serialize(snapshot);
    return new DistroData(new DistroKey(DataOperation.SNAPSHOT.name(), TYPE), data);
}
Also used : ClientSyncData(com.alibaba.nacos.naming.core.v2.client.ClientSyncData) ClientSyncDatumSnapshot(com.alibaba.nacos.naming.core.v2.client.ClientSyncDatumSnapshot) Client(com.alibaba.nacos.naming.core.v2.client.Client) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) LinkedList(java.util.LinkedList) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 9 with DistroKey

use of com.alibaba.nacos.core.distributed.distro.entity.DistroKey in project nacos by alibaba.

the class DistroClientDataProcessor method getVerifyData.

@Override
public List<DistroData> getVerifyData() {
    List<DistroData> result = new LinkedList<>();
    for (String each : clientManager.allClientId()) {
        Client client = clientManager.getClient(each);
        if (null == client || !client.isEphemeral()) {
            continue;
        }
        if (clientManager.isResponsibleClient(client)) {
            // TODO add revision for client.
            DistroClientVerifyInfo verifyData = new DistroClientVerifyInfo(client.getClientId(), 0);
            DistroKey distroKey = new DistroKey(client.getClientId(), TYPE);
            DistroData data = new DistroData(distroKey, ApplicationUtils.getBean(Serializer.class).serialize(verifyData));
            data.setType(DataOperation.VERIFY);
            result.add(data);
        }
    }
    return result;
}
Also used : Client(com.alibaba.nacos.naming.core.v2.client.Client) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) LinkedList(java.util.LinkedList) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 10 with DistroKey

use of com.alibaba.nacos.core.distributed.distro.entity.DistroKey in project nacos by alibaba.

the class DistroConsistencyServiceImpl method put.

@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, DistroConfig.getInstance().getSyncDelayMillis());
}
Also used : DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) UpgradeJudgement(com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement)

Aggregations

DistroKey (com.alibaba.nacos.core.distributed.distro.entity.DistroKey)16 DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)5 Datum (com.alibaba.nacos.naming.consistency.Datum)4 Client (com.alibaba.nacos.naming.core.v2.client.Client)4 DistroDelayTask (com.alibaba.nacos.core.distributed.distro.task.delay.DistroDelayTask)3 BaseTest (com.alibaba.nacos.naming.BaseTest)2 Serializer (com.alibaba.nacos.naming.cluster.transport.Serializer)2 UpgradeJudgement (com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 DistroSyncChangeTask (com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncChangeTask)1 DistroSyncDeleteTask (com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncDeleteTask)1 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)1 ClientSyncData (com.alibaba.nacos.naming.core.v2.client.ClientSyncData)1 ClientSyncDatumSnapshot (com.alibaba.nacos.naming.core.v2.client.ClientSyncDatumSnapshot)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1 HashMap (java.util.HashMap)1