Search in sources :

Example 1 with FileObject

use of com.bonree.brfs.duplication.datastream.file.FileObject in project BRFS by zhangnianli.

the class DefaultFileObjectSyncProcessor method process.

@Override
public boolean process(FileObjectSyncTask task) {
    FileObject file = task.file();
    LOG.info("start to synchronize file[{}]", file.node().getName());
    DuplicateNode[] nodeList = file.node().getDuplicateNodes();
    boolean syncAccomplished = true;
    List<FileObjectSyncState> fileStateList = getFileStateList(file.node());
    if (fileStateList.isEmpty()) {
        // 文件所在的所有磁盘节点都处于异常状态
        LOG.error("No available duplicate node is found to sync file[{}]", file.node().getName());
        if (task.isExpired()) {
            task.callback().timeout(file);
            return true;
        }
        return false;
    }
    if (fileStateList.size() != nodeList.length) {
        // 文件所在的所有磁盘节点中有部分不可用,这种情况先同步可用的磁盘节点信息
        LOG.warn("Not all duplicate nodes are available to sync file[{}]", file.node().getName());
        syncAccomplished = false;
    }
    long maxLength = -1;
    for (FileObjectSyncState state : fileStateList) {
        maxLength = Math.max(maxLength, state.getFileLength());
    }
    List<FileObjectSyncState> lack = new ArrayList<FileObjectSyncState>();
    List<FileObjectSyncState> full = new ArrayList<FileObjectSyncState>();
    for (FileObjectSyncState state : fileStateList) {
        if (state.getFileLength() != maxLength) {
            lack.add(state);
        } else {
            full.add(state);
        }
    }
    if (lack.isEmpty()) {
        if (syncAccomplished) {
            LOG.info("file[{}] is ok!", file.node().getName());
            task.callback().complete(file, maxLength);
            return true;
        } else {
            LOG.info("file[{}] is lack of some duplicate node!", file.node().getName());
            if (task.isExpired()) {
                LOG.info("file[{}] sync is expired!", file.node().getName());
                task.callback().timeout(file);
                return true;
            }
            return false;
        }
    } else {
        syncAccomplished &= doSynchronize(file.node(), maxLength, lack, full);
        if (syncAccomplished) {
            LOG.info("file[{}] sync is completed!", file.node().getName());
            task.callback().complete(file, maxLength);
            return true;
        } else {
            LOG.info("file[{}] sync is failed!", file.node().getName());
            if (task.isExpired()) {
                LOG.info("file[{}] sync is expired!", file.node().getName());
                task.callback().timeout(file);
                return true;
            }
            return false;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FileObjectSyncState(com.bonree.brfs.common.filesync.FileObjectSyncState) FileObject(com.bonree.brfs.duplication.datastream.file.FileObject) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)

Aggregations

FileObjectSyncState (com.bonree.brfs.common.filesync.FileObjectSyncState)1 FileObject (com.bonree.brfs.duplication.datastream.file.FileObject)1 DuplicateNode (com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)1 ArrayList (java.util.ArrayList)1