You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "gargvishesh (via GitHub)" <gi...@apache.org> on 2023/11/20 04:16:25 UTC

[PR] 35053-gcs-durable-storage-connector (druid)

gargvishesh opened a new pull request, #15398:
URL: https://github.com/apache/druid/pull/15398

   <!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
   
   <!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
   
   Fixes #XXXX.
   
   <!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
   
   <!-- If you are a committer, follow the PR action item checklist for committers:
   https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
   
   ### Description
   
   <!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
   
   <!-- Describe your patch: what did you change in code? How did you fix the problem? -->
   
   <!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
   
   #### Fixed the bug ...
   #### Renamed the class ...
   #### Added a forbidden-apis entry ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   #### Release note
   <!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users. 
   
   If your change doesn't have end user impact, you can skip this section.
   
   For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
   
   -->
   
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `MyFoo`
    * `OurBar`
    * `TheirBaz`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "gargvishesh (via GitHub)" <gi...@apache.org>.
gargvishesh commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1424845218


##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleStorageConnector.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.output;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import org.apache.druid.data.input.impl.CloudObjectLocation;
+import org.apache.druid.data.input.impl.prefetch.ObjectOpenFunction;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.storage.google.GoogleInputDataConfig;
+import org.apache.druid.storage.google.GoogleStorage;
+import org.apache.druid.storage.google.GoogleStorageDruidModule;
+import org.apache.druid.storage.google.GoogleStorageObjectMetadata;
+import org.apache.druid.storage.google.GoogleUtils;
+import org.apache.druid.storage.remote.ChunkingStorageConnector;
+import org.apache.druid.storage.remote.ChunkingStorageConnectorParameters;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+public class GoogleStorageConnector extends ChunkingStorageConnector<GoogleInputRange>

Review Comment:
   Added for this and some other classes as well.



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/ObjectStorageIterator.java:
##########
@@ -91,35 +75,35 @@ public boolean hasNext()
   }
 
   @Override
