mcvsubbu commented on a change in pull request #5314: URL: https://github.com/apache/incubator-pinot/pull/5314#discussion_r418222957
########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { + private Logger LOGGER = LoggerFactory.getLogger(BestEffortSegmentUploader.class); + private String _segmentStoreUriStr; + private ExecutorService _executorService = Executors.newCachedThreadPool(); + // The default segment location URI to return if the upload fails. + private URI _defaultSegmentLocationURI; + private int _timeoutInMs; + + public BestEffortSegmentUploader(String segmentStoreUriStr, int timeoutInMs, String defaultSegment) { + _segmentStoreUriStr = segmentStoreUriStr; + _timeoutInMs = timeoutInMs; + _defaultSegmentLocationURI = URI.create(defaultSegment); + } + + public URI uploadSegment(File segmentFile, String tableNameWithType, String segmentName) { + if (_segmentStoreUriStr == null || _segmentStoreUriStr.isEmpty()) { + return _defaultSegmentLocationURI; + } + + Callable<URI> uploadTask = () -> { + try { + PinotFS pinotFS = PinotFSFactory.create(new URI(_segmentStoreUriStr).getScheme()); + URI destUri = new URI(StringUtil.join(File.separator, _segmentStoreUriStr, tableNameWithType, segmentName)); + // Check and delete any existing segment file. + if (pinotFS.exists(destUri)) { + pinotFS.delete(destUri, true); + } + pinotFS.copyFromLocalFile(segmentFile, destUri); + return destUri; + } catch (Exception e) { + LOGGER.error("Failed copy segment tar file to segment store {}: {}", segmentFile.getName(), e); + } + return _defaultSegmentLocationURI; + }; + Future<URI> future = _executorService.submit(uploadTask); + try { + URI segmentLocation = future.get(_timeoutInMs, TimeUnit.MILLISECONDS); + return segmentLocation; + } catch (Exception e) { Review comment: InterruptedException should be OK, if the service is being shutdown ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { + private Logger LOGGER = LoggerFactory.getLogger(BestEffortSegmentUploader.class); + private String _segmentStoreUriStr; + private ExecutorService _executorService = Executors.newCachedThreadPool(); + // The default segment location URI to return if the upload fails. + private URI _defaultSegmentLocationURI; + private int _timeoutInMs; + + public BestEffortSegmentUploader(String segmentStoreUriStr, int timeoutInMs, String defaultSegment) { Review comment: ```suggestion public BestEffortSegmentUploader(String segmentStoreDirUri, int timeoutMillis, String defaultSegment) { ``` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { Review comment: ```suggestion public class PinotFSSegmentUploader implements SegmentUploader { ``` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { + private Logger LOGGER = LoggerFactory.getLogger(BestEffortSegmentUploader.class); + private String _segmentStoreUriStr; + private ExecutorService _executorService = Executors.newCachedThreadPool(); + // The default segment location URI to return if the upload fails. + private URI _defaultSegmentLocationURI; + private int _timeoutInMs; + + public BestEffortSegmentUploader(String segmentStoreUriStr, int timeoutInMs, String defaultSegment) { Review comment: can u javadoc the arguments? What is `defaultSegment`? Maybe call it defaultSegmentURI and define it as URI type? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { + private Logger LOGGER = LoggerFactory.getLogger(BestEffortSegmentUploader.class); + private String _segmentStoreUriStr; + private ExecutorService _executorService = Executors.newCachedThreadPool(); + // The default segment location URI to return if the upload fails. + private URI _defaultSegmentLocationURI; + private int _timeoutInMs; + + public BestEffortSegmentUploader(String segmentStoreUriStr, int timeoutInMs, String defaultSegment) { + _segmentStoreUriStr = segmentStoreUriStr; + _timeoutInMs = timeoutInMs; + _defaultSegmentLocationURI = URI.create(defaultSegment); + } + + public URI uploadSegment(File segmentFile, String tableNameWithType, String segmentName) { + if (_segmentStoreUriStr == null || _segmentStoreUriStr.isEmpty()) { + return _defaultSegmentLocationURI; + } + + Callable<URI> uploadTask = () -> { + try { + PinotFS pinotFS = PinotFSFactory.create(new URI(_segmentStoreUriStr).getScheme()); + URI destUri = new URI(StringUtil.join(File.separator, _segmentStoreUriStr, tableNameWithType, segmentName)); + // Check and delete any existing segment file. + if (pinotFS.exists(destUri)) { + pinotFS.delete(destUri, true); + } + pinotFS.copyFromLocalFile(segmentFile, destUri); + return destUri; + } catch (Exception e) { + LOGGER.error("Failed copy segment tar file to segment store {}: {}", segmentFile.getName(), e); Review comment: Not sure if this should be logged as an error, since we have recovery mechanisms. Warning should be ok. We should log an error in higher layers if we just cannot recover from this ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as Review comment: Better to separate the default uri functionality. If the uploader.upload fails, it always returns null (have a consistent javaoc in `SegmentUploader` interface). The caller can decide whether default is needed. In this case, the split committer should decide that. ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/Server2ControllerSegmentUploader.java ########## @@ -52,7 +52,7 @@ public Server2ControllerSegmentUploader(Logger segmentLogger, FileUploadDownload } @Override - public URI uploadSegment(File segmentFile) { + public URI uploadSegment(File segmentFile, String tableName, String segmentName) { Review comment: ```suggestion public URI uploadSegment(File segmentFile, LLCSegmentName segmentName) { ``` `segmentName` already has the (raw) tableName. ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/BestEffortSegmentUploader.java ########## @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import java.net.URI; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.spi.filesystem.PinotFS; +import org.apache.pinot.spi.filesystem.PinotFSFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// A segment uploader which does best effort segment upload to a segment store (with store root dir configured as +// _segmentStoreUriStr). The upload is successful if it is done within a configurable timeout period. +// The final segment location would be in the URI _segmentStoreUriStr/_tableNameWithType/segmentName if +// successful. If a segment upload fails or there is no segment store uri configured, it sets the segment location as +// the default URI. +public class BestEffortSegmentUploader implements SegmentUploader { + private Logger LOGGER = LoggerFactory.getLogger(BestEffortSegmentUploader.class); + private String _segmentStoreUriStr; + private ExecutorService _executorService = Executors.newCachedThreadPool(); + // The default segment location URI to return if the upload fails. + private URI _defaultSegmentLocationURI; + private int _timeoutInMs; + + public BestEffortSegmentUploader(String segmentStoreUriStr, int timeoutInMs, String defaultSegment) { + _segmentStoreUriStr = segmentStoreUriStr; + _timeoutInMs = timeoutInMs; + _defaultSegmentLocationURI = URI.create(defaultSegment); + } + + public URI uploadSegment(File segmentFile, String tableNameWithType, String segmentName) { + if (_segmentStoreUriStr == null || _segmentStoreUriStr.isEmpty()) { + return _defaultSegmentLocationURI; + } + + Callable<URI> uploadTask = () -> { + try { + PinotFS pinotFS = PinotFSFactory.create(new URI(_segmentStoreUriStr).getScheme()); + URI destUri = new URI(StringUtil.join(File.separator, _segmentStoreUriStr, tableNameWithType, segmentName)); + // Check and delete any existing segment file. + if (pinotFS.exists(destUri)) { + pinotFS.delete(destUri, true); + } + pinotFS.copyFromLocalFile(segmentFile, destUri); + return destUri; + } catch (Exception e) { + LOGGER.error("Failed copy segment tar file to segment store {}: {}", segmentFile.getName(), e); + } + return _defaultSegmentLocationURI; + }; + Future<URI> future = _executorService.submit(uploadTask); + try { + URI segmentLocation = future.get(_timeoutInMs, TimeUnit.MILLISECONDS); + return segmentLocation; + } catch (Exception e) { + LOGGER.error("Failed to upload file {} of segment {} for table {} ", segmentFile.getAbsolutePath(), segmentName, Review comment: same comment here about error. Will we be logging 2 error messages? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org