This is an automated email from the ASF dual-hosted git repository. nehapawar pushed a commit to branch revert-4757-download-fix in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 309c59728caf38455799e8c23bb5bad9def53666 Author: Neha Pawar <[email protected]> AuthorDate: Fri Nov 8 14:39:36 2019 -0800 Revert "Fix controller download segment api on non-local PinotFS. (#4757)" This reverts commit 7790e15f15a69e800f8b49cd0bdb44725db8d6c7. --- .../PinotSegmentUploadRestletResource.java | 40 ++++------------------ 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadRestletResource.java b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadRestletResource.java index 80228d1..62ac10d 100644 --- a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadRestletResource.java +++ b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadRestletResource.java @@ -30,7 +30,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.net.URI; -import java.nio.file.Files; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; @@ -53,7 +52,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.core.StreamingOutput; import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -66,7 +64,6 @@ import org.apache.pinot.common.segment.fetcher.SegmentFetcherFactory; import org.apache.pinot.common.utils.CommonConstants; import org.apache.pinot.common.utils.FileUploadDownloadClient; import org.apache.pinot.common.utils.JsonUtils; -import org.apache.pinot.common.utils.StringUtil; import org.apache.pinot.common.utils.URIUtils; import org.apache.pinot.common.utils.helix.HelixHelper; import org.apache.pinot.controller.ControllerConf; @@ -82,8 +79,6 @@ import org.apache.pinot.core.crypt.PinotCrypter; import org.apache.pinot.core.crypt.PinotCrypterFactory; import org.apache.pinot.core.metadata.DefaultMetadataExtractor; import org.apache.pinot.core.metadata.MetadataExtractorFactory; -import org.apache.pinot.filesystem.PinotFS; -import org.apache.pinot.filesystem.PinotFSFactory; import org.glassfish.grizzly.http.server.Request; import org.glassfish.jersey.media.multipart.FormDataBodyPart; import org.glassfish.jersey.media.multipart.FormDataMultiPart; @@ -98,7 +93,6 @@ public class PinotSegmentUploadRestletResource { private static final Logger LOGGER = LoggerFactory.getLogger(PinotSegmentUploadRestletResource.class); private static final String TMP_DIR_PREFIX = "tmp-"; private static final String ENCRYPTED_SUFFIX = "_encrypted"; - private static final String URL_ENCODING_SCHEME = "UTF-8"; @Inject PinotHelixResourceManager _pinotHelixResourceManager; @@ -166,7 +160,7 @@ public class PinotSegmentUploadRestletResource { public Response downloadSegment( @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "Name of the segment", required = true) @PathParam("segmentName") @Encoded String segmentName, - @Context HttpHeaders httpHeaders) throws Exception { + @Context HttpHeaders httpHeaders) { // Validate data access boolean hasDataAccess; try { @@ -188,34 +182,14 @@ public class PinotSegmentUploadRestletResource { throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e); } segmentName = URIUtils.decode(segmentName); - final URI segmentFileURI = URIUtils.getUri(provider.getBaseDataDirURI().toString(), tableName, segmentName); - PinotFS pinotFS = PinotFSFactory.create(provider.getBaseDataDirURI().getScheme()); - - if (!pinotFS.exists(segmentFileURI)) { + File dataFile = new File(provider.getBaseDataDir(), String.join(File.separator, tableName, segmentName)); + if (!dataFile.exists()) { throw new ControllerApplicationException(LOGGER, - "Segment " + segmentName + " or table " + tableName + " not found in " + segmentFileURI.toString(), Response.Status.NOT_FOUND); - } - Response.ResponseBuilder builder = Response.ok(); - File segmentFile; - // If the segment file is local, just use it as the return entity; otherwise copy it from remote to local first. - if (CommonConstants.Segment.LOCAL_SEGMENT_SCHEME.equals(segmentFileURI.getScheme())) { - segmentFile = new File(provider.getBaseDataDir(), StringUtil.join("/", tableName, segmentName)); - builder.entity(segmentFile); - } else { - segmentFile = new File(StringUtil.join("/", _controllerConf.getLocalTempDir(), tableName, - StringUtil.join("_", segmentName, String.valueOf(System.nanoTime())))); - pinotFS.copyToLocalFile(segmentFileURI, segmentFile); - // Streaming in the tmp file and delete it afterward. - builder.entity((StreamingOutput) output -> { - try { - Files.copy(segmentFile.toPath(), output); - } finally { - FileUtils.deleteQuietly(segmentFile); - } - }); + "Segment " + segmentName + " or table " + tableName + " not found", Response.Status.NOT_FOUND); } - builder.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + segmentFile.getName()); - builder.header(HttpHeaders.CONTENT_LENGTH, segmentFile.length()); + Response.ResponseBuilder builder = Response.ok(dataFile); + builder.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + dataFile.getName()); + builder.header(HttpHeaders.CONTENT_LENGTH, dataFile.length()); return builder.build(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
