Examples of EtlEventData


Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

            // 2.2 判断是否存在了prev节点
            if (stageNodes.contains(prevNode)) {
                // 2.2.1 获取上一个节点的next node节点信息
                byte[] data = zookeeper.readData(path + "/" + prevNode);
                EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
                if (eventData.getNextNid().equals(ArbitrateConfigUtils.getCurrentNid())) {
                    addReply(processId);// 添加到返回队列,唤醒wait阻塞
                }
            }
        } catch (ZkNoNodeException e) {
            // 出现节点不存在,说明出现了error情况
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

                    // 添加到待响应的buffer列表,不需要await termin信号,因为没启动过s/e/t/l流程
                    batchBuffer.put(new BatchTermin(gotMessage.getId(), false));
                    continue;
                }

                final EtlEventData etlEventData = arbitrateEventService.selectEvent().await(pipelineId);
                if (rversion.get() != startVersion) {// 说明存在过变化,中间出现过rollback,需要丢弃该数据
                    logger.warn("rollback happend , should skip this data and get new message.");
                    canStartSelector.get();// 确认一下rollback是否完成
                    gotMessage = otterSelector.selector();// 这时不管有没有数据,都需要执行一次s/e/t/l
                }

                final Message message = gotMessage;
                final BatchTermin batchTermin = new BatchTermin(message.getId(), etlEventData.getProcessId());
                batchBuffer.put(batchTermin); // 添加到待响应的buffer列表
                Runnable task = new Runnable() {

                    public void run() {
                        // 设置profiling信息
                        boolean profiling = isProfiling();
                        Long profilingStartTime = null;
                        if (profiling) {
                            profilingStartTime = System.currentTimeMillis();
                        }

                        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                        String currentName = Thread.currentThread().getName();
                        Thread.currentThread().setName(createTaskName(pipelineId, "SelectWorker"));
                        try {
                            pipeline = configClientService.findPipeline(pipelineId);
                            List<EventData> eventData = message.getDatas();
                            long startTime = etlEventData.getStartTime();
                            if (!CollectionUtils.isEmpty(eventData)) {
                                startTime = eventData.get(0).getExecuteTime();
                            }

                            Channel channel = configClientService.findChannelByPipelineId(pipelineId);
                            RowBatch rowBatch = new RowBatch();
                            // 构造唯一标识
                            Identity identity = new Identity();
                            identity.setChannelId(channel.getId());
                            identity.setPipelineId(pipelineId);
                            identity.setProcessId(etlEventData.getProcessId());
                            rowBatch.setIdentity(identity);
                            // 进行数据合并
                            for (EventData data : eventData) {
                                rowBatch.merge(data);
                            }

                            long nextNodeId = etlEventData.getNextNid();
                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(new DbBatch(rowBatch), nextNodeId);
                            etlEventData.setDesc(pipeKeys);
                            etlEventData.setNumber((long) eventData.size());
                            etlEventData.setFirstTime(startTime); // 使用原始数据的第一条
                            etlEventData.setBatchId(message.getId());

                            if (profiling) {
                                Long profilingEndTime = System.currentTimeMillis();
                                stageAggregationCollector.push(pipelineId,
                                                               StageType.SELECT,
                                                               new AggregationItem(profilingStartTime, profilingEndTime));
                            }
                            arbitrateEventService.selectEvent().single(etlEventData);
                        } catch (Throwable e) {
                            if (!isInterrupt(e)) {
                                logger.error(String.format("[%s] selectwork executor is error! data:%s", pipelineId,
                                                           etlEventData), e);
                                sendRollbackTermin(pipelineId, e);
                            } else {
                                logger.info(String.format("[%s] selectwork executor is interrrupt! data:%s",
                                                          pipelineId, etlEventData), e);
                            }
                        } finally {
                            Thread.currentThread().setName(currentName);
                            MDC.remove(OtterConstants.splitPipelineLogFileKey);
                        }
                    }
                };

                // 构造pending任务,可在关闭线程时退出任务
                SetlFuture extractFuture = new SetlFuture(StageType.SELECT, etlEventData.getProcessId(), pendingFuture,
                                                          task);
                executorService.execute(extractFuture);

            } catch (Throwable e) {
                if (!isInterrupt(e)) {
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

    public void run() {
        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
        while (running) {
            try {
                final EtlEventData etlEventData = arbitrateEventService.loadEvent().await(pipelineId);
                Runnable task = new Runnable() {

                    public void run() {
                        // 设置profiling信息
                        boolean profiling = isProfiling();
                        Long profilingStartTime = null;
                        if (profiling) {
                            profilingStartTime = System.currentTimeMillis();
                        }

                        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                        String currentName = Thread.currentThread().getName();
                        Thread.currentThread().setName(createTaskName(pipelineId, "LoadWorker"));
                        List<LoadContext> processedContexts = null;
                        try {
                            // 后续可判断同步数据是否为rowData
                            List<PipeKey> keys = (List<PipeKey>) etlEventData.getDesc();
                            DbBatch dbBatch = rowDataPipeDelegate.get(keys);

                            // 可能拿到为null,因为内存不足或者网络异常,长时间阻塞时,导致从pipe拿数据出现异常,数据可能被上一个节点已经删除
                            if (dbBatch == null) {
                                processMissData(pipelineId, "load miss data with keys:" + keys.toString());
                                return;
                            }

                            // 进行数据load处理
                            otterLoaderFactory.setStartTime(dbBatch.getRowBatch().getIdentity(),
                                                            etlEventData.getStartTime());

                            processedContexts = otterLoaderFactory.load(dbBatch);

                            if (profiling) {
                                Long profilingEndTime = System.currentTimeMillis();
                                stageAggregationCollector.push(pipelineId,
                                                               StageType.LOAD,
                                                               new AggregationItem(profilingStartTime, profilingEndTime));
                            }
                            // 处理完成后通知single已完成
                            arbitrateEventService.loadEvent().single(etlEventData);
                        } catch (Throwable e) {
                            if (!isInterrupt(e)) {
                                logger.error(String.format("[%s] loadWork executor is error! data:%s", pipelineId,
                                                           etlEventData), e);
                            } else {
                                logger.info(String.format("[%s] loadWork executor is interrrupt! data:%s", pipelineId,
                                                          etlEventData), e);
                            }

                            if (processedContexts != null) {// 说明load成功了,但是通知仲裁器失败了,需要记录下记录到store
                                for (LoadContext context : processedContexts) {
                                    try {
                                        if (context instanceof DbLoadContext) {
                                            dbLoadInterceptor.error((DbLoadContext) context);
                                        }

                                    } catch (Throwable ie) {
                                        logger.error(String.format("[%s] interceptor process error failed!", pipelineId),
                                                     ie);
                                    }
                                }
                            }

                            // try {
                            // arbitrateEventService.loadEvent().release(pipelineId);
                            // // 释放锁
                            // } catch (Throwable ie) {
                            // logger.error(String.format("[%s] load release failed!",
                            // pipelineId), ie);
                            // }

                            if (!isInterrupt(e)) {
                                sendRollbackTermin(pipelineId, e);
                            }
                        } finally {
                            Thread.currentThread().setName(currentName);
                            MDC.remove(OtterConstants.splitPipelineLogFileKey);
                        }
                    }
                };

                // 构造pending任务,可在关闭线程时退出任务
                SetlFuture extractFuture = new SetlFuture(StageType.LOAD, etlEventData.getProcessId(), pendingFuture,
                                                          task);
                executorService.execute(extractFuture);
            } catch (Throwable e) {
                if (isInterrupt(e)) {
                    logger.info(String.format("[%s] loadTask is interrupted!", pipelineId), e);
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

    public void run() {
        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
        while (running) {
            try {
                final EtlEventData etlEventData = arbitrateEventService.extractEvent().await(pipelineId);
                Runnable task = new Runnable() {

                    public void run() {
                        // 设置profiling信息
                        boolean profiling = isProfiling();
                        Long profilingStartTime = null;
                        if (profiling) {
                            profilingStartTime = System.currentTimeMillis();
                        }

                        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                        String currentName = Thread.currentThread().getName();
                        Thread.currentThread().setName(createTaskName(pipelineId, "ExtractWorker"));
                        try {
                            pipeline = configClientService.findPipeline(pipelineId);
                            List<PipeKey> keys = (List<PipeKey>) etlEventData.getDesc();
                            long nextNodeId = etlEventData.getNextNid();
                            DbBatch dbBatch = rowDataPipeDelegate.get(keys);

                            // 可能拿到为null,因为内存不足或者网络异常,长时间阻塞时,导致从pipe拿数据出现异常,数据可能被上一个节点已经删除
                            if (dbBatch == null) {
                                processMissData(pipelineId, "extract miss data with keys:" + keys.toString());
                                return;
                            }

                            otterExtractorFactory.extract(dbBatch);// 重新装配一下数据
                            if (dbBatch.getFileBatch() != null
                                && !CollectionUtils.isEmpty(dbBatch.getFileBatch().getFiles())
                                && pipeline.getParameters().getFileDetect()) { // 判断一下是否有文件同步,并且需要进行文件对比
                                // 对比一下中美图片是否有变化
                                FileBatch fileBatch = fileBatchConflictDetectService.detect(dbBatch.getFileBatch(),
                                                                                            nextNodeId);
                                dbBatch.setFileBatch(fileBatch);
                            }

                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(dbBatch, nextNodeId);
                            etlEventData.setDesc(pipeKeys);

                            if (profiling) {
                                Long profilingEndTime = System.currentTimeMillis();
                                stageAggregationCollector.push(pipelineId,
                                                               StageType.EXTRACT,
                                                               new AggregationItem(profilingStartTime, profilingEndTime));
                            }
                            arbitrateEventService.extractEvent().single(etlEventData);
                        } catch (Throwable e) {
                            if (!isInterrupt(e)) {
                                logger.error(String.format("[%d] extractwork executor is error! data:%s", pipelineId,
                                                           etlEventData), e);
                                sendRollbackTermin(pipelineId, e);
                            } else {
                                logger.info(String.format("[%d] extractwork executor is interrrupt! data:%s",
                                                          pipelineId, etlEventData), e);
                            }
                        } finally {
                            Thread.currentThread().setName(currentName);
                            MDC.remove(OtterConstants.splitPipelineLogFileKey);
                        }
                    }
                };

                // 构造pending任务,可在关闭线程时退出任务
                SetlFuture extractFuture = new SetlFuture(StageType.EXTRACT, etlEventData.getProcessId(),
                                                          pendingFuture, task);
                executorService.execute(extractFuture);
            } catch (Throwable e) {
                if (isInterrupt(e)) {
                    logger.info(String.format("[%s] extractTask is interrupted!", pipelineId), e);
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

    public void run() {
        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
        while (running) {
            try {
                final EtlEventData etlEventData = arbitrateEventService.transformEvent().await(pipelineId);
                Runnable task = new Runnable() {

                    @Override
                    public void run() {
                        // 设置profiling信息
                        boolean profiling = isProfiling();
                        Long profilingStartTime = null;
                        if (profiling) {
                            profilingStartTime = System.currentTimeMillis();
                        }

                        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                        String currentName = Thread.currentThread().getName();
                        Thread.currentThread().setName(createTaskName(pipelineId, "transformWorker"));

                        try {
                            // 后续可判断同步数据是否为rowData
                            List<PipeKey> keys = (List<PipeKey>) etlEventData.getDesc();
                            DbBatch dbBatch = rowDataPipeDelegate.get(keys);

                            // 可能拿到为null,因为内存不足或者网络异常,长时间阻塞时,导致从pipe拿数据出现异常,数据可能被上一个节点已经删除
                            if (dbBatch == null) {
                                processMissData(pipelineId, "transform miss data with keys:" + keys.toString());
                                return;
                            }

                            // 根据对应的tid,转化为目标端的tid。后续可进行字段的加工处理
                            // 暂时认为rowBatchs和fileBatchs不会有异构数据的转化
                            Map<Class, BatchObject> dataBatchs = otterTransformerFactory.transform(dbBatch.getRowBatch());

                            // 可能存在同一个Pipeline下有Mq和Db两种同步类型
                            dbBatch.setRowBatch((RowBatch) dataBatchs.get(EventData.class));

                            if (dbBatch.getFileBatch() != null) {
                                Map<Class, BatchObject> fileBatchs = otterTransformerFactory.transform(dbBatch.getFileBatch());
                                dbBatch.setFileBatch((FileBatch) fileBatchs.get(FileData.class));
                            }
                            // 传递给下一个流程
                            List<PipeKey> nextKeys = rowDataPipeDelegate.put(dbBatch, etlEventData.getNextNid());
                            etlEventData.setDesc(nextKeys);

                            if (profiling) {
                                Long profilingEndTime = System.currentTimeMillis();
                                stageAggregationCollector.push(pipelineId,
                                                               StageType.TRANSFORM,
                                                               new AggregationItem(profilingStartTime, profilingEndTime));
                            }
                            // 处理完成后通知single已完成
                            arbitrateEventService.transformEvent().single(etlEventData);
                        } catch (Throwable e) {
                            if (!isInterrupt(e)) {
                                logger.error(String.format("[%s] transformWork executor is error! data:%s", pipelineId,
                                                           etlEventData), e);
                                sendRollbackTermin(pipelineId, e);
                            } else {
                                logger.info(String.format("[%s] transformWork executor is interrrupt! data:%s",
                                                          pipelineId, etlEventData), e);
                            }
                        } finally {
                            Thread.currentThread().setName(currentName);
                            MDC.remove(OtterConstants.splitPipelineLogFileKey);
                        }
                    }
                };

                // 构造pending任务,可在关闭线程时退出任务
                SetlFuture extractFuture = new SetlFuture(StageType.TRANSFORM, etlEventData.getProcessId(),
                                                          pendingFuture, task);
                executorService.execute(extractFuture);

            } catch (Throwable e) {
                if (isInterrupt(e)) {
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

                    // 添加到待响应的buffer列表,不需要await termin信号,因为没启动过s/e/t/l流程
                    batchBuffer.put(new BatchTermin(gotMessage.getId(), false));
                    continue;
                }

                final EtlEventData etlEventData = arbitrateEventService.selectEvent().await(pipelineId);
                if (rversion.get() != startVersion) {// 说明存在过变化,中间出现过rollback,需要丢弃该数据
                    logger.warn("rollback happend , should skip this data and get new message.");
                    canStartSelector.get();// 确认一下rollback是否完成
                    gotMessage = otterSelector.selector();// 这时不管有没有数据,都需要执行一次s/e/t/l
                }

                final Message message = gotMessage;
                final BatchTermin batchTermin = new BatchTermin(message.getId(), etlEventData.getProcessId());
                batchBuffer.put(batchTermin); // 添加到待响应的buffer列表
                Runnable task = new Runnable() {

                    public void run() {
                        // 设置profiling信息
                        boolean profiling = isProfiling();
                        Long profilingStartTime = null;
                        if (profiling) {
                            profilingStartTime = System.currentTimeMillis();
                        }

                        MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                        String currentName = Thread.currentThread().getName();
                        Thread.currentThread().setName(createTaskName(pipelineId, "SelectWorker"));
                        try {
                            pipeline = configClientService.findPipeline(pipelineId);
                            List<EventData> eventData = message.getDatas();
                            long startTime = etlEventData.getStartTime();
                            if (!CollectionUtils.isEmpty(eventData)) {
                                startTime = eventData.get(0).getExecuteTime();
                            }

                            Channel channel = configClientService.findChannelByPipelineId(pipelineId);
                            RowBatch rowBatch = new RowBatch();
                            // 构造唯一标识
                            Identity identity = new Identity();
                            identity.setChannelId(channel.getId());
                            identity.setPipelineId(pipelineId);
                            identity.setProcessId(etlEventData.getProcessId());
                            rowBatch.setIdentity(identity);
                            // 进行数据合并
                            for (EventData data : eventData) {
                                rowBatch.merge(data);
                            }

                            long nextNodeId = etlEventData.getNextNid();
                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(new DbBatch(rowBatch), nextNodeId);
                            etlEventData.setDesc(pipeKeys);
                            etlEventData.setNumber((long) eventData.size());
                            etlEventData.setFirstTime(startTime); // 使用原始数据的第一条
                            etlEventData.setBatchId(message.getId());

                            if (profiling) {
                                Long profilingEndTime = System.currentTimeMillis();
                                stageAggregationCollector.push(pipelineId,
                                    StageType.SELECT,
                                    new AggregationItem(profilingStartTime, profilingEndTime));
                            }
                            arbitrateEventService.selectEvent().single(etlEventData);
                        } catch (Throwable e) {
                            if (!isInterrupt(e)) {
                                logger.error(String.format("[%s] selectwork executor is error! data:%s",
                                    pipelineId,
                                    etlEventData), e);
                                sendRollbackTermin(pipelineId, e);
                            } else {
                                logger.info(String.format("[%s] selectwork executor is interrrupt! data:%s",
                                    pipelineId,
                                    etlEventData), e);
                            }
                        } finally {
                            Thread.currentThread().setName(currentName);
                            MDC.remove(OtterConstants.splitPipelineLogFileKey);
                        }
                    }
                };

                // 构造pending任务,可在关闭线程时退出任务
                SetlFuture extractFuture = new SetlFuture(StageType.SELECT,
                    etlEventData.getProcessId(),
                    pendingFuture,
                    task);
                executorService.execute(extractFuture);

            } catch (Throwable e) {
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

                    byte[] bytes = orginZk.getData(stagePath, false, zkStat);
                    if (bytes != null && bytes.length > 0) {
                        // 特殊处理zookeeper里的data信息,manager没有对应node中PipeKey的对象,所以导致反序列化会失败,需要特殊处理,删除'@'符号
                        String json = StringUtils.remove(new String(bytes, "UTF-8"), '@');
                        EtlEventData data = JsonUtils.unmarshalFromString(json, EtlEventData.class);
                        stageStat.setNumber(data.getNumber());
                        stageStat.setSize(data.getSize());

                        Map exts = new HashMap();
                        if (!CollectionUtils.isEmpty(data.getExts())) {
                            exts.putAll(data.getExts());
                        }
                        exts.put("currNid", data.getCurrNid());
                        exts.put("nextNid", data.getNextNid());
                        exts.put("desc", data.getDesc());
                        stageStat.setExts(exts);
                    }
                    if (prev != null) {// 对应的start时间为上一个节点的结束时间
                        stageStat.setStartTime(prev.getEndTime());
                    } else {
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

    public synchronized void termin(TerminType type) {
        // 构建termin信号
        List<Long> processIds = new ArrayList<Long>(progress.keySet());
        Collections.sort(processIds);// 做一下排序
        for (Long processId : processIds) {
            EtlEventData eventData = progress.get(processId).getData();

            TerminEventData data = new TerminEventData();
            data.setPipelineId(getPipelineId());
            data.setType(type);
            data.setCode("channel");
            data.setDesc(type.toString());
            data.setProcessId(processId);
            if (eventData != null) {
                data.setBatchId(eventData.getBatchId());
                data.setCurrNid(eventData.getCurrNid());
                data.setStartTime(eventData.getStartTime());
                data.setEndTime(eventData.getEndTime());
                data.setFirstTime(eventData.getFirstTime());
                data.setNumber(eventData.getNumber());
                data.setSize(eventData.getSize());
                data.setExts(eventData.getExts());
            }
            offerTermin(data);
            progress.remove(processId);
        }
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

                    byte[] bytes = orginZk.getData(stagePath, false, zkStat);
                    if (bytes != null && bytes.length > 0) {
                        // 特殊处理zookeeper里的data信息,manager没有对应node中PipeKey的对象,所以导致反序列化会失败,需要特殊处理,删除'@'符号
                        String json = StringUtils.remove(new String(bytes, "UTF-8"), '@');
                        EtlEventData data = JsonUtils.unmarshalFromString(json, EtlEventData.class);
                        stageStat.setNumber(data.getNumber());
                        stageStat.setSize(data.getSize());

                        Map exts = new HashMap();
                        if (!CollectionUtils.isEmpty(data.getExts())) {
                            exts.putAll(data.getExts());
                        }
                        exts.put("currNid", data.getCurrNid());
                        exts.put("nextNid", data.getNextNid());
                        exts.put("desc", data.getDesc());
                        stageStat.setExts(exts);
                    }
                    if (prev != null) {// 对应的start时间为上一个节点的结束时间
                        stageStat.setStartTime(prev.getEndTime());
                    } else {
View Full Code Here

Examples of com.alibaba.otter.shared.arbitrate.model.EtlEventData

        Long processId = selectProcessListener.waitForProcess(); // 符合条件的processId

        ChannelStatus status = permitMonitor.getChannelPermit();
        if (status.isStart()) {// 即时查询一下当前的状态,状态随时可能会变
            try {
                EtlEventData eventData = new EtlEventData();
                eventData.setPipelineId(pipelineId);
                eventData.setProcessId(processId);
                eventData.setStartTime(new Date().getTime());// 返回当前时间

                Node node = LoadBalanceFactory.getNextExtractNode(pipelineId);// 获取下一个处理节点信息
                if (node == null) {// 没有后端节点
                    // TerminEventData termin = new TerminEventData();
                    // termin.setPipelineId(pipelineId);
                    // termin.setType(TerminType.ROLLBACK);
                    // termin.setCode("no_node");
                    // termin.setDesc(MessageFormat.format("pipeline[{}] extract stage has no node!", pipelineId));
                    // terminEvent.single(termin);
                    throw new ArbitrateException("Select_single", "no next node");
                } else {
                    eventData.setNextNid(node.getId());
                    markUsed(eventData); // 标记为已使用
                    return eventData;// 只有这一条路返回
                }
            } catch (ZkNoNodeException e) {
                logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.