Browse Source

Take into account range start to compute the current stream end on url repositories. (#70509)

Closes #70310
Francisco Fernández Castaño 4 years ago
parent
commit
b1c4cb4451

+ 5 - 0
modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/http/HttpURLBlobContainer.java

@@ -12,6 +12,7 @@ import org.elasticsearch.common.blobstore.BlobPath;
 import org.elasticsearch.common.blobstore.url.URLBlobContainer;
 import org.elasticsearch.common.blobstore.url.URLBlobStore;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -33,6 +34,10 @@ public class HttpURLBlobContainer extends URLBlobContainer {
 
     @Override
     public InputStream readBlob(String name, long position, long length) throws IOException {
+        if (length == 0) {
+            return new ByteArrayInputStream(new byte[0]);
+        }
+
         return new RetryingHttpInputStream(name,
             getURIForBlob(name),
             position,

+ 1 - 1
modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/http/RetryingHttpInputStream.java

@@ -220,7 +220,7 @@ class RetryingHttpInputStream extends InputStream {
                             " Status code: [" + statusCode + "] - Body: " + body));
                     }
 
-                    currentStreamLastOffset = getStreamLength(response);
+                    currentStreamLastOffset = Math.addExact(Math.addExact(start, totalBytesRead), getStreamLength(response));
 
                     return response.getInputStream();
                 } catch (URLHttpClientException e) {

+ 0 - 6
modules/repository-url/src/test/java/org/elasticsearch/common/blobstore/url/URLBlobContainerRetriesTests.java

@@ -41,12 +41,6 @@ public class URLBlobContainerRetriesTests extends AbstractBlobContainerRetriesTe
         factory.close();
     }
 
-    @Override
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/70310")
-    public void testReadRangeBlobWithRetries() {
-
-    }
-
     @Override
     protected String downloadStorageEndpoint(String blob) {
         return "/" + blob;