-  public StorageObject next()
+  public GoogleStorageObjectMetadata next()
   {
     if (!hasNext()) {
       throw new NoSuchElementException();
     }
 
-    final StorageObject retVal = currentObject;
+    final GoogleStorageObjectMetadata retVal = currentObject;
     advanceStorageObject();
     return retVal;
   }
 
   private void advanceStorageObject()
   {
-    while (storageObjectsIterator.hasNext() || nextPageToken != null || uris.hasNext()) {
-      while (storageObjectsIterator.hasNext()) {
-        final StorageObject next = storageObjectsIterator.next();
+    while (blobIterator.hasNext() || nextPageToken != null || uris.hasNext()) {
+      while (blobIterator.hasNext()) {
+        final GoogleStorageObjectMetadata next = blobIterator.next();
         // list with prefix can return directories, but they should always end with `/`, ignore them.
         // also skips empty objects.
-        if (!next.getName().endsWith("/") && next.getSize().signum() > 0) {
+        if (!next.getName().endsWith("/") && Long.signum(next.getSize()) > 0) {

Review Comment:
   This is more a check meant for != 0



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleInputRange.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.output;
+
+import java.util.Objects;
+
+public class GoogleInputRange
+{
+  private final long start;
+  private final long size;
+  private final String bucket;
+  private final String path;
+
+  public GoogleInputRange(long start, long size, String bucket, String path)
+  {
+    this.start = start;
+    this.size = size;
+    this.bucket = bucket;
+    this.path = path;
+  }
+
+  public long getStart()
+  {
+    return start;
+  }
+
+  public long getSize()
+  {
+    return size;
+  }
+
+  public String getBucket()
+  {
+    return bucket;
+  }
+
+  public String getPath()
+  {
+    return path;
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+    GoogleInputRange that = (GoogleInputRange) o;
+    return start == that.start
+           && size == that.size
+           && Objects.equals(bucket, that.bucket)
+           && Objects.equals(path, that.path);
+  }
+

Review Comment:
   Done



##########
extensions-core/google-extensions/pom.xml:
##########
@@ -48,16 +48,11 @@
         </dependency>
 
         <dependency>
-            <groupId>com.google.apis</groupId>

Review Comment:
   Removed now.



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleStorage.java:
##########
@@ -36,69 +47,137 @@ public class GoogleStorage
    * if we have a Storage instead of a supplier of it, it can cause unnecessary config validation
    * against Google storage even when it's not used at all. To perform the config validation
    * only when it is actually used, we use a supplier.
-   *
+   * <p>
    * See OmniDataSegmentKiller for how DataSegmentKillers are initialized.
    */
   private final Supplier<Storage> storage;
 
-  public GoogleStorage(Supplier<Storage> storage)
+  public GoogleStorage(final Supplier<Storage> storage)
   {
     this.storage = storage;
   }
 
   public void insert(final String bucket, final String path, AbstractInputStreamContent mediaContent) throws IOException
   {
-    Storage.Objects.Insert insertObject = storage.get().objects().insert(bucket, null, mediaContent);
-    insertObject.setName(path);
-    insertObject.getMediaHttpUploader().setDirectUploadEnabled(false);
-    insertObject.execute();
+    storage.get().createFrom(getBlobInfo(bucket, path), mediaContent.getInputStream());
   }
 
-  public InputStream get(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path) throws IOException
   {
-    return get(bucket, path, 0);
+    return getInputStream(bucket, path, 0, null);
   }
 
-  public InputStream get(final String bucket, final String path, long start) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start) throws IOException
   {
-    final Get get = storage.get().objects().get(bucket, path);
-    InputStream inputStream = get.executeMediaAsInputStream();
-    inputStream.skip(start);
-    return inputStream;
+    return getInputStream(bucket, path, start, null);
   }
 
-  public StorageObject getMetadata(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start, @Nullable Long length)
+      throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute();
+    ReadChannel reader = storage.get().reader(bucket, path);
+    reader.seek(start);
+    if (length != null) {
+      reader.limit(start + length);
+    }
+    return Channels.newInputStream(reader);
+  }
+
+  public OutputStream getObjectOutputStream(
+      final String bucket,
+      final String path
+  )
+  {
+    WriteChannel writer = storage.get().writer(getBlobInfo(bucket, path));
+    return Channels.newOutputStream(writer);
+  }
+
+  public GoogleStorageObjectMetadata getMetadata(
+      final String bucket,
+      final String path
+  )
+  {
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.values()));
+    return new GoogleStorageObjectMetadata(
+        blob.getBucket(),
+        blob.getName(),
+        blob.getSize(),
+        blob.getUpdateTimeOffsetDateTime()
+            .toEpochSecond()
+    );
   }
 
   public void delete(final String bucket, final String path) throws IOException
   {
-    storage.get().objects().delete(bucket, path).execute();
+    storage.get().delete(bucket, path);
   }
 
   public boolean exists(final String bucket, final String path)
   {
-    try {
-      return storage.get().objects().get(bucket, path).executeUsingHead().isSuccessStatusCode();
-    }
-    catch (Exception e) {
-      return false;
-    }
+
+    Blob blob = storage.get().get(bucket, path);
+    return blob != null;
   }
-   
+
   public long size(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getSize().longValue();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.SIZE));
+    return blob.getSize();
   }
 
   public String version(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getEtag();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.GENERATION));
+    return blob.getGeneratedId();
+  }
+
+  public GoogleStorageObjectPage list(

Review Comment:
   Done.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] 35053-gcs-durable-storage-connector (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1400447197


##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/ObjectStorageIteratorTest.java:
##########
@@ -194,70 +191,30 @@
    * Makes a mock Google Storage client that handles enough of "List" to test the functionality of the
    * {@link ObjectStorageIterator} class.
    */
-  static GoogleStorage makeMockClient(final List<StorageObject> storageObjects)
+  static GoogleStorage makeMockClient(final List<GoogleStorage.GoogleStorageObjectMetadata> storageObjects)
   {
     return new GoogleStorage(null)
     {
       @Override
-      public Storage.Objects.List list(final String bucket)
-      {
-        return mockList(bucket, storageObjects);
-      }
-    };
-  }
-
-  @SuppressWarnings("UnnecessaryFullyQualifiedName")
-  static class MockStorage extends Storage
-  {
-    private MockStorage()
-    {
-      super(
-          EasyMock.niceMock(HttpTransport.class),
-          EasyMock.niceMock(JsonFactory.class),
-          EasyMock.niceMock(HttpRequestInitializer.class)
-      );
-    }
-
-    private MockList mockList(String bucket, java.util.List<StorageObject> storageObjects)
-    {
-      return new MockObjects().mockList(bucket, storageObjects);
-    }
-
-    class MockObjects extends Storage.Objects
-    {
-      private MockList mockList(String bucket, java.util.List<StorageObject> storageObjects)
+      public GoogleStorageObjectPage list(
+          final String bucket, final String prefix, final Long pageSize, final String pageToken
+      )
       {
-        return new MockList(bucket, storageObjects);
-      }
-
-      class MockList extends Objects.List
-      {
-        private final java.util.List<StorageObject> storageObjects;
-
-        private MockList(String bucket, java.util.List<StorageObject> storageObjects)
-        {
-          super(bucket);
-          this.storageObjects = storageObjects;
-        }
-
-        @Override
-        public com.google.api.services.storage.model.Objects execute()
         {
           // Continuation token is an index in the "objects" list.
-          final String continuationToken = getPageToken();
-          final int startIndex = continuationToken == null ? 0 : Integer.parseInt(continuationToken);
+          final int startIndex = pageToken == null ? 0 : Integer.parseInt(pageToken);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5990)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe merged PR #15398:
URL: https://github.com/apache/druid/pull/15398


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on PR #15398:
URL: https://github.com/apache/druid/pull/15398#issuecomment-1854994245

   Thanks @gargvishesh for working on this. 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1423538766


##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleInputRange.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.output;
+
+import java.util.Objects;
+
+public class GoogleInputRange
+{
+  private final long start;
+  private final long size;
+  private final String bucket;
+  private final String path;
+
+  public GoogleInputRange(long start, long size, String bucket, String path)
+  {
+    this.start = start;
+    this.size = size;
+    this.bucket = bucket;
+    this.path = path;
+  }
+
+  public long getStart()
+  {
+    return start;
+  }
+
+  public long getSize()
+  {
+    return size;
+  }
+
+  public String getBucket()
+  {
+    return bucket;
+  }
+
+  public String getPath()
+  {
+    return path;
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+    GoogleInputRange that = (GoogleInputRange) o;
+    return start == that.start
+           && size == that.size
+           && Objects.equals(bucket, that.bucket)
+           && Objects.equals(path, that.path);
+  }
+

Review Comment:
   nit: Lets add a toString to this as well. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] 35053-gcs-durable-storage-connector (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1398657614


##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleTaskLogsTest.java:
##########
@@ -379,29 +377,29 @@
 
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, inputDataConfig, storage);
+    EasyMock.replay(inputDataConfig, storage);
 
     googleTaskLogs.killOlderThan(TIME_NOW);
 
-    EasyMock.verify(listRequest, inputDataConfig, storage);
+    EasyMock.verify(inputDataConfig, storage);
   }
 
   @Test
   public void test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorage.GoogleStorageObjectPage objectsPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectsPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5986)



##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentKillerTest.java:
##########
@@ -224,30 +225,30 @@
     EasyMock.expect(accountConfig.getPrefix()).andReturn(PREFIX).anyTimes();
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, accountConfig, inputDataConfig, storage);
+    EasyMock.replay(accountConfig, inputDataConfig, storage);
 
     GoogleDataSegmentKiller killer = new GoogleDataSegmentKiller(storage, accountConfig, inputDataConfig);
     killer.killAll();
 
-    EasyMock.verify(listRequest, accountConfig, inputDataConfig, storage);
+    EasyMock.verify(accountConfig, inputDataConfig, storage);
   }
 
   @Test
   public void test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorage.GoogleStorageObjectPage objectPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5984)



