You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2021/06/22 14:12:12 UTC

[ignite-3] branch main updated: IGNITE-14799 Added prefix queries to MetaStorageManager. Fixes #159

This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 0f8846f  IGNITE-14799 Added prefix queries to MetaStorageManager. Fixes #159
0f8846f is described below

commit 0f8846fc204ead7e9b4626695f7b4e121494ce89
Author: Kirill Gusakov <kg...@gmail.com>
AuthorDate: Tue Jun 22 17:11:40 2021 +0300

    IGNITE-14799 Added prefix queries to MetaStorageManager. Fixes #159
    
    Signed-off-by: Slava Koptilin <sl...@gmail.com>
---
 .../internal/metastorage/MetaStorageManager.java   | 72 ++++++++++++++++++++--
 1 file changed, 68 insertions(+), 4 deletions(-)

diff --git a/modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java b/modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
index 7e1316f..b535b6c 100644
--- a/modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
+++ b/modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
@@ -431,6 +431,72 @@ public class MetaStorageManager {
     }
 
     /**
+     * Retrieves entries for the given key prefix in lexicographic order.
+     * Entries will be filtered out by the current applied revision as an upper bound.
+     * Applied revision is a revision of the last successful vault update.
+     *
+     * Prefix query is a synonym of the range query {@code (prefixKey, nextKey(prefixKey))}.
+     *
+     * @param keyPrefix Prefix of the key to retrieve the entries. Couldn't be {@code null}.
+     * @return Cursor built upon entries corresponding to the given range and applied revision.
+     * @throws OperationTimeoutException If the operation is timed out.
+     * @throws CompactedException If the desired revisions are removed from the storage due to a compaction.
+     * @see ByteArray
+     * @see Entry
+     */
+    public @NotNull Cursor<Entry> prefixWithAppliedRevision(@NotNull ByteArray keyPrefix) {
+        var rangeCriterion = KeyCriterion.RangeCriterion.fromPrefixKey(keyPrefix);
+        return new CursorWrapper<>(
+            metaStorageSvcFut,
+            metaStorageSvcFut.thenApply(svc -> {
+                try {
+                    return svc.range(rangeCriterion.from(), rangeCriterion.to(), appliedRevision());
+                }
+                catch (IgniteInternalCheckedException e) {
+                    throw new IgniteInternalException(e);
+                }
+            })
+        );
+    }
+
+    /**
+     * Retrieves entries for the given key prefix in lexicographic order. Short cut for
+     * {@link #prefix(ByteArray, long)} where {@code revUpperBound == -1}.
+     *
+     * @param keyPrefix Prefix of the key to retrieve the entries. Couldn't be {@code null}.
+     * @return Cursor built upon entries corresponding to the given range and revision.
+     * @throws OperationTimeoutException If the operation is timed out.
+     * @throws CompactedException If the desired revisions are removed from the storage due to a compaction.
+     * @see ByteArray
+     * @see Entry
+     */
+    public @NotNull Cursor<Entry> prefix(@NotNull ByteArray keyPrefix) {
+        return prefix(keyPrefix, -1);
+    }
+
+    /**
+     * Retrieves entries for the given key prefix in lexicographic order. Entries will be filtered out by upper bound
+     * of given revision number.
+     *
+     * Prefix query is a synonym of the range query {@code range(prefixKey, nextKey(prefixKey))}.
+     *
+     * @param keyPrefix Prefix of the key to retrieve the entries. Couldn't be {@code null}.
+     * @param revUpperBound  The upper bound for entry revision. {@code -1} means latest revision.
+     * @return Cursor built upon entries corresponding to the given range and revision.
+     * @throws OperationTimeoutException If the operation is timed out.
+     * @throws CompactedException If the desired revisions are removed from the storage due to a compaction.
+     * @see ByteArray
+     * @see Entry
+     */
+    public @NotNull Cursor<Entry> prefix(@NotNull ByteArray keyPrefix, long revUpperBound) {
+        var rangeCriterion = KeyCriterion.RangeCriterion.fromPrefixKey(keyPrefix);
+        return new CursorWrapper<>(
+            metaStorageSvcFut,
+            metaStorageSvcFut.thenApply(svc -> svc.range(rangeCriterion.from(), rangeCriterion.to(), revUpperBound))
+        );
+    }
+
+    /**
      * @see MetaStorageService#compact()
      */
     public @NotNull CompletableFuture<Void> compact() {
@@ -601,13 +667,11 @@ public class MetaStorageManager {
             return it;
         }
 
-        @Override
-        public boolean hasNext() {
+        @Override public boolean hasNext() {
             return it.hasNext();
         }
 
-        @Override
-        public T next() {
+        @Override public T next() {
             return it.next();
         }