Search in sources :

Example 6 with DuplicateNode

use of com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode in project BRFS by zhangnianli.

the class MinimalDuplicateNodeSelector method getDuplicationNodes.

@Override
public DuplicateNode[] getDuplicationNodes(int storageId, int nums) {
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (serviceList.isEmpty()) {
        return new DuplicateNode[0];
    }
    List<DuplicateNode> nodes = new ArrayList<DuplicateNode>();
    while (!serviceList.isEmpty() && nodes.size() < nums) {
        Service service = serviceList.remove(rand.nextInt(serviceList.size()));
        DuplicateNode node = new DuplicateNode(service.getServiceGroup(), service.getServiceId());
        DiskNodeConnection conn = connectionPool.getConnection(node.getGroup(), node.getId());
        if (conn == null || conn.getClient() == null || !conn.getClient().ping()) {
            continue;
        }
        nodes.add(node);
    }
    DuplicateNode[] result = new DuplicateNode[nodes.size()];
    return nodes.toArray(result);
}
Also used : ArrayList(java.util.ArrayList) Service(com.bonree.brfs.common.service.Service) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 7 with DuplicateNode

use of com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode in project BRFS by zhangnianli.

the class ResourceWriteSelector method getDuplicationNodes.

@Override
public DuplicateNode[] getDuplicationNodes(int storageId, int nums) {
    long start = System.currentTimeMillis();
    DuplicateNode[] duplicateNodes;
    try {
        StorageRegion sr = this.storageRegionManager.findStorageRegionById(storageId);
        String srName = sr.getName();
        if (sr == null) {
            LOG.error("srid : {} is not exist !!!", storageId);
            return new DuplicateNode[0];
        }
        // 获取资源信息
        Collection<ResourceModel> resources = daemon.getClusterResources();
        // 采集资源未上传则使用备用选择器
        if (resources == null || resources.isEmpty()) {
            LOG.warn("[{}] select resource list is empty !!!! use bak selector", groupName);
            return this.bakSelector.getDuplicationNodes(storageId, nums);
        }
        // 过滤资源异常服务
        Collection<ResourceModel> selectors = this.resourceSelector.filterService(resources, srName);
        if (selectors == null || selectors.isEmpty()) {
            LOG.error("[{}] none avaible server to selector !!!", groupName);
            return new DuplicateNode[0];
        }
        // 按策略获取服务
        Collection<ResourceModel> wins = this.resourceSelector.selector(selectors, srName, nums);
        if (wins == null || wins.isEmpty()) {
            LOG.error("[{}] no service can write !!!", groupName);
            return new DuplicateNode[0];
        }
        if (wins.size() != nums) {
            LOG.warn("[{}] service can write !!!need {} but give {} ", groupName, nums, wins.size());
        }
        duplicateNodes = new DuplicateNode[wins.size()];
        Iterator<ResourceModel> iterator = wins.iterator();
        int i = 0;
        StringBuilder sBuild = new StringBuilder();
        sBuild.append("select service -> ");
        ResourceModel next;
        while (iterator.hasNext()) {
            next = iterator.next();
            duplicateNodes[i] = new DuplicateNode(groupName, next.getServerId());
            i++;
            sBuild.append(i).append(":").append(next.getServerId()).append("(").append(next.getHost()).append(", remainSize").append(next.getLocalRemainSizeValue(srName)).append("b ), ");
        }
        LOG.info("{}", sBuild.toString());
        return duplicateNodes;
    } finally {
        long stop = System.currentTimeMillis();
        LOG.info("resource select node time: {} ms", (stop - start));
    }
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 8 with DuplicateNode

use of com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode in project BRFS by zhangnianli.

the class FileNameBuilder method createFile.

public static String createFile(ServerIDManager idManager, StorageRegion storageRegion, DuplicateNode[] duplicateNodes) {
    StringBuilder builder = new StringBuilder();
    builder.append(UUID.randomUUID().toString().replaceAll("-", ""));
    List<String> ids = new ArrayList<String>();
    for (DuplicateNode node : duplicateNodes) {
        ids.add(node.getId());
        builder.append('_').append(idManager.getOtherSecondID(node.getId(), storageRegion.getId()));
    }
    int virtualIdCount = storageRegion.getReplicateNum() - duplicateNodes.length;
    if (virtualIdCount > 0) {
        for (String virtualId : idManager.getVirtualServerID(storageRegion.getId(), virtualIdCount, ids)) {
            LOG.info("get virtual id---{}", virtualId);
            builder.append('_').append(virtualId);
        }
    }
    return builder.toString();
}
Also used : ArrayList(java.util.ArrayList) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)

Aggregations

DuplicateNode (com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)8 ArrayList (java.util.ArrayList)6 DiskNodeConnection (com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)5 Service (com.bonree.brfs.common.service.Service)3 FileObjectSyncState (com.bonree.brfs.common.filesync.FileObjectSyncState)2 ExecutorService (java.util.concurrent.ExecutorService)2 FileObject (com.bonree.brfs.duplication.datastream.file.FileObject)1 FileNode (com.bonree.brfs.duplication.filenode.FileNode)1 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 ResourceModel (com.bonree.brfs.resourceschedule.model.ResourceModel)1 HashMap (java.util.HashMap)1