##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleTaskLogsTest.java:
##########
@@ -282,31 +280,31 @@
 
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, inputDataConfig, storage, timeSupplier);
+    EasyMock.replay(inputDataConfig, storage, timeSupplier);
 
     googleTaskLogs.killAll();
 
-    EasyMock.verify(listRequest, inputDataConfig, storage, timeSupplier);
+    EasyMock.verify(inputDataConfig, storage, timeSupplier);
   }
 
   @Test
   public void test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorage.GoogleStorageObjectPage objectsPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectsPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5985)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1409218199


##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleStorage.java:
##########
@@ -36,69 +47,137 @@ public class GoogleStorage
    * if we have a Storage instead of a supplier of it, it can cause unnecessary config validation
    * against Google storage even when it's not used at all. To perform the config validation
    * only when it is actually used, we use a supplier.
-   *
+   * <p>
    * See OmniDataSegmentKiller for how DataSegmentKillers are initialized.
    */
   private final Supplier<Storage> storage;
 
-  public GoogleStorage(Supplier<Storage> storage)
+  public GoogleStorage(final Supplier<Storage> storage)
   {
     this.storage = storage;
   }
 
   public void insert(final String bucket, final String path, AbstractInputStreamContent mediaContent) throws IOException
   {
-    Storage.Objects.Insert insertObject = storage.get().objects().insert(bucket, null, mediaContent);
-    insertObject.setName(path);
-    insertObject.getMediaHttpUploader().setDirectUploadEnabled(false);
-    insertObject.execute();
+    storage.get().createFrom(getBlobInfo(bucket, path), mediaContent.getInputStream());
   }
 
