use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class DefaultStorageRegionManager method createStorageRegion.
@Override
public StorageRegion createStorageRegion(String regionName, StorageRegionConfig config) throws Exception {
if (exists(regionName)) {
throw new StorageNameExistException(regionName);
}
String regionPath = buildRegionPath(regionName);
try {
StorageRegion region = StorageRegion.newBuilder().setName(regionName).setId(idBuilder.createRegionId()).setCreateTime(System.currentTimeMillis()).setEnable(true).setReplicateNum(config.getReplicateNum()).setDataTtl(config.getDataTtl()).setFileCapacity(config.getFileCapacity()).setFilePartitionDuration(config.getFilePartitionDuration()).build();
zkClient.create().forPath(regionPath, JsonUtils.toJsonBytes(region));
return region;
} catch (NodeExistsException e) {
throw new StorageNameExistException(regionName);
} catch (Exception e) {
LOG.error("create storage name node error", e);
throw e;
}
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class CreateStorageRegionMessageHandler method handleMessage.
@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
LOG.info("create storage region[{}] with attrs {}", msg.getName(), msg.getAttributes());
try {
StorageRegionConfig config = new StorageRegionConfig();
config.update(msg.getAttributes());
StorageRegion node = storageRegionManager.createStorageRegion(msg.getName(), config);
LOG.info("created region[{}]", node);
callback.completed(new HandleResult(true));
} catch (Exception e) {
callback.completed(new HandleResult(false));
}
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class DeleteStorageRegionMessageHandler method handleMessage.
@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
StorageRegion region = storageRegionManager.findStorageRegionByName(msg.getName());
if (region == null) {
callback.completed(new HandleResult(false));
return;
}
boolean deleted;
HandleResult result = new HandleResult();
try {
List<Service> services = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
if (region.isEnable()) {
result.setSuccess(false);
result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
callback.completed(result);
return;
}
ReturnCode code = TasksUtils.createUserDeleteTask(services, zkPaths, region, region.getCreateTime(), System.currentTimeMillis(), true);
if (!ReturnCode.SUCCESS.equals(code)) {
result.setSuccess(false);
result.setData(BrStringUtils.toUtf8Bytes(code.name()));
} else {
deleted = storageRegionManager.removeStorageRegion(msg.getName());
result.setSuccess(deleted);
if (deleted) {
LOG.info("clean all data for " + msg.getName());
} else {
result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
}
}
} catch (StorageNameNonexistentException e) {
result.setSuccess(false);
result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_NONEXIST_ERROR.name()));
} catch (Exception e) {
result.setSuccess(false);
result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
}
callback.completed(result);
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class TaskStateLifeContral method getSRs.
/**
* 概述:转换
* @param srm
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static List<String> getSRs(StorageRegionManager srm) {
List<StorageRegion> srList = srm.getStorageRegionList();
List<String> srs = new ArrayList<>();
if (srList == null || srList.isEmpty()) {
return srs;
}
String srName;
for (StorageRegion sr : srList) {
srName = sr.getName();
if (BrStringUtils.isEmpty(srName)) {
continue;
}
srs.add(srName);
}
return srs;
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class TaskDispatcher method start.
public void start() throws Exception {
LOG.info("begin leaderLath server!");
leaderLath.start();
LOG.info("changeMonitorPath:" + changesPath);
treeCache.addListener(changesPath, new ServerChangeListener(this));
LOG.info("tasksPath:" + tasksPath);
treeCache.addListener(tasksPath, new TaskStatusListener(this));
singleServer.execute(new Runnable() {
@Override
public void run() {
try {
dealChangeSDetail();
} catch (InterruptedException e) {
LOG.error("consumer queue error!!", e);
e.printStackTrace();
}
}
});
scheduleExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if (leaderLath.hasLeadership()) {
if (isLoad.get()) {
LOG.info("auditTask timer cacheSummaryCache:" + cacheSummaryCache);
for (Entry<Integer, List<ChangeSummary>> entry : cacheSummaryCache.entrySet()) {
StorageRegion sn = snManager.findStorageRegionById(entry.getKey());
// 因为sn可能会被删除
if (sn != null) {
syncAuditTask(entry.getKey(), entry.getValue());
}
}
} else {
LOG.info("load once cache!");
loadCache();
isLoad.set(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, 3000, 3000, TimeUnit.MILLISECONDS);
}
Aggregations