Search in sources :

Example 1 with SecondIDParser

use of com.bonree.brfs.rebalance.route.SecondIDParser 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 2 with SecondIDParser

use of com.bonree.brfs.rebalance.route.SecondIDParser in project BRFS by zhangnianli.

the class CopyCountCheck method collectionSnFiles.

/**
 * 概述:获取集群对应目录的文件
 * @param services
 * @param snList
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Map<StorageRegion, List<String>> collectionSnFiles(List<Service> services, List<StorageRegion> snList, final Map<String, Long> snTimes) throws Exception {
    Map<StorageRegion, List<String>> snMap = new HashMap<>();
    DiskNodeClient client = null;
    int reCount;
    String snName = null;
    String path;
    List<String> strs;
    long time;
    String dirName;
    String sid;
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    CuratorClient zkClient = mcf.getClient();
    SecondIDParser parser;
    String basePath = mcf.getZkPath().getBaseRoutePath();
    int timeout = 10000;
    for (Service service : services) {
        try {
            client = TcpClientUtils.getClient(service.getHost(), service.getPort(), service.getExtraPort(), timeout);
            long granule;
            for (StorageRegion sn : snList) {
                parser = new SecondIDParser(zkClient, sn.getId(), basePath);
                parser.updateRoute();
                sid = sim.getOtherSecondID(service.getServiceId(), sn.getId());
                granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
                reCount = sn.getReplicateNum();
                snName = sn.getName();
                if (!snTimes.containsKey(snName)) {
                    LOG.debug("sntime don't contain {}", snName);
                    continue;
                }
                time = snTimes.get(snName);
                dirName = TimeUtils.timeInterval(time, granule);
                for (int i = 1; i <= reCount; i++) {
                    path = "/" + snName + "/" + i + "/" + dirName;
                    LOG.debug("path :{}", path);
                    strs = getFileList(parser, client, path, sid);
                    if (strs == null || strs.isEmpty()) {
                        LOG.debug("files is empty {}", path);
                        continue;
                    }
                    LOG.debug("Collection dirName :{},{} size :{}", dirName, path, strs.size());
                    if (!snMap.containsKey(sn)) {
                        snMap.put(sn, new ArrayList<>());
                    }
                    snMap.get(sn).addAll(strs);
                }
            }
        } catch (Exception e) {
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
            builder.setModel("collect file execute 模块服务发生问题");
            builder.setException(e);
            builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
            Map<String, String> map = new HashedMap();
            map.put("remote ", service.getHost());
            map.put("connectTimeout", String.valueOf(timeout));
            map.put("sn", StringUtils.isEmpty(snName) ? "" : snName);
            if (snTimes != null && !snTimes.isEmpty()) {
                map.put("sntime", JSON.toJSONString(snTimes));
            }
            builder.setVariable(map);
            emailPool.sendEmail(builder);
            throw e;
        } finally {
            if (client != null) {
                try {
                    client.close();
                } catch (IOException e) {
                    LOG.error("{}", e);
                }
            }
        }
    }
    return clearUnLawFiles(snMap);
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Service(com.bonree.brfs.common.service.Service) EmailPool(com.bonree.brfs.email.EmailPool) IOException(java.io.IOException) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException) DiskNodeClient(com.bonree.brfs.disknode.client.DiskNodeClient) HashedMap(org.apache.commons.collections.map.HashedMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 3 with SecondIDParser

use of com.bonree.brfs.rebalance.route.SecondIDParser in project BRFS by zhangnianli.

the class CopyRecovery method recoveryDirs.

/**
 * 概述:修复目录
 * @param content
 * @param zkHosts
 * @param baseRoutesPath
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static TaskResultModel recoveryDirs(String content, String zkHosts, String baseRoutesPath, String dataPath) {
    TaskResultModel result = new TaskResultModel();
    BatchAtomModel batch = converStringToBatch(content);
    if (batch == null) {
        result.setSuccess(false);
        LOG.debug("batch is empty");
        return result;
    }
    List<AtomTaskModel> atoms = batch.getAtoms();
    if (atoms == null || atoms.isEmpty()) {
        result.setSuccess(true);
        LOG.debug(" files is empty");
        return result;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    ServiceManager sm = mcf.getSm();
    StorageRegionManager snm = mcf.getSnm();
    CuratorClient curatorClient = mcf.getClient();
    StorageRegion sn;
    SecondIDParser parser;
    String snName;
    int snId;
    AtomTaskResultModel atomR;
    List<String> errors;
    for (AtomTaskModel atom : atoms) {
        atomR = new AtomTaskResultModel();
        atomR.setFiles(atom.getFiles());
        atomR.setSn(atom.getStorageName());
        snName = atom.getStorageName();
        sn = snm.findStorageRegionByName(snName);
        if (sn == null) {
            atomR.setSuccess(false);
            result.setSuccess(false);
            result.add(atomR);
            LOG.debug("sn == null snName :{}", snName);
            continue;
        }
        snId = sn.getId();
        parser = new SecondIDParser(curatorClient, snId, baseRoutesPath);
        parser.updateRoute();
        errors = recoveryFiles(sm, sim, parser, sn, atom, dataPath);
        if (errors == null || errors.isEmpty()) {
            result.add(atomR);
            LOG.debug("result is empty snName:{}", snName);
            continue;
        }
        atomR.addAll(errors);
        atomR.setSuccess(false);
        result.setSuccess(false);
    }
    return result;
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Aggregations

StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)3 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)3 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)2 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)2 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)2 Service (com.bonree.brfs.common.service.Service)1 ServiceManager (com.bonree.brfs.common.service.ServiceManager)1 BRFSPath (com.bonree.brfs.common.utils.BRFSPath)1 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)1 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)1 EmailPool (com.bonree.brfs.email.EmailPool)1 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)1 AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)1 BatchAtomModel (com.bonree.brfs.schedulers.task.model.BatchAtomModel)1 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)1 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HashedMap (org.apache.commons.collections.map.HashedMap)1