-  public InputStream get(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path) throws IOException
   {
-    return get(bucket, path, 0);
+    return getInputStream(bucket, path, 0, null);
   }
 
-  public InputStream get(final String bucket, final String path, long start) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start) throws IOException
   {
-    final Get get = storage.get().objects().get(bucket, path);
-    InputStream inputStream = get.executeMediaAsInputStream();
-    inputStream.skip(start);
-    return inputStream;
+    return getInputStream(bucket, path, start, null);
   }
 
-  public StorageObject getMetadata(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start, @Nullable Long length)
+      throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute();
+    ReadChannel reader = storage.get().reader(bucket, path);
+    reader.seek(start);
+    if (length != null) {
+      reader.limit(start + length);
+    }
+    return Channels.newInputStream(reader);
+  }
+
+  public OutputStream getObjectOutputStream(
+      final String bucket,
+      final String path
+  )
+  {
+    WriteChannel writer = storage.get().writer(getBlobInfo(bucket, path));
+    return Channels.newOutputStream(writer);
+  }
+
+  public GoogleStorageObjectMetadata getMetadata(
+      final String bucket,
+      final String path
+  )
+  {
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.values()));
+    return new GoogleStorageObjectMetadata(
+        blob.getBucket(),
+        blob.getName(),
+        blob.getSize(),
+        blob.getUpdateTimeOffsetDateTime()
+            .toEpochSecond()
+    );
   }
 
   public void delete(final String bucket, final String path) throws IOException
   {
-    storage.get().objects().delete(bucket, path).execute();
+    storage.get().delete(bucket, path);
   }
 
   public boolean exists(final String bucket, final String path)
   {
-    try {
-      return storage.get().objects().get(bucket, path).executeUsingHead().isSuccessStatusCode();
-    }
-    catch (Exception e) {
-      return false;
-    }
+
+    Blob blob = storage.get().get(bucket, path);
+    return blob != null;
   }
-   
+
   public long size(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getSize().longValue();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.SIZE));
+    return blob.getSize();
   }
 
   public String version(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getEtag();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.GENERATION));
+    return blob.getGeneratedId();
+  }
+
+  public GoogleStorageObjectPage list(
+      final String bucket,
+      @Nullable final String prefix,
+      @Nullable final Long pageSize,
+      @Nullable final String pageToken
+  ) throws IOException
+  {
+    List<Storage.BlobListOption> options = new ArrayList<>();
+
+    if (prefix != null) {
+      options.add(Storage.BlobListOption.prefix(prefix));
+    }
+
+    if (pageSize != null) {
+      options.add(Storage.BlobListOption.pageSize(pageSize));
+    }
+
+    if (pageToken != null) {
+      options.add(Storage.BlobListOption.pageToken(pageToken));
+    }
+
+    Page<Blob> blobPage = storage.get().list(bucket, options.toArray(new Storage.BlobListOption[0]));
+
+    List<GoogleStorageObjectMetadata> googleStorageObjectMetadataList =
+        blobPage.streamValues()
+                .map(blob -> new GoogleStorageObjectMetadata(
+                    blob.getBucket(),
+                    blob.getName(),
+                    blob.getSize(),
+                    blob.getUpdateTimeOffsetDateTime()
+                        .toEpochSecond()
+                ))
+                .collect(Collectors.toList());
+
+    return new GoogleStorageObjectPage(googleStorageObjectMetadataList, blobPage.getNextPageToken());
+
   }
 
-  public Storage.Objects.List list(final String bucket) throws IOException
+  public void batchDelete(final String bucket, final Iterable<String> paths)

Review Comment:
   Nit: could you java doc this. 



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleStorage.java:
##########
@@ -36,69 +47,137 @@ public class GoogleStorage
    * if we have a Storage instead of a supplier of it, it can cause unnecessary config validation
    * against Google storage even when it's not used at all. To perform the config validation
    * only when it is actually used, we use a supplier.
-   *
+   * <p>
    * See OmniDataSegmentKiller for how DataSegmentKillers are initialized.
    */
   private final Supplier<Storage> storage;
 
