agura commented on a change in pull request #64: URL: https://github.com/apache/ignite-3/pull/64#discussion_r592471241
########## File path: modules/metastorage-client/src/main/java/org/apache/ignite/metastorage/client/MetaStorageService.java ########## @@ -0,0 +1,334 @@ +/* + * 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.ignite.metastorage.client; + +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.metastorage.common.CompactedException; +import org.apache.ignite.metastorage.common.Condition; +import org.apache.ignite.metastorage.common.Cursor; +import org.apache.ignite.metastorage.common.Entry; +import org.apache.ignite.metastorage.common.Operation; +import org.apache.ignite.metastorage.common.OperationTimeoutException; +import org.apache.ignite.metastorage.common.WatchListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Defines interface for access to a meta storage service. + */ +public interface MetaStorageService { + /** + * Retrieves an entry for the given key. + * + * @param key Key. Couldn't be {@code null}. + * @return An entry for the given key. Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Entry> get(@NotNull byte[] key); + + /** + * Retrieves an entry for the given key and the revision upper bound. + * + * @param key The key. Couldn't be {@code null}. + * @param revUpperBound The upper bound for entry revisions. Must be positive. + * @return An entry for the given key and maximum revision limited by {@code revUpperBound}. + * Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @throws CompactedException If the desired revisions are removed from the storage due to a compaction. + * Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Entry> get(@NotNull byte[] key, long revUpperBound); + + /** + * Retrieves entries for given keys. + * + * @param keys The collection of keys. Couldn't be {@code null} or empty. + * Collection elements couldn't be {@code null}. + * @return A list of entries for given keys. The order of entries in the result list corresponds to + * the traversal order of {@code keys} collection. Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<List<Entry>> getAll(Collection<byte[]> keys); + + /** + * Retrieves entries for given keys and the revision upper bound. + * + * @param keys The collection of keys. Couldn't be {@code null} or empty. + * Collection elements couldn't be {@code null}. + * @param revUpperBound The upper bound for entry revisions. Must be positive. + * @return A list of entries for given keys and maximum revision limited by {@code revUpperBound}. + * The order of entries in the result list corresponds to the traversal order of {@code keys} collection. + * Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @throws CompactedException If the desired revisions are removed from the storage due to a compaction. + * Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<List<Entry>> getAll(Collection<byte[]> keys, long revUpperBound); + + /** + * Inserts or updates an entry with the given key and the given value. + * + * @param key The key. Couldn't be {@code null}. + * @param value The value.Couldn't be {@code null}. + * @return Completed future. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Void> put(@NotNull byte[] key, @NotNull byte[] value); + + /** + * Inserts or updates an entry with the given key and the given value and + * retrieves a previous entry for the given key. + * + * @param key The key. Couldn't be {@code null}. + * @param value The value.Couldn't be {@code null}. + * @return A previous entry for the given key. Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Entry> getAndPut(@NotNull byte[] key, @NotNull byte[] value); + + /** + * Inserts or updates entries with given keys and given values. + * Size of {@code keys} and {@code values} must be the same. + * + * @param keys The list of keys. Couldn't be {@code null} or empty. + * @param values The list of values corresponding to the list of keys. Couldn't be {@code null} or empty. + * @return Completed future. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Void> putAll(@NotNull List<byte[]> keys, @NotNull List<byte[]> values); + + /** + * Inserts or updates entries with given keys and given values and + * retrieves a previous entries for given keys. + * Size of {@code keys} and {@code values} must be the same. + * + * @param keys The list of keys. Couldn't be {@code null} or empty. + * @param values The list of values corresponding to the list of keys. Couldn't be {@code null} or empty. + * @return A list of entries for given keys. Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<List<Entry>> getAndPutAll(@NotNull List<byte[]> keys, @NotNull List<byte[]> values); + + /** + * Removes an entry for the given key. + * + * @param key The key. Couldn't be {@code null}. + * @return Completed future. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Void> remove(@NotNull byte[] key); + + /** + * Removes an entry for the given key. + * + * @param key The key. Couldn't be {@code null}. + * @return A previous entry for the given key. Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Void> getAndRemove(@NotNull byte[] key); + + /** + * Removes entries for given keys. + * + * @param key The key. Couldn't be {@code null}. + * @return Completed future. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<Void> removeAll(@NotNull Collection<byte[]> key); + + /** + * Removes entries for given keys and retrieves previous entries. + * + * @param key The key. Couldn't be {@code null}. + * @return A list of previous entries for given keys.. + * The order of entries in the result list corresponds to the traversal order of {@code keys} collection. + * Couldn't be {@code null}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + */ + @NotNull + CompletableFuture<List<Entry>> getAndRemoveAll(@NotNull Collection<byte[]> key); + + + /** + * Updates an entry for the given key conditionally. + * + * <p>Conditional update could be treated as <i>if(condition)-then(success)-else(failure)</i> expression.</p> + * + * @param key The key. Couldn't be {@code null}. + * @param condition The condition. + * @param success The update which will be applied in case of condition evaluation yields {@code true}. + * @param failure The update which will be applied in case of condition evaluation yields {@code false}. + * @return Future result {@code true} if {@code success} update was applied, otherwise {@code false}. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + * @see Condition + * @see Operation + */ + // TODO: https://issues.apache.org/jira/browse/IGNITE-14269: will be replaced by conditional multi update. + @NotNull + CompletableFuture<Boolean> invoke(@NotNull byte[] key, @NotNull Condition condition, + @NotNull Operation success, @NotNull Operation failure); + + /** + * Updates an entry for the given key conditionally. + * + * <p>Conditional update could be treated as <i>if(condition)-then(success)-else(failure)</i> expression.</p> + * + * @param key The key. Couldn't be {@code null}. + * @param condition The condition. + * @param success The update which will be applied in case of condition evaluation yields {@code true}. + * @param failure The update which will be applied in case of condition evaluation yields {@code false}. + * @return A previous entry for the given key. + * @throws OperationTimeoutException If the operation is timed out. Will be thrown on getting future result. + * @see Entry + * @see Condition + * @see Operation + */ + //TODO: https://issues.apache.org/jira/browse/IGNITE-14269: will be replaced by conditional multi update. + @NotNull + CompletableFuture<Entry> getAndInvoke(@NotNull byte[] key, @NotNull Condition condition, Review comment: @Berkof See `TODO`. Conditional updates will be reworked significantly. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
