-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Make GoogleCloudStorageRetryingInputStream request same generation on resume #127626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make GoogleCloudStorageRetryingInputStream request same generation on resume #127626
Conversation
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
Hi @nicktindall, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I just had the one question about the assertion in parseGenerationHeader()
, the rest were a few small nits. Might be good to get a look from other folks with GCS code experience though.
.../src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRetryingInputStream.java
Outdated
Show resolved
Hide resolved
test/fixtures/gcs-fixture/src/main/java/fixture/gcs/MockGcsBlobStore.java
Outdated
Show resolved
Hide resolved
test/fixtures/gcs-fixture/src/main/java/fixture/gcs/MockGcsBlobStore.java
Outdated
Show resolved
Hide resolved
test/fixtures/gcs-fixture/src/main/java/fixture/gcs/MockGcsBlobStore.java
Outdated
Show resolved
Hide resolved
…bStore.java Co-authored-by: Jeremy Dahlgren <[email protected]>
…bStore.java Co-authored-by: Jeremy Dahlgren <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# Conflicts: # modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRetryingInputStream.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The usages for the different generation parameters seem correct to me. It would be great if we can test the change against the real thing as well. Is it not viable?
public void testContentsChangeWhileStreaming() throws IOException { | ||
GoogleCloudStorageHttpHandler handler = new GoogleCloudStorageHttpHandler("bucket"); | ||
httpServer.createContext("/", handler); | ||
final int enoughBytesToTriggerChunkedDownload = Math.toIntExact(ByteSizeValue.ofMb(30).getBytes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind adding a comment to explain briefly how the size of 30mb is decided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is actually incorrect (I don't think the current client does any chunking for downloads, only uploads). We just need to ensure the blob is large enough that it doesn't get entirely buffered when we read the first byte. This is probably a TCP level thing because as far as I can see the google or Java HTTP infrastructure merely relies on the underlying JVM/OS behaviour. I did some experiments locally and 2MB is usually enough to exceed the buffer, so 30M should be fairly conservative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ce03dae
@@ -212,6 +217,11 @@ public HttpRequestInitializer getHttpRequestInitializer(ServiceOptions<?, ?> ser | |||
); | |||
} | |||
|
|||
@Override | |||
protected void addSuccessfulDownloadHeaders(HttpExchange exchange) { | |||
exchange.getResponseHeaders().add("x-goog-generation", "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the actual generation number does not matter, can we randomize it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2d2960c
InetSocketAddress currentAddress = httpServer.getAddress(); | ||
httpServer.stop(0); | ||
httpServer = MockHttpServer.createHttp(currentAddress, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether rebinding to the same address can be flaky sometimes. We can have it as is for now and see how it goes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be OK as long as we have SO_REUSEADDR
set? It seemed to work locally so perhaps that's the default?
There are assertions confirming that we do receive the It would be tricky to write a test where the generation failed against the real store because we'd need to somehow interrupt the stream to trigger a second request back to the server. I think that'd require some proxying or something. I think the assertions confirming the header is present and the tests simulating the resume interaction should be sufficient? |
Yeah that is what I had in mind, e.g. WebProxyServer. The assertion fo For my knowledge, what is the behaviour when there is no connection interuption and the blob gets overwrite midway? |
That doesn't appear to be specified, I imagine as long as the download is not interrupted it would probably complete, but I haven't been able to test that. I'll see if I can run locally against the real blob store, there might be an easy way to test it. |
I added an integration test using the proxy in eebcb0c I think it's actually important to do because the documents are inconsistent about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for adding the 3rd party test.
@@ -26,19 +27,16 @@ | |||
*/ | |||
abstract class MockHttpProxyServer implements Closeable { | |||
|
|||
private final HttpServer httpServer; | |||
private HttpServer httpServer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this field volatile to avoid have to think about visibility? Technically we restart the server on a generic thread and shutdown at test cleanup time in a different thread.
…ume' into ES-11432_check_generation_on_resume
When we resume a download due to an IOException, we now specify the generation of the object that we were originally downloading in the request so that we can detect if the object changed.
Some decisions that were made
generation
parameter rather thanifGenerationMatch
. The former requests a specific generation where the latter requests the latest generation and triggers an error if its not the one specified. This distinction is only important if the bucket we're fetching from has object versioning enabled. If the object is overwritten and object versioning is enabled, resume withgeneration
specified will succeed because the prior version will still be available, but resume withifGenerationMatch
specified would fail because the latest version is no longer the one we were downloading.ifMetagenerationMatch
orEtag
s instead, but I don't think we want that.Closes ES-11432
I marked this PR as "non-issue" because currently we never update objects with different contents. This is just future proofing.