-  public GoogleStorage(Supplier<Storage> storage)
+  public GoogleStorage(final Supplier<Storage> storage)
   {
     this.storage = storage;
   }
 
   public void insert(final String bucket, final String path, AbstractInputStreamContent mediaContent) throws IOException
   {
-    Storage.Objects.Insert insertObject = storage.get().objects().insert(bucket, null, mediaContent);
-    insertObject.setName(path);
-    insertObject.getMediaHttpUploader().setDirectUploadEnabled(false);
-    insertObject.execute();
+    storage.get().createFrom(getBlobInfo(bucket, path), mediaContent.getInputStream());
   }
 
-  public InputStream get(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path) throws IOException
   {
-    return get(bucket, path, 0);
+    return getInputStream(bucket, path, 0, null);
   }
 
-  public InputStream get(final String bucket, final String path, long start) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start) throws IOException
   {
-    final Get get = storage.get().objects().get(bucket, path);
-    InputStream inputStream = get.executeMediaAsInputStream();
-    inputStream.skip(start);
-    return inputStream;
+    return getInputStream(bucket, path, start, null);
   }
 
-  public StorageObject getMetadata(final String bucket, final String path) throws IOException
+  public InputStream getInputStream(final String bucket, final String path, long start, @Nullable Long length)
+      throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute();
+    ReadChannel reader = storage.get().reader(bucket, path);
+    reader.seek(start);
+    if (length != null) {
+      reader.limit(start + length);
+    }
+    return Channels.newInputStream(reader);
+  }
+
+  public OutputStream getObjectOutputStream(
+      final String bucket,
+      final String path
+  )
+  {
+    WriteChannel writer = storage.get().writer(getBlobInfo(bucket, path));
+    return Channels.newOutputStream(writer);
+  }
+
+  public GoogleStorageObjectMetadata getMetadata(
+      final String bucket,
+      final String path
+  )
+  {
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.values()));
+    return new GoogleStorageObjectMetadata(
+        blob.getBucket(),
+        blob.getName(),
+        blob.getSize(),
+        blob.getUpdateTimeOffsetDateTime()
+            .toEpochSecond()
+    );
   }
 
   public void delete(final String bucket, final String path) throws IOException
   {
-    storage.get().objects().delete(bucket, path).execute();
+    storage.get().delete(bucket, path);
   }
 
   public boolean exists(final String bucket, final String path)
   {
-    try {
-      return storage.get().objects().get(bucket, path).executeUsingHead().isSuccessStatusCode();
-    }
-    catch (Exception e) {
-      return false;
-    }
+
+    Blob blob = storage.get().get(bucket, path);
+    return blob != null;
   }
-   
+
   public long size(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getSize().longValue();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.SIZE));
+    return blob.getSize();
   }
 
   public String version(final String bucket, final String path) throws IOException
   {
-    return storage.get().objects().get(bucket, path).execute().getEtag();
+    Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.GENERATION));
+    return blob.getGeneratedId();
+  }
+
+  public GoogleStorageObjectPage list(

Review Comment:
   NIt: javaDoc this as well. 



##########
extensions-core/google-extensions/pom.xml:
##########
@@ -48,16 +48,11 @@
         </dependency>
 
         <dependency>
-            <groupId>com.google.apis</groupId>

Review Comment:
   We might want to update : https://github.com/apache/druid/blob/88124955b215a737c0ea811f60afa87ae12319f0/integration-tests-ex/cases/pom.xml#L154-L164 as well



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleStorageConnector.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.output;

Review Comment:
   aah I made a mistake adding output to the package name. I guess its too late to change now :)



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleStorageConnector.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.output;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import org.apache.druid.data.input.impl.CloudObjectLocation;
+import org.apache.druid.data.input.impl.prefetch.ObjectOpenFunction;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.storage.google.GoogleInputDataConfig;
+import org.apache.druid.storage.google.GoogleStorage;
+import org.apache.druid.storage.google.GoogleStorageDruidModule;
+import org.apache.druid.storage.google.GoogleStorageObjectMetadata;
+import org.apache.druid.storage.google.GoogleUtils;
+import org.apache.druid.storage.remote.ChunkingStorageConnector;
+import org.apache.druid.storage.remote.ChunkingStorageConnectorParameters;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+public class GoogleStorageConnector extends ChunkingStorageConnector<GoogleInputRange>

Review Comment:
   I donot see test cases for this class. 



