use of com.bonree.brfs.duplication.storageregion.StorageRegion 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.storageregion.StorageRegion in project BRFS by zhangnianli.
the class DeleteDataMessageHandler method handle.
@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
HandleResult result = new HandleResult();
List<String> deleteInfo = Splitter.on("/").omitEmptyStrings().trimResults().splitToList(msg.getPath());
if (deleteInfo.size() != 2) {
result.setSuccess(false);
result.setCause(new IllegalArgumentException(msg.getPath()));
callback.completed(result);
return;
}
int storageId = Integer.parseInt(deleteInfo.get(0));
LOG.info("DELETE data for storage[{}]", storageId);
StorageRegion sn = storageNameManager.findStorageRegionById(storageId);
if (sn == null) {
result.setSuccess(false);
result.setCause(new StorageNameNonexistentException(storageId));
callback.completed(result);
LOG.info("storage[{}] is null", storageId);
return;
}
List<String> times = Splitter.on("_").omitEmptyStrings().trimResults().splitToList(deleteInfo.get(1));
ReturnCode code = checkTime(times.get(0), times.get(1), sn.getCreateTime(), Duration.parse(sn.getFilePartitionDuration()).toMillis());
if (!ReturnCode.SUCCESS.equals(code)) {
result.setSuccess(false);
result.setData(BrStringUtils.toUtf8Bytes(code.name()));
callback.completed(result);
LOG.info("DELETE DATE Fail storage[{}] reason : {}", storageId, code.name());
return;
}
long startTime = DateTime.parse(times.get(0)).getMillis();
long endTime = DateTime.parse(times.get(1)).getMillis();
LOG.info("DELETE DATA [{}-->{}]", times.get(0), times.get(1));
List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
code = TasksUtils.createUserDeleteTask(serviceList, zkPaths, sn, startTime, endTime, false);
result.setSuccess(ReturnCode.SUCCESS.equals(code));
result.setData(BrStringUtils.toUtf8Bytes(code.name()));
callback.completed(result);
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class CheckCycleJob method collectionTimes.
/**
* 概述:生成sn时间
* @param needSns
* @param startTime
* @param endTime
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public Map<String, List<Long>> collectionTimes(List<StorageRegion> needSns, final long startTime, final long endTime) {
if (needSns == null || needSns.isEmpty()) {
return null;
}
Map<String, List<Long>> snTimes = new HashMap<>();
List<Long> times;
long cTime;
long granule;
String snName;
for (StorageRegion sn : needSns) {
snName = sn.getName();
cTime = sn.getCreateTime();
granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
times = new ArrayList<>();
for (long start = startTime; start < endTime; start += granule) {
if (start < cTime) {
continue;
}
times.add(start);
}
if (times == null || times.isEmpty()) {
continue;
}
if (!snTimes.containsKey(snName)) {
snTimes.put(snName, times);
}
}
return snTimes;
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class CheckCycleJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
LOG.info("cycle check job work !!!");
JobDataMap data = context.getJobDetail().getJobDataMap();
int day = data.getInt(JobDataMapConstract.CHECK_TIME_RANGE);
if (day <= 0) {
LOG.warn("skip cycle job!! because check time range is 0");
return;
}
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
StorageRegionManager snm = mcf.getSnm();
ServiceManager sm = mcf.getSm();
if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
LOG.warn("rebalance task is running !! skip check copy task ,wait next time to check");
return;
}
List services = sm.getServiceListByGroup(mcf.getGroupName());
if ((services == null) || (services.isEmpty())) {
LOG.warn("SKIP create {} task, because service is empty", TaskType.SYSTEM_COPY_CHECK);
return;
}
List<StorageRegion> snList = snm.getStorageRegionList();
if ((snList == null) || (snList.isEmpty())) {
LOG.warn("SKIP storagename list is null");
return;
}
long currentTime = System.currentTimeMillis();
long lGraDay = currentTime - currentTime % 86400000L;
long sGraDay = lGraDay - day * 86400000L;
List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
if (needSns == null || needSns.isEmpty()) {
LOG.warn("no storagename need check copy count ! ");
return;
}
Map<String, List<Long>> snTimes = collectionTimes(needSns, sGraDay, lGraDay);
if (snTimes == null || snTimes.isEmpty()) {
LOG.warn("{} - {} time, no data to check copy count", TimeUtils.formatTimeStamp(sGraDay), TimeUtils.formatTimeStamp(lGraDay));
return;
}
List<Map<String, Long>> tTimes = converTimes(snTimes);
for (Map<String, Long> sourceTimes : tTimes) {
if (sourceTimes == null || sourceTimes.isEmpty()) {
continue;
}
createSingleTask(release, needSns, services, TaskType.SYSTEM_COPY_CHECK, sourceTimes);
}
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class CreateSystemTaskJob method operation.
@Override
public void operation(JobExecutionContext context) {
LOG.info("create system task working");
// 判断是否有恢复任务,有恢复任务则不进行创建
JobDataMap data = context.getJobDetail().getJobDataMap();
long checkTtl = data.getLong(JobDataMapConstract.CHECK_TTL);
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
// 获取开启的任务名称
List<TaskType> switchList = mcf.getTaskOn();
if (switchList == null || switchList.isEmpty()) {
LOG.warn("switch on task is empty !!!");
return;
}
// 获取可用服务
String groupName = mcf.getGroupName();
ServiceManager sm = mcf.getSm();
// 2.设置可用服务
List<String> serverIds = CreateSystemTask.getServerIds(sm, groupName);
if (serverIds == null || serverIds.isEmpty()) {
LOG.warn("{} available server list is null", groupName);
return;
}
// 3.获取storageName
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> snList = snm.getStorageRegionList();
if (snList == null || snList.isEmpty()) {
LOG.info("skip create system task !!! because storageName is null !!!");
return;
}
TaskModel task;
String taskName;
TaskTypeModel tmodel;
long ttl = 0;
Pair<TaskModel, TaskTypeModel> result;
List<String> srs = TaskStateLifeContral.getSRs(snm);
for (TaskType taskType : switchList) {
if (TaskType.SYSTEM_COPY_CHECK.equals(taskType) || TaskType.USER_DELETE.equals(taskType)) {
continue;
}
TaskStateLifeContral.watchSR(release, srs, taskType.name());
if (TaskType.SYSTEM_DELETE.equals(taskType)) {
ttl = 0;
} else if (TaskType.SYSTEM_CHECK.equals(taskType)) {
ttl = checkTtl;
}
tmodel = release.getTaskTypeInfo(taskType.name());
if (tmodel == null) {
tmodel = new TaskTypeModel();
tmodel.setSwitchFlag(true);
LOG.warn("taskType{} is switch but metadata is null");
}
result = CreateSystemTask.createSystemTask(tmodel, taskType, snList, ttl);
if (result == null) {
LOG.warn("create sys task is empty {}", taskType.name());
continue;
}
task = result.getFirst();
taskName = CreateSystemTask.updateTask(release, task, serverIds, taskType);
if (!BrStringUtils.isEmpty(taskName)) {
LOG.info("create {} {} task successfull !!!", taskType.name(), taskName);
release.setTaskTypeModel(taskType.name(), tmodel);
}
}
}
Aggregations