Package com.alibaba.otter.node.etl.load.exception

Examples of com.alibaba.otter.node.etl.load.exception.LoadException


    /**
     * 返回结果为已处理成功的记录
     */
    public FileLoadContext load(FileBatch fileBatch, File rootDir, WeightController controller) {
        if (false == rootDir.exists()) {
            throw new LoadException(rootDir.getPath() + " is not exist");
        }
        FileLoadContext context = buildContext(fileBatch.getIdentity());
        context.setPrepareDatas(fileBatch.getFiles());
        boolean isDryRun = context.getPipeline().getParameters().isDryRun();
        try {
            // 复制成功的文件信息
            WeightBuckets<FileData> buckets = buildWeightBuckets(fileBatch.getIdentity(), fileBatch.getFiles());
            List<Long> weights = buckets.weights();
            controller.start(weights);
            // 处理数据
            for (int i = 0; i < weights.size(); i++) {
                Long weight = weights.get(i);
                controller.await(weight.intValue());
                if (logger.isInfoEnabled()) {
                    logger.debug("##start load for weight:{}\n", weight);
                }

                // 处理同一个weight下的数据
                List<FileData> items = buckets.getItems(weight);
                if (context.getPipeline().getParameters().isDryRun()) {
                    dryRun(context, items, rootDir);
                } else {
                    moveFiles(context, items, rootDir);
                }

                controller.single(weight.intValue());
                if (logger.isInfoEnabled()) {
                    logger.debug("##end load for weight:{}\n", weight);
                }
            }

            if (dump || isDryRun) {
                MDC.put(OtterConstants.splitPipelineLoadLogFileKey,
                        String.valueOf(fileBatch.getIdentity().getPipelineId()));
                logger.info(FileloadDumper.dumpContext("successed", context));
                MDC.remove(OtterConstants.splitPipelineLoadLogFileKey);
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            if (dump || isDryRun) {
                MDC.put(OtterConstants.splitPipelineLoadLogFileKey,
                        String.valueOf(fileBatch.getIdentity().getPipelineId()));
                logger.info(FileloadDumper.dumpContext("error", context));
                MDC.remove(OtterConstants.splitPipelineLoadLogFileKey);
            }
        } catch (Exception e) {
            if (dump || isDryRun) {
                MDC.put(OtterConstants.splitPipelineLoadLogFileKey,
                        String.valueOf(fileBatch.getIdentity().getPipelineId()));
                logger.info(FileloadDumper.dumpContext("error", context));
                MDC.remove(OtterConstants.splitPipelineLoadLogFileKey);
            }
            throw new LoadException(e);
        } finally {

            // 不论是否移动成功,删除临时目录
            NioUtils.delete(rootDir, 3);
        }
View Full Code Here


                entryName = fileData.getNameSpace() + File.separator + fileData.getPath();
            }
            File sourceFile = new File(rootDir, entryName);
            if (true == sourceFile.exists() && false == sourceFile.isDirectory()) {
                if (false == isLocal) {
                    throw new LoadException(fileData + " is not support!");
                } else {
                    // 记录一下文件的meta信息
                    fileData.setSize(sourceFile.length());
                    fileData.setLastModifiedTime(sourceFile.lastModified());
                    context.getProcessedDatas().add(fileData);
                }

                LoadCounter counter = loadStatsTracker.getStat(context.getIdentity()).getStat(fileData.getPairId());
                counter.getFileCount().incrementAndGet();
                counter.getFileSize().addAndGet(fileData.getSize());
            } else if (fileData.getEventType().isDelete()) {
                // 删除对应的文件
                if (false == isLocal) {
                    throw new LoadException(fileData + " is not support!");
                } else {
                    context.getProcessedDatas().add(fileData);
                }
            } else {
                context.getFailedDatas().add(fileData);// 失败记录
View Full Code Here

                    for (Future<Exception> result : results) {
                        if (!result.isDone() && !result.isCancelled()) {
                            result.cancel(true);
                        }
                    }
                    throw exception instanceof LoadException ? (LoadException) exception : new LoadException(exception);
                }
            }

        }

        int resultSize = results.size();
        int cursor = 0;
        while (cursor < resultSize) {
            try {
                Future<Exception> result = executorComplition.take();
                exception = result.get();
            } catch (Exception e) {
                exception = e;
                break;
            }
            cursor++;
        }

        if (cursor != resultSize) { // 发现任务出错,立刻把正在进行的任务取消
            for (Future<Exception> future : results) {
                if (!future.isDone() && !future.isCancelled()) {
                    future.cancel(true);
                }
            }

        }

        if (exception != null) {
            throw exception instanceof LoadException ? (LoadException) exception : new LoadException(exception);
        }
    }