##########
extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/ObjectStorageIterator.java:
##########
@@ -91,35 +75,35 @@ public boolean hasNext()
   }
 
   @Override
-  public StorageObject next()
+  public GoogleStorageObjectMetadata next()
   {
     if (!hasNext()) {
       throw new NoSuchElementException();
     }
 
-    final StorageObject retVal = currentObject;
+    final GoogleStorageObjectMetadata retVal = currentObject;
     advanceStorageObject();
     return retVal;
   }
 
   private void advanceStorageObject()
   {
-    while (storageObjectsIterator.hasNext() || nextPageToken != null || uris.hasNext()) {
-      while (storageObjectsIterator.hasNext()) {
-        final StorageObject next = storageObjectsIterator.next();
+    while (blobIterator.hasNext() || nextPageToken != null || uris.hasNext()) {
+      while (blobIterator.hasNext()) {
+        final GoogleStorageObjectMetadata next = blobIterator.next();
         // list with prefix can return directories, but they should always end with `/`, ignore them.
         // also skips empty objects.
-        if (!next.getName().endsWith("/") && next.getSize().signum() > 0) {
+        if (!next.getName().endsWith("/") && Long.signum(next.getSize()) > 0) {

Review Comment:
   Nit: Why would size be negative ever ?



##########
pom.xml:
##########
@@ -128,6 +128,7 @@
         <com.google.http.client.apis.version>1.42.3</com.google.http.client.apis.version>
         <com.google.apis.compute.version>v1-rev20230606-2.0.0</com.google.apis.compute.version>
         <com.google.apis.storage.version>v1-rev20230301-2.0.0</com.google.apis.storage.version>

Review Comment:
   Can we remove  <com.google.apis.storage.version> property ?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "gargvishesh (via GitHub)" <gi...@apache.org>.
gargvishesh commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1424845979


##########
pom.xml:
##########
@@ -128,6 +128,7 @@
         <com.google.http.client.apis.version>1.42.3</com.google.http.client.apis.version>
         <com.google.apis.compute.version>v1-rev20230606-2.0.0</com.google.apis.compute.version>
         <com.google.apis.storage.version>v1-rev20230301-2.0.0</com.google.apis.storage.version>

Review Comment:
   Removed



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add MSQ Durable Storage Connector for Google Cloud Storage and change current Google Cloud Storage client library (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15398:
URL: https://github.com/apache/druid/pull/15398#discussion_r1400587788


##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleTaskLogsTest.java:
##########
@@ -379,29 +342,22 @@
 
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, inputDataConfig, storage);
+    EasyMock.replay(inputDataConfig, storage);
 
     googleTaskLogs.killOlderThan(TIME_NOW);
 
-    EasyMock.verify(listRequest, inputDataConfig, storage);
+    EasyMock.verify(inputDataConfig, storage);
   }
 
   @Test
   public void test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorageObjectPage objectsPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectsPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5993)



##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentKillerTest.java:
##########
@@ -224,30 +208,23 @@
     EasyMock.expect(accountConfig.getPrefix()).andReturn(PREFIX).anyTimes();
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, accountConfig, inputDataConfig, storage);
+    EasyMock.replay(accountConfig, inputDataConfig, storage);
 
     GoogleDataSegmentKiller killer = new GoogleDataSegmentKiller(storage, accountConfig, inputDataConfig);
     killer.killAll();
 
-    EasyMock.verify(listRequest, accountConfig, inputDataConfig, storage);
+    EasyMock.verify(accountConfig, inputDataConfig, storage);
   }
 
   @Test
   public void test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorageObjectPage objectPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5991)



##########
extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleTaskLogsTest.java:
##########
@@ -282,31 +266,24 @@
 
     EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
 
-    EasyMock.replay(listRequest, inputDataConfig, storage, timeSupplier);
+    EasyMock.replay(inputDataConfig, storage, timeSupplier);
 
     googleTaskLogs.killAll();
 
-    EasyMock.verify(listRequest, inputDataConfig, storage, timeSupplier);
+    EasyMock.verify(inputDataConfig, storage, timeSupplier);
   }
 
   @Test
   public void test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs()
   {
     boolean ioExceptionThrown = false;
-    Storage.Objects.List listRequest = null;
+    GoogleStorageObjectPage objectsPage = null;

Review Comment:
   ## Unread local variable
   
   Variable 'GoogleStorageObjectPage objectsPage' is never read.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5992)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org