Search in sources :

Example 6 with DiskNodeConnection

use of com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection in project BRFS by zhangnianli.

the class DefaultFileObjectSyncProcessor method getFileStateList.

private List<FileObjectSyncState> getFileStateList(FileNode fileNode) {
    List<FileObjectSyncState> fileStateList = new ArrayList<FileObjectSyncState>();
    for (DuplicateNode node : fileNode.getDuplicateNodes()) {
        DiskNodeConnection connection = connectionPool.getConnection(node.getGroup(), node.getId());
        if (connection == null || connection.getClient() == null) {
            LOG.error("duplication node[{}, {}] of [{}] is not available, that's maybe a trouble!", node.getGroup(), node.getId(), fileNode.getName());
            continue;
        }
        String filePath = pathMaker.buildPath(fileNode, node);
        LOG.info("checking---{}", filePath);
        long fileLength = connection.getClient().getFileLength(filePath);
        if (fileLength < 0) {
            LOG.error("duplication node[{}, {}] of [{}] can not get file length, that's maybe a trouble!", node.getGroup(), node.getId(), fileNode.getName());
            continue;
        }
        LOG.info("server{} -- {}", node.getId(), fileLength);
        fileStateList.add(new FileObjectSyncState(node.getGroup(), node.getId(), filePath, fileLength));
    }
    return fileStateList;
}
Also used : ArrayList(java.util.ArrayList) FileObjectSyncState(com.bonree.brfs.common.filesync.FileObjectSyncState) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 7 with DiskNodeConnection

use of com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection in project BRFS by zhangnianli.

the class DefaultFileObjectSyncProcessor method doSynchronize.

private boolean doSynchronize(FileNode fileNode, long correctLength, List<FileObjectSyncState> lacks, List<FileObjectSyncState> fulls) {
    List<String> fullStates = new ArrayList<String>();
    for (FileObjectSyncState state : fulls) {
        fullStates.add(SyncStateCodec.toString(state));
    }
    boolean allSynced = true;
    for (FileObjectSyncState state : lacks) {
        DiskNodeConnection connection = connectionPool.getConnection(state.getServiceGroup(), state.getServiceId());
        if (connection == null) {
            LOG.error("can not recover file[{}], because of lack of connection to service[{}, {}]", fileNode.getName(), state.getServiceGroup(), state.getServiceId());
            allSynced = false;
            continue;
        }
        DiskNodeClient client = connection.getClient();
        if (client == null) {
            allSynced = false;
            continue;
        }
        LOG.info("start synchronize file[{}] at data node[{}, {}]", fileNode.getName(), state.getServiceGroup(), state.getServiceId());
        if (!client.recover(state.getFilePath(), state.getFileLength(), fullStates)) {
            LOG.error("can not synchronize file[{}] at data node[{}, {}]", fileNode.getName(), state.getServiceGroup(), state.getServiceId());
            allSynced = false;
        }
    }
    return allSynced;
}
Also used : DiskNodeClient(com.bonree.brfs.disknode.client.DiskNodeClient) ArrayList(java.util.ArrayList) FileObjectSyncState(com.bonree.brfs.common.filesync.FileObjectSyncState) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 8 with DiskNodeConnection

use of com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection 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)

Aggregations

DiskNodeConnection (com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)8 DuplicateNode (com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)5 ArrayList (java.util.ArrayList)5 Service (com.bonree.brfs.common.service.Service)3 FileObjectSyncState (com.bonree.brfs.common.filesync.FileObjectSyncState)2 ResourceModel (com.bonree.brfs.resourceschedule.model.ResourceModel)2 ExecutorService (java.util.concurrent.ExecutorService)2 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)1 FileNode (com.bonree.brfs.duplication.filenode.FileNode)1 EmailPool (com.bonree.brfs.email.EmailPool)1 MailWorker (com.bonree.mail.worker.MailWorker)1 HashMap (java.util.HashMap)1