Source:
private String downloadSegmentToLocal(String uri, PinotCrypter crypter, String tableName, String segmentName) throws Exception { RetryPolicies.fixedDelayRetryPolicy(3, 5_000L).attempt(() -> { File tempDir = new File(new File(_instanceDataManager.getSegmentFileDirectory(), tableName), "tmp-" + segmentName + "-" + UUID.randomUUID()); FileUtils.forceMkdir(tempDir); File tempDownloadFile = new File(tempDir, segmentName + ENCODED_SUFFIX); File tempTarFile = new File(tempDir, segmentName + TAR_GZ_SUFFIX); File tempSegmentDir = new File(tempDir, segmentName); try { SegmentFetcherFactory.fetchSegmentToLocal(uri, tempDownloadFile); if (crypter != null) { crypter.decrypt(tempDownloadFile, tempTarFile); } else { tempTarFile = tempDownloadFile; } LOGGER.info("Downloaded tarred segment: for table: from: to: {}, file length: {}", segmentName, tableName, uri, tempTarFile, tempTarFile.length()); File tempIndexDir = TarGzCompressionUtils.untar(tempTarFile, tempSegmentDir).get(0); File indexDir = new File(new File(_instanceDataManager.getSegmentDataDirectory(), tableName), segmentName); if (indexDir.exists()) { LOGGER.info("Deleting existing index directory for segment: for table: {}", segmentName, tableName); FileUtils.deleteDirectory(indexDir); } FileUtils.moveDirectory(tempIndexDir, indexDir); LOGGER.info("Successfully downloaded segment: for table: to: {}", segmentName, tableName, indexDir); return Boolean.TRUE; } catch (AttemptsExceededException e) { LOGGER.error("Attempts exceed when downloading segment for table: to local", segmentName, tableName, e); throw e; } catch (Exception e) { LOGGER.error("Caught exception when downloading segment for table: to local", segmentName, tableName, e); return Boolean.FALSE; } finally { FileUtils.deleteQuietly(tempDir); } }); return new File(new File(_instanceDataManager.getSegmentDataDirectory(), tableName), segmentName).getAbsolutePath(); }

Target:
private String downloadSegmentToLocal(String uri, PinotCrypter crypter, String tableName, String segmentName) throws Exception { RetryPolicies.fixedDelayRetryPolicy(3, 5_000L).attempt(() -> { File tempDir = new File(new File(_instanceDataManager.getSegmentFileDirectory(), tableName), "tmp-" + segmentName + "-" + UUID.randomUUID()); FileUtils.forceMkdir(tempDir); File tempDownloadFile = new File(tempDir, segmentName + ENCODED_SUFFIX); File tempTarFile = new File(tempDir, segmentName + TAR_GZ_SUFFIX); File tempSegmentDir = new File(tempDir, segmentName); try { SegmentFetcherFactory.fetchSegmentToLocal(uri, tempDownloadFile); if (crypter != null) { crypter.decrypt(tempDownloadFile, tempTarFile); } else { tempTarFile = tempDownloadFile; } LOGGER.info("Downloaded tarred segment: for table: from: to: {}, file length: {}", segmentName, tableName, uri, tempTarFile, tempTarFile.length()); try { File tempIndexDir = TarGzCompressionUtils.untar(tempTarFile, tempSegmentDir).get(0); File indexDir = new File(new File(_instanceDataManager.getSegmentDataDirectory(), tableName), segmentName); if (indexDir.exists()) { LOGGER.info("Deleting existing index directory for segment: for table: {}", segmentName, tableName); FileUtils.deleteDirectory(indexDir); } FileUtils.moveDirectory(tempIndexDir, indexDir); LOGGER.info("Successfully downloaded segment: for table: to: {}", segmentName, tableName, indexDir); return Boolean.TRUE; } catch (Exception e) { _serverMetrics.addMeteredTableValue(tableName, ServerMeter.UNTAR_FAILURES, 1L); Utils.rethrowException(e); return Boolean.FALSE; } } catch (AttemptsExceededException e) { LOGGER.error("Attempts exceed when downloading segment for table: to local", segmentName, tableName, e); Utils.rethrowException(e); return Boolean.FALSE; } finally { FileUtils.deleteQuietly(tempDir); } }); return new File(new File(_instanceDataManager.getSegmentDataDirectory(), tableName), segmentName).getAbsolutePath(); }