View Full Code Here

            entryName = fileData.getNameSpace() + File.separator + fileData.getPath();
        }
        File sourceFile = new File(rootDir, entryName);
        if (true == sourceFile.exists() && false == sourceFile.isDirectory()) {
            if (false == isLocal) {
                throw new LoadException(fileData + " is not support!");
            } else {
                File targetFile = new File(fileData.getPath());
                // copy to product path
                NioUtils.copy(sourceFile, targetFile, retry);
                if (true == targetFile.exists()) {
                    // 记录一下文件的meta信息
                    fileData.setSize(sourceFile.length());
                    fileData.setLastModifiedTime(sourceFile.lastModified());
                    context.getProcessedDatas().add(fileData);
                } else {
                    throw new LoadException(String.format("copy/rename [%s] to [%s] failed by unknow reason",
                                                          sourceFile.getPath(), targetFile.getPath()));
                }

            }

            LoadCounter counter = loadStatsTracker.getStat(context.getIdentity()).getStat(fileData.getPairId());
            counter.getFileCount().incrementAndGet();
            counter.getFileSize().addAndGet(fileData.getSize());
        } else if (fileData.getEventType().isDelete()) {
            // 删除对应的文件
            if (false == isLocal) {
                throw new LoadException(fileData + " is not support!");
            } else {
                File targetFile = new File(fileData.getPath());
                if (NioUtils.delete(targetFile, retry)) {
                    context.getProcessedDatas().add(fileData);
                } else {
View Full Code Here

                            Thread.sleep(50);
                        }
                    }
                }

                throw new LoadException(String.format("FileLoadWorker is error! createFile failed[%s]",
                                                      fileData.getPath()), exception);
            } finally {
                MDC.remove(OtterConstants.splitPipelineLogFileKey);
            }
        }
View Full Code Here

        }

        // 先获取一下异步处理的结果,记录一下出错的index
        List<LoadContext> processedContexts = new ArrayList<LoadContext>();
        int index = 0;
        LoadException exception = null;
        while (index < futures.size()) {
            try {
                Future future = completionService.take();// 它也可能被打断
                future.get();
            } catch (InterruptedException e) {
                exception = new LoadException(e);
                break;
            } catch (ExecutionException e) {
                exception = new LoadException(e);
                break;
            }

            index++;
        }
View Full Code Here

        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            interceptor.error(context);
        } catch (Exception e) {
            interceptor.error(context);
            throw new LoadException(e);
        }

        return context;// 返回处理成功的记录
    }
View Full Code Here

    private boolean isDdlDatas(List<EventData> eventDatas) {
        boolean result = false;
        for (EventData eventData : eventDatas) {
            result |= eventData.getEventType().isDdl();
            if (result && !eventData.getEventType().isDdl()) {
                throw new LoadException("ddl/dml can't be in one batch, it's may be a bug , pls submit issues.",
                    DbLoadDumper.dumpEventDatas(eventDatas));
            }
        }

        return result;
View Full Code Here

            } catch (Throwable e) {
                if (skipDdlException) {
                    // do skip
                    logger.warn("skip exception for ddl : {} , caused by {}", data, ExceptionUtils.getFullStackTrace(e));
                } else {
                    throw new LoadException(e);
                }
            }

        }
    }
View Full Code Here

                    if (ex != null) {
                        throw ex; // 自己抛自己接
                    }
                } catch (Exception ex) {
                    logger.error("##load phase two failed!", ex);
                    throw new LoadException(ex);
                }
            }

            // 清理failed data数据
            for (EventData data : retryEventDatas) {
View Full Code Here

TOP

Related Classes of com.alibaba.otter.node.etl.load.exception.LoadException

Copyright © 2018 www.massapicom. 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.