Search in sources :

Example 11 with Retryable

use of org.apache.hadoop.hive.ql.exec.util.Retryable in project hive by apache.

the class TestFileList method setupFileList.

private FileList setupFileList(boolean... retryParams) throws Exception {
    HiveConf hiveConf = Mockito.mock(HiveConf.class);
    FileSystem mockFs = Mockito.mock(FileSystem.class);
    Path backingFile = Mockito.spy(new Path("/tmp/backingFile"));
    FileList fileList = Mockito.spy(new FileList(backingFile, hiveConf));
    outStream = Mockito.spy(new FSDataOutputStream(null, null));
    Retryable retryable = Retryable.builder().withTotalDuration(60).withInitialDelay(1).withBackoff(1.0).withRetryOnException(IOException.class).build();
    if (retryParams.length == 0) {
        // setup for normal flow, without failures
        Path noRetryPath = new Path(new Path(TEST_DATA_DIR), "noRetry");
        testFileStream = Mockito.spy(noRetryPath.getFileSystem(conf).create(noRetryPath));
        Mockito.doReturn(retryable).when(fileList).buildRetryable();
        Mockito.doReturn(true).when(hiveConf).getBoolVar(HiveConf.ConfVars.REPL_COPY_FILE_LIST_ITERATOR_RETRY);
        Mockito.doReturn(testFileStream).when(fileList).initWriter();
    } else if (retryParams.length == 1) {
        // setup for retries
        Mockito.doReturn(true).when(hiveConf).getBoolVar(HiveConf.ConfVars.REPL_COPY_FILE_LIST_ITERATOR_RETRY);
        Mockito.doReturn(retryable).when(fileList).buildRetryable();
        Mockito.doReturn(mockFs).when(backingFile).getFileSystem(hiveConf);
        if (retryParams[0]) {
            // setup for retry because of create-failure
            Mockito.doReturn(false).when(mockFs).exists(backingFile);
            Mockito.doThrow(testException).when(fileList).getWriterCreateMode();
        } else {
            // setup for retry because of failure during writes
            Mockito.when(mockFs.exists(backingFile)).thenReturn(false).thenReturn(true);
            Mockito.doReturn(outStream).when(fileList).getWriterAppendMode();
            Mockito.doReturn(outStream).when(fileList).getWriterCreateMode();
            Mockito.doThrow(testException).when(outStream).writeBytes(Mockito.anyString());
        }
    } else if (retryParams.length == 2) {
        // setup for failure but no retry
        Mockito.doReturn(false).when(hiveConf).getBoolVar(HiveConf.ConfVars.REPL_COPY_FILE_LIST_ITERATOR_RETRY);
        Mockito.doReturn(outStream).when(fileList).getWriterCreateMode();
        Mockito.doThrow(testException).when(outStream).writeBytes(Mockito.anyString());
    } else if (retryParams.length == 3) {
        // setup for abort case
        Mockito.doReturn(true).when(hiveConf).getBoolVar(HiveConf.ConfVars.REPL_COPY_FILE_LIST_ITERATOR_RETRY);
        Mockito.doReturn(outStream).when(fileList).initWriter();
    }
    return fileList;
}
Also used : Path(org.apache.hadoop.fs.Path) Retryable(org.apache.hadoop.hive.ql.exec.util.Retryable) FileSystem(org.apache.hadoop.fs.FileSystem) HiveConf(org.apache.hadoop.hive.conf.HiveConf) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IOException(java.io.IOException)

Example 12 with Retryable

use of org.apache.hadoop.hive.ql.exec.util.Retryable in project hive by apache.

the class AtlasDumpTask method lastStoredTimeStamp.

