-
Notifications
You must be signed in to change notification settings - Fork 3.8k
GCS lookup support #11026
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
Merged
Merged
GCS lookup support #11026
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...ons/src/main/java/org/apache/druid/storage/google/GoogleTimestampVersionedDataFinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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.druid.storage.google; | ||
|
|
||
| import com.google.api.services.storage.model.Objects; | ||
| import com.google.api.services.storage.model.StorageObject; | ||
| import com.google.inject.Inject; | ||
| import org.apache.druid.data.SearchableVersionedDataFinder; | ||
| import org.apache.druid.data.input.impl.CloudObjectLocation; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class GoogleTimestampVersionedDataFinder extends GoogleDataSegmentPuller | ||
| implements SearchableVersionedDataFinder<URI> | ||
| { | ||
| private static final long MAX_LISTING_KEYS = 1000; | ||
|
|
||
| @Inject | ||
| public GoogleTimestampVersionedDataFinder(final GoogleStorage storage) | ||
| { | ||
| super(storage); | ||
| } | ||
|
|
||
| @Override | ||
| public URI getLatestVersion(URI descriptorBase, @Nullable Pattern pattern) | ||
| { | ||
| try { | ||
| long mostRecent = Long.MIN_VALUE; | ||
| URI latest = null; | ||
| final CloudObjectLocation baseLocation = new CloudObjectLocation(descriptorBase); | ||
| final Objects objects = storage.list(baseLocation.getBucket()).setPrefix(baseLocation.getPath()).setMaxResults(MAX_LISTING_KEYS).execute(); | ||
| for (StorageObject storageObject : objects.getItems()) { | ||
| if (GoogleUtils.isDirectoryPlaceholder(storageObject)) { | ||
| continue; | ||
| } | ||
| // remove path prefix from file name | ||
| final CloudObjectLocation objectLocation = new CloudObjectLocation(storageObject.getBucket(), | ||
| storageObject.getName() | ||
| ); | ||
| final String keyString = StringUtils | ||
| .maybeRemoveLeadingSlash(storageObject.getName().substring(baseLocation.getPath().length())); | ||
| if (pattern != null && !pattern.matcher(keyString).matches()) { | ||
| continue; | ||
| } | ||
| final long latestModified = storageObject.getUpdated().getValue(); | ||
| if (latestModified >= mostRecent) { | ||
| mostRecent = latestModified; | ||
| latest = objectLocation.toUri(GoogleStorageDruidModule.SCHEME_GS); | ||
| } | ||
| } | ||
| return latest; | ||
| } | ||
| catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...src/test/java/org/apache/druid/storage/google/GoogleTimestampVersionedDataFinderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * 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.druid.storage.google; | ||
|
|
||
| import com.google.api.client.util.DateTime; | ||
| import com.google.api.services.storage.model.StorageObject; | ||
| import com.google.common.collect.ImmutableList; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class GoogleTimestampVersionedDataFinderTest | ||
| { | ||
| @Test | ||
| public void getLatestVersion() | ||
| { | ||
| String bucket = "bucket"; | ||
| String keyPrefix = "prefix/dir/0"; | ||
|
|
||
| // object for directory prefix/dir/0/ | ||
| final StorageObject storageObject1 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "//", 0); | ||
| storageObject1.setUpdated(new DateTime(System.currentTimeMillis())); | ||
| final StorageObject storageObject2 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v1", 1); | ||
| storageObject2.setUpdated(new DateTime(System.currentTimeMillis())); | ||
| final StorageObject storageObject3 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v2", 1); | ||
| storageObject3.setUpdated(new DateTime(System.currentTimeMillis() + 100)); | ||
| final StorageObject storageObject4 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/other", 4); | ||
| storageObject4.setUpdated(new DateTime(System.currentTimeMillis() + 100)); | ||
| final GoogleStorage storage = ObjectStorageIteratorTest.makeMockClient(ImmutableList.of(storageObject1, storageObject2, storageObject3, storageObject4)); | ||
|
|
||
| final GoogleTimestampVersionedDataFinder finder = new GoogleTimestampVersionedDataFinder(storage); | ||
| Pattern pattern = Pattern.compile("v.*"); | ||
| URI latest = finder.getLatestVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, keyPrefix)), pattern); | ||
| URI expected = URI.create(StringUtils.format("gs://%s/%s", bucket, storageObject3.getName())); | ||
| Assert.assertEquals(expected, latest); | ||
| } | ||
|
|
||
| @Test | ||
| public void getLatestVersionTrailingSlashKeyPrefix() | ||
| { | ||
| String bucket = "bucket"; | ||
| String keyPrefix = "prefix/dir/0/"; | ||
|
|
||
| // object for directory prefix/dir/0/ | ||
| final StorageObject storageObject1 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/", 0); | ||
| storageObject1.setUpdated(new DateTime(System.currentTimeMillis())); | ||
| final StorageObject storageObject2 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "v1", 1); | ||
| storageObject2.setUpdated(new DateTime(System.currentTimeMillis())); | ||
| final StorageObject storageObject3 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "v2", 1); | ||
| storageObject3.setUpdated(new DateTime(System.currentTimeMillis() + 100)); | ||
| final StorageObject storageObject4 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "other", 4); | ||
| storageObject4.setUpdated(new DateTime(System.currentTimeMillis() + 100)); | ||
| final GoogleStorage storage = ObjectStorageIteratorTest.makeMockClient(ImmutableList.of(storageObject1, storageObject2, storageObject3, storageObject4)); | ||
|
|
||
| final GoogleTimestampVersionedDataFinder finder = new GoogleTimestampVersionedDataFinder(storage); | ||
| Pattern pattern = Pattern.compile("v.*"); | ||
| URI latest = finder.getLatestVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, keyPrefix)), pattern); | ||
| URI expected = URI.create(StringUtils.format("gs://%s/%s", bucket, storageObject3.getName())); | ||
| Assert.assertEquals(expected, latest); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.