Search in sources :

Example 1 with StorageRegion

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;
    }
}
Also used : StorageNameExistException(com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameExistException(com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException) StorageNameRemoveException(com.bonree.brfs.duplication.storageregion.exception.StorageNameRemoveException) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 2 with StorageRegion

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));
    }
}
Also used : StorageRegionConfig(com.bonree.brfs.duplication.storageregion.StorageRegionConfig) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 3 with StorageRegion

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);
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) Service(com.bonree.brfs.common.service.Service) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)

Example 4 with StorageRegion

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;
}
Also used : StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 5 with StorageRegion

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);
}
Also used : Entry(java.util.Map.Entry) ServerChangeListener(com.bonree.brfs.rebalance.task.listener.ServerChangeListener) TaskStatusListener(com.bonree.brfs.rebalance.task.listener.TaskStatusListener) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException)

Aggregations

StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)30 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)8 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HandleResult (com.bonree.brfs.common.net.http.HandleResult)5 Service (com.bonree.brfs.common.service.Service)5 ServiceManager (com.bonree.brfs.common.service.ServiceManager)5 Pair (com.bonree.brfs.common.utils.Pair)4 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)4 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashedMap (org.apache.commons.collections.map.HashedMap)4 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)3 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)3 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)3 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)3 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)3 IOException (java.io.IOException)3 JobDataMap (org.quartz.JobDataMap)3