Search in sources :

Example 6 with StorageRegion

use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.

the class TaskOperation method launchDelayTaskExecutor.

public void launchDelayTaskExecutor(BalanceTaskSummary taskSummary, String taskPath) {
    DataRecover recover = null;
    List<String> multiIds = taskSummary.getOutputServers();
    if (multiIds.contains(idManager.getSecondServerID(taskSummary.getStorageIndex()))) {
        // 注册自身的selfMultiId,并设置为created阶段
        if (taskSummary.getTaskType() == RecoverType.NORMAL) {
            // 正常迁移任务
            StorageRegion node = snManager.findStorageRegionById(taskSummary.getStorageIndex());
            if (node == null) {
                LOG.error("无法开启对" + taskSummary.getStorageIndex() + "的任务");
                return;
            }
            String storageName = snManager.findStorageRegionById(taskSummary.getStorageIndex()).getName();
            recover = new MultiRecover(taskSummary, idManager, serviceManager, taskPath, client, dataDir, storageName, baseRoutesPath);
        } else if (taskSummary.getTaskType() == RecoverType.VIRTUAL) {
            // 虚拟迁移任务
            StorageRegion node = snManager.findStorageRegionById(taskSummary.getStorageIndex());
            if (node == null) {
                LOG.error("无法开启对" + taskSummary.getStorageIndex() + "的任务");
                return;
            }
            String storageName = snManager.findStorageRegionById(taskSummary.getStorageIndex()).getName();
            recover = new VirtualRecover(client, taskSummary, taskPath, dataDir, storageName, idManager, serviceManager);
        }
        updateTaskStatus(taskSummary, TaskStatus.RUNNING);
        launchTask(recover);
    }
}
Also used : VirtualRecover(com.bonree.brfs.rebalance.recover.VirtualRecover) MultiRecover(com.bonree.brfs.rebalance.recover.MultiRecover) DataRecover(com.bonree.brfs.rebalance.DataRecover) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 7 with StorageRegion

use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.

the class CopyCheckJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.info("createCheck Copy Job working");
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    StorageRegionManager snm = mcf.getSnm();
    ServiceManager sm = mcf.getSm();
    List<String> srs = TaskStateLifeContral.getSRs(snm);
    TaskStateLifeContral.watchSR(release, srs, TaskType.SYSTEM_COPY_CHECK.name());
    // 判断是否有恢复任务,有恢复任务则不进行创建
    if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
        LOG.warn("rebalance task is running !! skip check copy task");
        return;
    }
    String taskType = TaskType.SYSTEM_COPY_CHECK.name();
    List<Service> services = sm.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (services == null || services.isEmpty()) {
        LOG.warn("skip create {} task, because service is empty", taskType);
        return;
    }
    List<StorageRegion> snList = snm.getStorageRegionList();
    if (snList == null || snList.isEmpty()) {
        LOG.warn("storagename list is null");
        return;
    }
    // 1.获取sn创建任务的实际那
    TaskTypeModel tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        release.setTaskTypeModel(taskType, tmodel);
    }
    Map<String, Long> sourceTimes = tmodel.getSnTimes();
    LOG.debug("update init sn time :{}", sourceTimes);
    // 2.过滤不符合副本校验的sn信息
    List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
    // 3.针对第一次出现的sn补充时间
    sourceTimes = CopyCountCheck.repairTime(sourceTimes, needSns);
    Map<String, List<String>> losers = CopyCountCheck.collectLossFile(needSns, services, sourceTimes);
    LOG.info("update before sn time :{}", sourceTimes);
    Pair<TaskModel, Map<String, Long>> pair = CreateSystemTask.creatTaskWithFiles(sourceTimes, losers, needSns, TaskType.SYSTEM_COPY_CHECK, RECOVERY_NUM, 0);
    if (pair == null) {
        LOG.warn("create pair is empty !!!!");
        return;
    }
    TaskModel task = pair.getFirst();
    String taskName = null;
    if (task != null) {
        List<String> servers = CreateSystemTask.getServerIds(services);
        taskName = CreateSystemTask.updateTask(release, task, servers, TaskType.SYSTEM_COPY_CHECK);
    }
    if (!BrStringUtils.isEmpty(taskName)) {
        LOG.info("create {} {} task successfull !!!", taskType, taskName);
    }
    sourceTimes = pair.getSecond();
    // 更新sn临界信息
    tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        LOG.warn("taskType {} metadata loss create against !!", taskType);
    }
    tmodel.putAllSnTimes(sourceTimes);
    release.setTaskTypeModel(taskType, tmodel);
    LOG.debug("update sn time {}", sourceTimes);
    createTransferTasks(release);
}
Also used : Service(com.bonree.brfs.common.service.Service) TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) List(java.util.List) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) Map(java.util.Map) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Example 8 with StorageRegion

