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