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;
}
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;
}
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);
}
Aggregations