use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.

the class WatchDog method searchPreys.

/**
 * 概述:获取
 * @param sim
 * @param sns
 * @param dataPath
 * @param limitTime
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void searchPreys(ServerIDManager sim, Collection<StorageRegion> sns, String zkHosts, String baseRoutesPath, String dataPath, long limitTime) {
    if (sns == null || sns.isEmpty() || BrStringUtils.isEmpty(dataPath)) {
        LOG.debug("skip search data because is empty");
        return;
    }
    if (isRun) {
        LOG.info("SKip search data because there is one");
        return;
    }
    lastTime = System.currentTimeMillis();
    // sn 目录及文件
    int snId;
    SecondIDParser parser;
    // 初始化zk连接
    if (curatorClient == null) {
        curatorClient = ManagerContralFactory.getInstance().getClient();
    }
    Map<String, String> snMap;
    long granule;
    long snLimitTime;
    for (StorageRegion sn : sns) {
        if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
            LOG.warn("skip search data because there is one reblance");
            return;
        }
        snId = sn.getId();
        granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
        ;
        snLimitTime = limitTime - limitTime % granule;
        LOG.info(" watch dog eat {} :{}", sn.getName(), sn.getId());
        // 单个副本的不做检查
        if (sn.getReplicateNum() <= 1) {
            continue;
        }
        parser = new SecondIDParser(curatorClient, snId, baseRoutesPath);
        // 使用前必须更新路由规则,否则会解析错误
        parser.updateRoute();
        snMap = new HashMap<>();
        snMap.put(BRFSPath.STORAGEREGION, sn.getName());
        List<BRFSPath> sfiles = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSDogFoodsFilter(sim, parser, sn, snLimitTime));
        if (sfiles == null || sfiles.isEmpty()) {
            continue;
        }
        for (BRFSPath brfsPath : sfiles) {
            preys.add(dataPath + FileUtils.FILE_SEPARATOR + brfsPath.toString());
        }
    }
    // 若见采集结果不为空则调用删除线程
    if (preys.size() > 0) {
        isRun = true;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                // 为空跳出
                if (preys == null) {
                    LOG.debug("queue is empty skip !!!");
                    return;
                }
                int count = 0;
                String path;
                while (!preys.isEmpty()) {
                    try {
                        path = preys.poll();
                        boolean deleteFlag = FileUtils.deleteFile(path);
                        LOG.debug("file : {} deleting!", path);
                        if (!deleteFlag) {
                            LOG.info("file : {} cann't delete !!!", path);
                        }
                        count++;
                        if (count % 100 == 0) {
                            Thread.sleep(1000L);
                        }
                    } catch (Exception e) {
                        LOG.error("watch dog delete file error {}", e);
                    }
                }
                isRun = false;
            }
        });
    }
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) BRFSPath(com.bonree.brfs.common.utils.BRFSPath)

Example 9 with StorageRegion

use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.

the class ServerMain method main.

public static void main(String[] args) {
    ProcessFinalizer finalizer = new ProcessFinalizer();
    try {
        ResourceTaskConfig resourceConfig = ResourceTaskConfig.parse();
        // 初始化email发送配置
        EmailPool.getInstance();
        String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
        CuratorClient leaderClient = CuratorClient.getClientInstance(zkAddresses, 1000, 1000);
        CuratorClient client = CuratorClient.getClientInstance(zkAddresses);
        CuratorCacheFactory.init(zkAddresses);
        ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME), zkAddresses);
        SimpleAuthentication authentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client.getInnerClient());
        UserModel model = authentication.getUser("root");
        if (model == null) {
            LOG.error("please init server!!!");
            System.exit(1);
        }
        ServerIDManager idManager = new ServerIDManager(client.getInnerClient(), zookeeperPaths);
        idManager.getFirstServerID();
        StorageRegionManager snManager = new DefaultStorageRegionManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), null);
        snManager.addStorageRegionStateListener(new StorageRegionStateListener() {

            @Override
            public void storageRegionAdded(StorageRegion node) {
                LOG.info("-----------StorageNameAdded--[{}]", node);
                idManager.getSecondServerID(node.getId());
            }

            @Override
            public void storageRegionUpdated(StorageRegion node) {
            }

            @Override
            public void storageRegionRemoved(StorageRegion node) {
                LOG.info("-----------StorageNameRemove--[{}]", node);
                idManager.deleteSecondServerID(node.getId());
            }
        });
        snManager.start();
        finalizer.add(snManager);
        ServiceManager sm = new DefaultServiceManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
        sm.start();
        finalizer.add(sm);
        // 磁盘管理模块
        // EmptyMain diskMain = new EmptyMain(sm);
        // diskMain.start();
        // 
        // finalizer.add(diskMain);
        DataNodeBootStrap dataNodeBootStrap = new DataNodeBootStrap(sm);
        dataNodeBootStrap.start();
        finalizer.add(dataNodeBootStrap);
        // 副本平衡模块
        sm.addServiceStateListener(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), new ServerChangeTaskGenetor(leaderClient, client, sm, idManager, zookeeperPaths.getBaseRebalancePath(), 3000, snManager));
        @SuppressWarnings("resource") RebalanceManager rebalanceServer = new RebalanceManager(zookeeperPaths, idManager, snManager, sm);
        rebalanceServer.start();
        String host = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST);
        int port = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_PORT);
        int readPort = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_PORT);
        Service selfService = new Service();
        selfService.setHost(host);
        selfService.setPort(port);
        selfService.setExtraPort(readPort);
        selfService.setServiceGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        String serviceId = idManager.getFirstServerID();
        selfService.setServiceId(serviceId);
        Service checkService = sm.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), serviceId);
        if (checkService == null) {
            sm.registerService(selfService);
            System.out.println(selfService);
        } else {
            LOG.error("serviceId : {} is exists, system will exit!!!", serviceId);
            System.exit(1);
        }
        finalizer.add(new Closeable() {

            @Override
            public void close() throws IOException {
                try {
                    sm.unregisterService(selfService);
                } catch (Exception e) {
                    LOG.error("unregister service[{}] error", selfService, e);
                }
            }
        });
        // 资源管理模块
        InitTaskManager.initManager(resourceConfig, zookeeperPaths, sm, snManager, idManager, client);
    } catch (Exception e) {
        LOG.error("launch server error!!!", e);
        System.exit(1);
    } finally {
        Runtime.getRuntime().addShutdownHook(finalizer);
    }
}
Also used : Closeable(java.io.Closeable) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Service(com.bonree.brfs.common.service.Service) RebalanceManager(com.bonree.brfs.rebalance.RebalanceManager) IOException(java.io.IOException) ResourceTaskConfig(com.bonree.brfs.configuration.ResourceTaskConfig) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException) UserModel(com.bonree.brfs.authentication.model.UserModel) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) DataNodeBootStrap(com.bonree.brfs.disknode.boot.DataNodeBootStrap) ZookeeperPaths(com.bonree.brfs.common.ZookeeperPaths) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) ServiceManager(com.bonree.brfs.common.service.ServiceManager) ServerChangeTaskGenetor(com.bonree.brfs.rebalance.task.ServerChangeTaskGenetor) SimpleAuthentication(com.bonree.brfs.authentication.SimpleAuthentication) ProcessFinalizer(com.bonree.brfs.common.process.ProcessFinalizer) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionStateListener(com.bonree.brfs.duplication.storageregion.StorageRegionStateListener)

Example 10 with StorageRegion

use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.

the class GatherResourceJob method getStorageNames.

/**
 * 概述:获取storageName的名称
 * @param storageNames
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private List<String> getStorageNames(List<StorageRegion> storageNames) {
    List<String> snList = new ArrayList<>();
    if (storageNames == null || storageNames.isEmpty()) {
        return snList;
    }
    String tmp;
    for (StorageRegion sn : storageNames) {
        if (sn == null) {
            continue;
        }
        tmp = sn.getName();
        if (BrStringUtils.isEmpty(tmp)) {
            continue;
        }
        snList.add(tmp);
    }
    return snList;
}
Also used : StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

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