-
Notifications
You must be signed in to change notification settings - Fork 260
[Backport Fix to staging-2.2.x]: Prevent Hadoop directory copy failures by correctly setting generation id Preconditions #1466
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
base: staging-2.2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,9 @@ | |
| import com.google.cloud.hadoop.gcsio.GoogleCloudStorageReadOptions.Fadvise; | ||
| import com.google.cloud.hadoop.gcsio.integration.GoogleCloudStorageTestHelper; | ||
| import com.google.cloud.hadoop.util.GrpcErrorTypeExtractor; | ||
| import com.google.cloud.storage.BlobId; | ||
| import com.google.cloud.storage.Storage; | ||
| import com.google.cloud.storage.Storage.BlobSourceOption; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.protobuf.ByteString; | ||
| import java.io.EOFException; | ||
|
|
@@ -200,6 +202,59 @@ public void readFullObject() throws IOException { | |
| verifyNoMoreInteractions(fakeReadChannel); | ||
| } | ||
|
|
||
| @Test | ||
| public void read_withPositiveGeneration_usesGenerationMatchPrecondition() throws IOException { | ||
| long generation = 12345L; | ||
| GoogleCloudStorageItemInfo itemInfo = | ||
| GoogleCloudStorageItemInfo.createObject( | ||
| new StorageResourceId(V1_BUCKET_NAME, OBJECT_NAME, generation), | ||
| /* creationTime= */ 10L, | ||
| /* modificationTime= */ 15L, | ||
| /* size= */ OBJECT_SIZE, | ||
| /* contentType= */ "text/plain", | ||
| /* contentEncoding= */ "text", | ||
| /* metadata= */ null, | ||
| /* contentGeneration= */ generation, | ||
| /* metaGeneration= */ 2L, | ||
| /* verificationAttributes= */ null); | ||
|
|
||
| readChannel = getJavaStorageChannel(itemInfo, DEFAULT_READ_OPTION); | ||
| readChannel.read(ByteBuffer.allocate(1)); | ||
|
|
||
| ArgumentCaptor<BlobSourceOption> optionsCaptor = | ||
| ArgumentCaptor.forClass(BlobSourceOption.class); | ||
| verify(mockedStorage).reader(any(BlobId.class), optionsCaptor.capture()); | ||
|
|
||
| assertThat(optionsCaptor.getAllValues()).contains(BlobSourceOption.generationMatch(generation)); | ||
| } | ||
|
|
||
| @Test | ||
| public void read_withZeroGeneration_doesNotUseGenerationMatchPrecondition() throws IOException { | ||
| long generation = 0L; | ||
| GoogleCloudStorageItemInfo itemInfo = | ||
| GoogleCloudStorageItemInfo.createObject( | ||
| new StorageResourceId(V1_BUCKET_NAME, OBJECT_NAME, generation), | ||
| /* creationTime= */ 10L, | ||
| /* modificationTime= */ 15L, | ||
| /* size= */ OBJECT_SIZE, | ||
| /* contentType= */ "text/plain", | ||
| /* contentEncoding= */ "text", | ||
| /* metadata= */ null, | ||
| /* contentGeneration= */ generation, | ||
| /* metaGeneration= */ 2L, | ||
| /* verificationAttributes= */ null); | ||
|
|
||
| readChannel = getJavaStorageChannel(itemInfo, DEFAULT_READ_OPTION); | ||
| readChannel.read(ByteBuffer.allocate(1)); | ||
|
|
||
| ArgumentCaptor<BlobSourceOption> optionsCaptor = | ||
| ArgumentCaptor.forClass(BlobSourceOption.class); | ||
| verify(mockedStorage).reader(any(BlobId.class), optionsCaptor.capture()); | ||
|
|
||
| assertThat(optionsCaptor.getAllValues()) | ||
| .doesNotContain(BlobSourceOption.generationMatch(generation)); | ||
| } | ||
|
Comment on lines
+231
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test |
||
|
|
||
| @Test | ||
| public void fadviseAuto_onForwardRead_switchesToRandom() throws IOException { | ||
| int chunkSize = FakeReadChannel.CHUNK_SIZE; | ||
|
|
||
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.
This condition
resourceId.hasGenerationId() && resourceId.getGenerationId() > 0is also used ininitMetadata(line 778) andcreateMetadataRequest(line 1152). To improve maintainability and reduce duplication, consider extracting this logic into a private helper method, for exampleshouldUseGenerationId().