private long lastStoredTimeStamp() throws SemanticException {
    Path prevMetadataPath = new Path(work.getPrevAtlasDumpDir(), EximUtil.METADATA_NAME);
    Retryable retryable = Retryable.builder().withHiveConf(conf).withRetryOnException(IOException.class).withFailOnException(FileNotFoundException.class).build();
    try {
        return retryable.executeCallable(() -> {
            BufferedReader br = null;
            try {
                FileSystem fs = prevMetadataPath.getFileSystem(conf);
                br = new BufferedReader(new InputStreamReader(fs.open(prevMetadataPath), Charset.defaultCharset()));
                String line = br.readLine();
                if (line == null) {
                    throw new SemanticException(ErrorMsg.REPL_INVALID_INTERNAL_CONFIG_FOR_SERVICE.format("Could not read lastStoredTimeStamp from atlas metadata file", ReplUtils.REPL_ATLAS_SERVICE));
                }
                String[] lineContents = line.split("\t", 5);
                return Long.parseLong(lineContents[1]);
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                    // Do nothing
                    }
                }
            }
        });
    } catch (SemanticException e) {
        throw e;
    } catch (Exception e) {
        throw new SemanticException(ErrorMsg.REPL_RETRY_EXHAUSTED.format(e.getMessage()), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) InputStreamReader(java.io.InputStreamReader) Retryable(org.apache.hadoop.hive.ql.exec.util.Retryable) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 13 with Retryable

use of org.apache.hadoop.hive.ql.exec.util.Retryable in project hive by apache.

the class AtlasLoadTask method getStoredFsUri.

private String getStoredFsUri(Path atlasDumpDir) throws SemanticException {
    Path metadataPath = new Path(atlasDumpDir, EximUtil.METADATA_NAME);
    Retryable retryable = Retryable.builder().withHiveConf(conf).withRetryOnException(IOException.class).build();
    try {
        return retryable.executeCallable(() -> {
            BufferedReader br = null;
            try {
                FileSystem fs = metadataPath.getFileSystem(conf);
                br = new BufferedReader(new InputStreamReader(fs.open(metadataPath), Charset.defaultCharset()));
                String line = br.readLine();
                if (line == null) {
                    throw new SemanticException(ErrorMsg.REPL_INVALID_INTERNAL_CONFIG_FOR_SERVICE.format("Could not read stored " + "src FS Uri from atlas metadata file", ReplUtils.REPL_ATLAS_SERVICE));
                }
                String[] lineContents = line.split("\t", 5);
                return lineContents[0];
            } finally {
                if (br != null) {
                    br.close();
                }
            }
        });
    } catch (Exception e) {
        throw new SemanticException(ErrorMsg.REPL_RETRY_EXHAUSTED.format(e.getMessage()), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) InputStreamReader(java.io.InputStreamReader) Retryable(org.apache.hadoop.hive.ql.exec.util.Retryable) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 14 with Retryable

use of org.apache.hadoop.hive.ql.exec.util.Retryable in project hive by apache.

the class DirCopyTask method execute.

@Override
public int execute() {
    LOG.info("Started DirCopyTask for source: {} to target: {}", work.getFullyQualifiedSourcePath(), work.getFullyQualifiedTargetPath());
    HiveConf clonedConf = getConf(conf);
    String distCpDoAsUser = clonedConf.getVar(HiveConf.ConfVars.HIVE_DISTCP_DOAS_USER);
    Retryable retryable = Retryable.builder().withHiveConf(clonedConf).withRetryOnException(IOException.class).withFailOnException(SnapshotException.class).build();
    long startTime = System.currentTimeMillis();
    AtomicInteger retries = new AtomicInteger(-1);
    AtomicBoolean result = new AtomicBoolean(false);
    try {
        return retryable.executeCallable(() -> {
            retries.getAndIncrement();
            UserGroupInformation proxyUser = null;
            Path sourcePath = work.getFullyQualifiedSourcePath();
            Path targetPath = work.getFullyQualifiedTargetPath();
            try {
                if (clonedConf.getBoolVar(HiveConf.ConfVars.REPL_ADD_RAW_RESERVED_NAMESPACE)) {
                    sourcePath = reservedRawPath(work.getFullyQualifiedSourcePath().toUri());
                    targetPath = reservedRawPath(work.getFullyQualifiedTargetPath().toUri());
                }
                UserGroupInformation ugi = Utils.getUGI();
                String currentUser = ugi.getShortUserName();
                if (distCpDoAsUser != null && !currentUser.equals(distCpDoAsUser)) {
                    proxyUser = UserGroupInformation.createProxyUser(distCpDoAsUser, UserGroupInformation.getLoginUser());
                }
                setTargetPathOwner(targetPath, sourcePath, proxyUser, clonedConf);
                try {
                    if (!checkIfPathExist(sourcePath, proxyUser, clonedConf)) {
                        LOG.info("Source path is missing. Ignoring exception.");
                        return 0;
                    }
                } catch (Exception ex) {
                    LOG.warn("Source path missing check failed. ", ex);
                    // Should be retried
                    throw new IOException(ex);
                }
                if (!getWork().getCopyMode().equals(SnapshotUtils.SnapshotCopyMode.FALLBACK_COPY)) {
                    LOG.info("Using Snapshot mode of copy for source: {} and target: {}", sourcePath, targetPath);
                    // Use distcp with snapshots for copy.
                    result.set(copyUsingDistCpSnapshots(sourcePath, targetPath, proxyUser, clonedConf));
                } else {
                    LOG.info("Using Normal copy for source: {} and target: {}", sourcePath, targetPath);
                    result.set(runFallbackDistCp(sourcePath, targetPath, proxyUser, clonedConf));
                }
                return 0;
            } finally {
                if (proxyUser != null) {
                    FileSystem.closeAllForUGI(proxyUser);
                }
            }
        });
    } catch (Exception e) {
        LOG.error("Replication failed ", e);
        Exception ex = new SecurityException(ErrorMsg.REPL_RETRY_EXHAUSTED.format(e.getMessage()), e);
        setException(ex);
        return ReplUtils.handleException(true, ex, work.getDumpDirectory(), work.getMetricCollector(), getName(), clonedConf);
    } finally {
        String jobId = clonedConf.get(ReplUtils.DISTCP_JOB_ID_CONF, ReplUtils.DISTCP_JOB_ID_CONF_DEFAULT);
        LOG.info("DirCopyTask status for source: {} to  target: {}. Took {}. DistCp JobId {}. Number of retries {}. " + "Result: {}", work.getFullyQualifiedSourcePath(), work.getFullyQualifiedTargetPath(), ReplUtils.convertToHumanReadableTime(System.currentTimeMillis() - startTime), jobId, retries.get(), result.get() ? "SUCCEEDED" : "FAILED");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Retryable(org.apache.hadoop.hive.ql.exec.util.Retryable) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IOException(java.io.IOException) SnapshotException(org.apache.hadoop.hdfs.protocol.SnapshotException) SnapshotException(org.apache.hadoop.hdfs.protocol.SnapshotException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 15 with Retryable

use of org.apache.hadoop.hive.ql.exec.util.Retryable in project hive by apache.

the class ReplDumpTask method cleanFailedEventDirIfExists.

private void cleanFailedEventDirIfExists(Path dumpDir, long resumeFrom) throws SemanticException {
    Path nextEventRoot = new Path(dumpDir, String.valueOf(resumeFrom + 1));
    Retryable retryable = Retryable.builder().withHiveConf(conf).withRetryOnException(IOException.class).build();
    try {
        retryable.executeCallable((Callable<Void>) () -> {
            FileSystem fs = FileSystem.get(nextEventRoot.toUri(), conf);
            try {
                fs.delete(nextEventRoot, true);
            } catch (FileNotFoundException e) {
            // no worries
            }
            return null;
        });
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Retryable(org.apache.hadoop.hive.ql.exec.util.Retryable) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) TException(org.apache.thrift.TException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SnapshotException(org.apache.hadoop.hdfs.protocol.SnapshotException) FileNotFoundException(java.io.FileNotFoundException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

IOException (java.io.IOException)19 Retryable (org.apache.hadoop.hive.ql.exec.util.Retryable)19 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)13 FileNotFoundException (java.io.FileNotFoundException)11 Path (org.apache.hadoop.fs.Path)8 FileSystem (org.apache.hadoop.fs.FileSystem)6 UncheckedIOException (java.io.UncheckedIOException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)4 SnapshotException (org.apache.hadoop.hdfs.protocol.SnapshotException)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 Task (org.apache.hadoop.hive.ql.exec.Task)3 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 MalformedURLException (java.net.MalformedURLException)2 NoSuchElementException (java.util.NoSuchElementException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2