alievmirza commented on a change in pull request #105:
URL: https://github.com/apache/ignite-3/pull/105#discussion_r620735811



##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/VaultManager.java
##########
@@ -17,18 +17,80 @@
 
 package org.apache.ignite.internal.vault;
 
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.impl.VaultServiceImpl;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+
 /**
- * VaultManager is responsible for handling VaultService lifecycle and 
providing interface for managing local keys.
+ * VaultManager is responsible for handling {@link VaultService} lifecycle
+ * and providing interface for managing local keys.
  */
 public class VaultManager {
+    private VaultService vaultService;
+
+    /**
+     * Default constructor.
+     */
+    public VaultManager() {
+        this.vaultService = new VaultServiceImpl();
+    }
 
     /**
      * @return {@code true} if VaultService beneath given VaultManager was 
bootstrapped with data
      * either from PDS or from user initial bootstrap configuration.
+     *
+     * TODO: implement when IGNITE-14408 will be ready
      */
     public boolean bootstrapped() {
         return false;

Review comment:
       lets do that in the separate ticket 
https://issues.apache.org/jira/browse/IGNITE-14408

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultWatch.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.Comparator;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Watch for vault entries.
+ * Could be specified by range of keys.
+ * If value of key in range is changed, then corresponding listener will be 
triggered.
+ */
+public class VaultWatch {

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {
+        synchronized (mux) {
+            return CompletableFuture.completedFuture(new VaultEntry(key, 
storage.get(key)));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public CompletableFuture<Long> appliedRevision() {
+        synchronized (mux) {
+            return 
CompletableFuture.completedFuture(IgniteUtils.bytesToLong(storage.get(APPLIED_REV),
 0));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> put(ByteArray key, byte[] val) {

Review comment:
       let's save the same contract as far as we want to generify interfaces of 
vault and metastorage https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: modules/core/src/main/java/org/apache/ignite/lang/ByteArray.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.lang;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * A class for handling byte array.
+ */
+public final class ByteArray implements Comparable<ByteArray> {
+    /** Byte-wise representation of the {@code ByteArray}. */
+    @NotNull
+    private final byte[] arr;
+
+    /**
+     * Constructs {@code ByteArray} instance from the given byte array. 
<em>Note:</em> copy of the given byte array will not be
+     * created in order to avoid redundant memory consumption.
+     *
+     * @param arr Byte array. Can't be {@code null}.
+     */
+    public ByteArray(@NotNull byte[] arr) {
+        this.arr = arr;
+    }
+
+    /**
+     * Constructs {@code ByteArray} instance from the given string.

Review comment:
       done.

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultEntry.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.internal.vault.common;
+
+import java.io.Serializable;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Representation of vault entry.
+ */
+public class VaultEntry implements Entry, Serializable {

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/VaultManager.java
##########
@@ -17,18 +17,80 @@
 
 package org.apache.ignite.internal.vault;
 
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.impl.VaultServiceImpl;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+
 /**
- * VaultManager is responsible for handling VaultService lifecycle and 
providing interface for managing local keys.
+ * VaultManager is responsible for handling {@link VaultService} lifecycle
+ * and providing interface for managing local keys.
  */
 public class VaultManager {
+    private VaultService vaultService;
+
+    /**
+     * Default constructor.
+     */
+    public VaultManager() {
+        this.vaultService = new VaultServiceImpl();
+    }
 
     /**
      * @return {@code true} if VaultService beneath given VaultManager was 
bootstrapped with data
      * either from PDS or from user initial bootstrap configuration.
+     *
+     * TODO: implement when IGNITE-14408 will be ready
      */
     public boolean bootstrapped() {
         return false;
     }
 
-    // TODO: IGNITE-14405 Local persistent key-value storage (Vault).
+    /**
+     * See {@link VaultService#get(ByteArray)}
+     */
+    public CompletableFuture<VaultEntry> get(ByteArray key) {

Review comment:
       I would keep it as is as far as we have plans to generify Vault and 
Metastorage interfaces https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
##########
@@ -167,4 +167,63 @@ public static int hash(long key) {
 
         return hash(val);
     }
+
+    /**
+     * Constructs {@code long} from byte array.
+     *
+     * @param bytes Array of bytes.
+     * @param off Offset in {@code bytes} array.
+     * @return Long value.
+     */
+    public static long bytesToLong(byte[] bytes, int off) {

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/Entry.java
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.internal.vault.common;
+
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents a vault unit as entry with key and value, where
+ * <ul>
+ *     <li>key - an unique entry's key. Keys are comparable in lexicographic 
manner and represented as an {@link ByteArray}.</li>
+ *     <li>value - a data which is associated with a key and represented as an 
array of bytes.</ul>
+ * </ul>
+ */
+public interface Entry {

Review comment:
       done. Also mentioned @sanpwc 's idea in the ticket 
https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/WatcherImpl.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Implementation of vault {@link Watcher}.
+ */
+public class WatcherImpl implements Watcher {
+    /** Queue for changed vault entries. */
+    private final BlockingQueue<VaultEntry> queue = new 
LinkedBlockingQueue<>();
+
+    /** Registered vault watches. */
+    private final Map<IgniteUuid, VaultWatch> watches = new HashMap<>();
+
+    /** Flag for indicating if watcher is stopped. */
+    private volatile boolean stop;
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    /** Execution service which runs thread for processing changed vault 
entries. */
+    private final ExecutorService exec;
+
+    /**
+     * Default constructor.
+     */
+    public WatcherImpl() {
+        exec = Executors.newFixedThreadPool(1);
+
+        exec.execute(new WatcherWorker());
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<IgniteUuid> register(@NotNull 
VaultWatch vaultWatch) {
+        synchronized (mux) {
+            IgniteUuid key = new IgniteUuid(UUID.randomUUID(), 0);

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/VaultManager.java
##########
@@ -17,18 +17,80 @@
 
 package org.apache.ignite.internal.vault;
 
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.impl.VaultServiceImpl;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+
 /**
- * VaultManager is responsible for handling VaultService lifecycle and 
providing interface for managing local keys.
+ * VaultManager is responsible for handling {@link VaultService} lifecycle
+ * and providing interface for managing local keys.
  */
 public class VaultManager {
+    private VaultService vaultService;
+
+    /**
+     * Default constructor.
+     */
+    public VaultManager() {
+        this.vaultService = new VaultServiceImpl();
+    }
 
     /**
      * @return {@code true} if VaultService beneath given VaultManager was 
bootstrapped with data
      * either from PDS or from user initial bootstrap configuration.
+     *
+     * TODO: implement when IGNITE-14408 will be ready
      */
     public boolean bootstrapped() {
         return false;
     }
 
-    // TODO: IGNITE-14405 Local persistent key-value storage (Vault).
+    /**
+     * See {@link VaultService#get(ByteArray)}
+     */
+    public CompletableFuture<VaultEntry> get(ByteArray key) {
+        return vaultService.get(key);
+    }
+
+    /**
+     * See {@link VaultService#put(ByteArray, byte[])}
+     */
+    public CompletableFuture<Void> put(ByteArray key, byte[] val) {
+        return vaultService.put(key, val);
+    }
+
+    /**
+     * See {@link VaultService#remove(ByteArray)}
+     */
+    public CompletableFuture<Void> remove(ByteArray key) {
+        return vaultService.remove(key);
+    }
+
+    /**
+     * See {@link VaultService#range(ByteArray, ByteArray)}
+     */
+    public Iterator<VaultEntry> range(ByteArray fromKey, ByteArray toKey) {
+        return vaultService.range(fromKey, toKey);
+    }
+
+    /**
+     * See {@link VaultService#putAll}
+     */
+    @NotNull
+    public CompletableFuture<Void> putAll(@NotNull Map<ByteArray, byte[]> 
vals, long revision) {
+        return vaultService.putAll(vals, revision);
+    }
+
+    /**
+     * See {@link VaultService#appliedRevision()}
+     */
+    @NotNull
+    public CompletableFuture<Long> appliedRevision() {
+        return vaultService.appliedRevision();
+    }

Review comment:
       added

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultListener.java
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.internal.vault.common;
+
+/**
+ * Vault storage listener for changes.
+ */
+@FunctionalInterface
+public interface VaultListener {

Review comment:
       corresponding ticket https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/Watcher.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Vault watcher.
+ *
+ * Watches for vault entries updates.
+ */
+public interface Watcher {

Review comment:
       Let's save it, as far as I can understand, in the future, we will have 
watcher in metastorage, and this interface might be common for vault and 
metastorage. Mentioned that in 
https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/Watcher.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Vault watcher.
+ *
+ * Watches for vault entries updates.
+ */
+public interface Watcher {
+    /**
+     * Registers watch for vault entries updates.
+     *
+     * @param vaultWatch Vault watch.
+     * @return UUID of registered watch.
+     */
+    CompletableFuture<IgniteUuid> register(@NotNull VaultWatch vaultWatch);

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/WatcherImpl.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Implementation of vault {@link Watcher}.
+ */
+public class WatcherImpl implements Watcher {
+    /** Queue for changed vault entries. */
+    private final BlockingQueue<VaultEntry> queue = new 
LinkedBlockingQueue<>();
+
+    /** Registered vault watches. */
+    private final Map<IgniteUuid, VaultWatch> watches = new HashMap<>();
+
+    /** Flag for indicating if watcher is stopped. */
+    private volatile boolean stop;
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    /** Execution service which runs thread for processing changed vault 
entries. */
+    private final ExecutorService exec;
+
+    /**
+     * Default constructor.
+     */
+    public WatcherImpl() {
+        exec = Executors.newFixedThreadPool(1);
+
+        exec.execute(new WatcherWorker());
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<IgniteUuid> register(@NotNull 
VaultWatch vaultWatch) {

Review comment:
       I believe that metastorage will also have some sort of Watcher and 
`register` method make sense for that case. Also, I believe that we will 
generify that watcher approach for vault and metastorage, so for simplicity, I 
decided to save the contract. Mentioned generification of watcher here 
https://issues.apache.org/jira/browse/IGNITE-14653 

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/VaultManager.java
##########
@@ -17,18 +17,80 @@
 
 package org.apache.ignite.internal.vault;
 
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.impl.VaultServiceImpl;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+
 /**
- * VaultManager is responsible for handling VaultService lifecycle and 
providing interface for managing local keys.
+ * VaultManager is responsible for handling {@link VaultService} lifecycle
+ * and providing interface for managing local keys.
  */
 public class VaultManager {
+    private VaultService vaultService;

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {

Review comment:
       answered above

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/WatcherImpl.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Implementation of vault {@link Watcher}.
+ */
+public class WatcherImpl implements Watcher {
+    /** Queue for changed vault entries. */
+    private final BlockingQueue<VaultEntry> queue = new 
LinkedBlockingQueue<>();
+
+    /** Registered vault watches. */
+    private final Map<IgniteUuid, VaultWatch> watches = new HashMap<>();
+
+    /** Flag for indicating if watcher is stopped. */
+    private volatile boolean stop;
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    /** Execution service which runs thread for processing changed vault 
entries. */
+    private final ExecutorService exec;
+
+    /**
+     * Default constructor.
+     */
+    public WatcherImpl() {
+        exec = Executors.newFixedThreadPool(1);
+
+        exec.execute(new WatcherWorker());
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<IgniteUuid> register(@NotNull 
VaultWatch vaultWatch) {
+        synchronized (mux) {
+            IgniteUuid key = new IgniteUuid(UUID.randomUUID(), 0);
+
+            watches.put(key, vaultWatch);
+
+            return CompletableFuture.completedFuture(key);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void notify(@NotNull VaultEntry val) {
+        queue.offer(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void cancel(@NotNull IgniteUuid uuid) {
+        synchronized (mux) {
+            watches.remove(uuid);
+        }
+    }
+
+    /**
+     * Shutdowns watcher.
+     */
+    public void shutdown() {
+        stop = true;
+
+        if (exec != null) {
+            List<Runnable> tasks = exec.shutdownNow();
+
+            if (!tasks.isEmpty())
+                System.out.println("Runnable tasks outlived thread pool 
executor service");

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {
+        synchronized (mux) {
+            return CompletableFuture.completedFuture(new VaultEntry(key, 
storage.get(key)));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public CompletableFuture<Long> appliedRevision() {
+        synchronized (mux) {
+            return 
CompletableFuture.completedFuture(IgniteUtils.bytesToLong(storage.get(APPLIED_REV),
 0));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> put(ByteArray key, byte[] val) {
+        synchronized (mux) {
+            storage.put(key, val);
+
+            watcher.notify(new VaultEntry(key, val));
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> remove(ByteArray key) {
+        synchronized (mux) {
+            storage.remove(key);
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<VaultEntry> range(ByteArray fromKey, ByteArray 
toKey) {
+        synchronized (mux) {
+            return new ArrayList<>(storage.subMap(fromKey, toKey).entrySet())
+                .stream()
+                .map(e -> new VaultEntry(e.getKey(), e.getValue()))
+                .iterator();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public @NotNull CompletableFuture<IgniteUuid> watch(@NotNull 
VaultWatch vaultWatch) {

Review comment:
       lets do that in the ticket about generification  
https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/service/VaultService.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.internal.vault.service;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.common.VaultWatch;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Defines interface for accessing to a vault service.
+ */
+public interface VaultService {

Review comment:
       lets do that in the ticket about generification 
https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/service/VaultService.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.internal.vault.service;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.common.VaultWatch;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Defines interface for accessing to a vault service.
+ */
+public interface VaultService {

Review comment:
       let's do that in the ticket about generification 
https://issues.apache.org/jira/browse/IGNITE-14653

##########
File path: modules/core/src/main/java/org/apache/ignite/lang/ByteArray.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.lang;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * A class for handling byte array.
+ */
+public final class ByteArray implements Comparable<ByteArray> {
+    /** Byte-wise representation of the {@code ByteArray}. */
+    @NotNull
+    private final byte[] arr;
+
+    /**
+     * Constructs {@code ByteArray} instance from the given byte array. 
<em>Note:</em> copy of the given byte array will not be
+     * created in order to avoid redundant memory consumption.
+     *
+     * @param arr Byte array. Can't be {@code null}.
+     */
+    public ByteArray(@NotNull byte[] arr) {
+        this.arr = arr;
+    }
+
+    /**
+     * Constructs {@code ByteArray} instance from the given string.
+     *
+     * @param s The string {@code ByteArray} representation. Can't be {@code 
null}.
+     */
+    public static ByteArray fromString(@NotNull String s) {
+        return new ByteArray(s.getBytes(StandardCharsets.UTF_8));
+    }
+
+    /**
+     * Returns the {@code ByteArray} as byte array.
+     *
+     * @return Bytes of the {@code ByteArray}.
+     */
+    public byte[] bytes() {
+        return arr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o) return true;
+
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ByteArray byteArray = (ByteArray)o;
+
+        return Arrays.equals(arr, byteArray.arr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return Arrays.hashCode(arr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compareTo(@NotNull ByteArray other) {
+        return Arrays.compare(this.arr, other.arr);
+    }
+
+    /**
+     * Compares two {@code ByteArray} values.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    x.compareTo(y)
+     * </pre>
+     *
+     * where x and y are {@code ByteArray}'s
+     */
+    public static int compare(ByteArray x, ByteArray y) {

Review comment:
       agree, done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {
+        synchronized (mux) {
+            return CompletableFuture.completedFuture(new VaultEntry(key, 
storage.get(key)));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public CompletableFuture<Long> appliedRevision() {
+        synchronized (mux) {
+            return 
CompletableFuture.completedFuture(IgniteUtils.bytesToLong(storage.get(APPLIED_REV),
 0));

Review comment:
       As far as I can understand, revision equals 0 means that metastorage is 
in an initial state and there weren't any entries in metastorage at all, so I 
would say that when `storage.get(APPLIED_REV)` equals `null` means that vault 
hasn't received any updates from metastorage yet and revision should be equal 
to 0 as for initial state in metastorage. WDYT? 

##########
File path: 
modules/vault/src/test/java/org/apache/ignite/internal/vault/impl/VaultBaseContractsTest.java
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.vault.common.VaultEntry;
+import org.apache.ignite.internal.vault.common.VaultWatch;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Test for base vault contracts.
+ */
+public class VaultBaseContractsTest {
+    /** Vault. */
+    private VaultService storage;
+
+    /**
+     * Instantiate vault.
+     */
+    @BeforeEach
+    public void setUp() {
+        storage = new VaultServiceImpl();
+    }
+
+    /**
+     * put contract
+     */
+    @Test
+    public void put() throws ExecutionException, InterruptedException {
+        ByteArray key = getKey(1);
+        byte[] val = getValue(key, 1);
+
+        assertNull(storage.get(key).get().value());
+
+        storage.put(key, val);
+
+        VaultEntry v = storage.get(key).get();
+
+        assertFalse(v.empty());
+        assertEquals(val, v.value());
+
+        storage.put(key, val);
+
+        v = storage.get(key).get();
+
+        assertFalse(v.empty());
+        assertEquals(val, v.value());
+    }
+
+    /**
+     * remove contract.
+     */
+    @Test
+    public void remove() throws ExecutionException, InterruptedException {
+        ByteArray key = getKey(1);
+        byte[] val = getValue(key, 1);
+
+        assertNull(storage.get(key).get().value());
+
+        // Remove non-existent value.
+        storage.remove(key);
+
+        assertNull(storage.get(key).get().value());
+
+        storage.put(key, val);
+
+        VaultEntry v = storage.get(key).get();
+
+        assertFalse(v.empty());
+        assertEquals(val, v.value());
+
+        // Remove existent value.
+        storage.remove(key);
+
+        v = storage.get(key).get();
+
+        assertNull(v.value());
+    }
+
+    /**
+     * range contract.
+     */
+    @Test
+    public void range() throws ExecutionException, InterruptedException {
+        ByteArray key;
+
+        Map<ByteArray, byte[]> values = new HashMap<>();
+
+        for (int i = 0; i < 10; i++) {
+            key = getKey(i);
+
+            values.put(key, getValue(key, i));
+
+            assertNull(storage.get(key).get().value());
+        }
+
+        values.forEach((k, v) -> storage.put(k, v));
+
+        for (Map.Entry<ByteArray, byte[]> entry : values.entrySet())
+            assertEquals(entry.getValue(), 
storage.get(entry.getKey()).get().value());
+
+        Iterator<VaultEntry> it = storage.range(getKey(3), getKey(7));
+
+        List<VaultEntry> rangeRes = new ArrayList<>();
+
+        it.forEachRemaining(rangeRes::add);
+
+        assertEquals(4, rangeRes.size());
+
+        //Check that we have exact range from "key3" to "key6"
+        for (int i = 3; i < 7; i++)
+            assertEquals(values.get(getKey(i)), rangeRes.get(i - 3).value());
+    }
+
+    /**
+     * watch contract.
+     */
+    @Test
+    public void watch() throws ExecutionException, InterruptedException {
+        ByteArray key;
+
+        Map<ByteArray, byte[]> values = new HashMap<>();
+
+        for (int i = 0; i < 10; i++) {
+            key = getKey(i);
+
+            values.put(key, getValue(key, i));
+        }
+
+        values.forEach((k, v) -> storage.put(k, v));
+
+        for (Map.Entry<ByteArray, byte[]> entry : values.entrySet())
+            assertEquals(entry.getValue(), 
storage.get(entry.getKey()).get().value());
+
+        AtomicInteger counter = new AtomicInteger();
+
+        VaultWatch vaultWatch = new VaultWatch(changedValue -> 
counter.incrementAndGet());
+
+        vaultWatch.startKey(getKey(3));
+        vaultWatch.endKey(getKey(7));
+
+        storage.watch(vaultWatch);
+
+        for (int i = 3; i < 7; i++)
+            storage.put(getKey(i), ("new" + i).getBytes());
+
+        Thread.sleep(500);

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/WatcherImpl.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Implementation of vault {@link Watcher}.
+ */
+public class WatcherImpl implements Watcher {
+    /** Queue for changed vault entries. */
+    private final BlockingQueue<VaultEntry> queue = new 
LinkedBlockingQueue<>();
+
+    /** Registered vault watches. */
+    private final Map<IgniteUuid, VaultWatch> watches = new HashMap<>();
+
+    /** Flag for indicating if watcher is stopped. */
+    private volatile boolean stop;
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    /** Execution service which runs thread for processing changed vault 
entries. */
+    private final ExecutorService exec;
+
+    /**
+     * Default constructor.
+     */
+    public WatcherImpl() {
+        exec = Executors.newFixedThreadPool(1);
+
+        exec.execute(new WatcherWorker());
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<IgniteUuid> register(@NotNull 
VaultWatch vaultWatch) {
+        synchronized (mux) {
+            IgniteUuid key = new IgniteUuid(UUID.randomUUID(), 0);
+
+            watches.put(key, vaultWatch);
+
+            return CompletableFuture.completedFuture(key);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void notify(@NotNull VaultEntry val) {

Review comment:
       Could you please clarify a bit your question? Anyway, I've added 
`onError` in `VaultListener`, also I've added the logic of unregistering 
watches in `WatcherWorker`. Is your question still valid taking into account 
these modifications? 

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultEntry.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.internal.vault.common;
+
+import java.io.Serializable;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Representation of vault entry.
+ */
+public class VaultEntry implements Entry, Serializable {
+    /** Key. */
+    private ByteArray key;
+
+    /** Value. */
+    private byte[] val;
+
+    /**
+     * Constructs {@code VaultEntry} instance from the given key and value.
+     *
+     * @param key Key as a {@code ByteArray}.
+     * @param val Value as a {@code byte[]}.
+     */
+    public VaultEntry(ByteArray key, byte[] val) {

Review comment:
       done

##########
File path: modules/core/src/main/java/org/apache/ignite/lang/ByteArray.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.lang;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * A class for handling byte array.
+ */
+public final class ByteArray implements Comparable<ByteArray> {
+    /** Byte-wise representation of the {@code ByteArray}. */
+    @NotNull
+    private final byte[] arr;
+
+    /**
+     * Constructs {@code ByteArray} instance from the given byte array. 
<em>Note:</em> copy of the given byte array will not be
+     * created in order to avoid redundant memory consumption.
+     *
+     * @param arr Byte array. Can't be {@code null}.
+     */
+    public ByteArray(@NotNull byte[] arr) {
+        this.arr = arr;
+    }
+
+    /**
+     * Constructs {@code ByteArray} instance from the given string.
+     *
+     * @param s The string {@code ByteArray} representation. Can't be {@code 
null}.
+     */
+    public static ByteArray fromString(@NotNull String s) {
+        return new ByteArray(s.getBytes(StandardCharsets.UTF_8));
+    }
+
+    /**
+     * Returns the {@code ByteArray} as byte array.
+     *
+     * @return Bytes of the {@code ByteArray}.
+     */
+    public byte[] bytes() {
+        return arr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o) return true;
+
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ByteArray byteArray = (ByteArray)o;
+
+        return Arrays.equals(arr, byteArray.arr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return Arrays.hashCode(arr);

Review comment:
       @AMashenkov could you please shed a light on the root cause of the boost 
in that approach? Anyway, I would move such discussion to a separate ticket, 
where we can discuss it properly and compare benchmarks. WDYT? 

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultEntry.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.internal.vault.common;
+
+import java.io.Serializable;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Representation of vault entry.
+ */
+public class VaultEntry implements Entry, Serializable {
+    /** Key. */
+    private ByteArray key;
+
+    /** Value. */
+    private byte[] val;

Review comment:
       done.

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultListener.java
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.internal.vault.common;
+
+/**
+ * Vault storage listener for changes.
+ */
+@FunctionalInterface
+public interface VaultListener {
+    /**
+     * Method called when entries in storage change.
+     * @param changedEntry Changed value
+     */
+    void onEntryChanged(VaultEntry changedEntry);

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {
+        synchronized (mux) {
+            return CompletableFuture.completedFuture(new VaultEntry(key, 
storage.get(key)));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public CompletableFuture<Long> appliedRevision() {
+        synchronized (mux) {
+            return 
CompletableFuture.completedFuture(IgniteUtils.bytesToLong(storage.get(APPLIED_REV),
 0));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> put(ByteArray key, byte[] val) {
+        synchronized (mux) {
+            storage.put(key, val);
+
+            watcher.notify(new VaultEntry(key, val));
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> remove(ByteArray key) {
+        synchronized (mux) {
+            storage.remove(key);
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<VaultEntry> range(ByteArray fromKey, ByteArray 
toKey) {
+        synchronized (mux) {
+            return new ArrayList<>(storage.subMap(fromKey, toKey).entrySet())

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultWatch.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.Comparator;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Watch for vault entries.
+ * Could be specified by range of keys.
+ * If value of key in range is changed, then corresponding listener will be 
triggered.
+ */
+public class VaultWatch {
+    /** Comparator for {@code ByteArray} values. */
+    private static final Comparator<ByteArray> CMP = ByteArray::compare;
+
+    /** Start key of range (inclusive) */
+    @Nullable
+    private ByteArray startKey;
+
+    /** End key of range (inclusive) */
+    @Nullable
+    private ByteArray endKey;
+
+    /** Listener for vault's values updates. */
+    private VaultListener listener;
+
+    /**
+     * @param listener Listener.
+     */
+    public VaultWatch(VaultListener listener) {
+        this.listener = listener;
+    }
+
+    /**
+     * Start key of range (inclusive).
+     * If value of key in range is changed, then corresponding listener will 
be triggered.
+     *
+     * @param startKey Start key represented as {@code ByteArray}.
+     */
+    public void startKey(ByteArray startKey) {
+        this.startKey = startKey;
+    }
+
+    /**
+     * Start key of range (inclusive).
+     * If value of key in range is changed, then corresponding listener will 
be triggered.
+     *
+     * @param endKey End key represented as {@code ByteArray}.
+     */
+    public void endKey(ByteArray endKey) {
+        this.endKey = endKey;
+    }
+
+    /**
+     * Notifies specified listener if {@code val} of key in range was changed.
+     *
+     * @param val Vault entry.
+     */
+    public void notify(VaultEntry val) {
+        if (startKey != null && CMP.compare(val.key(), startKey) < 0)
+            return;
+
+        if (endKey != null && CMP.compare(val.key(), endKey) > 0)

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultWatch.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.Comparator;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Watch for vault entries.
+ * Could be specified by range of keys.
+ * If value of key in range is changed, then corresponding listener will be 
triggered.
+ */
+public class VaultWatch {
+    /** Comparator for {@code ByteArray} values. */
+    private static final Comparator<ByteArray> CMP = ByteArray::compare;
+
+    /** Start key of range (inclusive) */
+    @Nullable
+    private ByteArray startKey;

Review comment:
       fixed

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/common/VaultWatch.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.vault.common;
+
+import java.util.Comparator;
+import org.apache.ignite.lang.ByteArray;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Watch for vault entries.
+ * Could be specified by range of keys.
+ * If value of key in range is changed, then corresponding listener will be 
triggered.
+ */
+public class VaultWatch {
+    /** Comparator for {@code ByteArray} values. */
+    private static final Comparator<ByteArray> CMP = ByteArray::compare;
+
+    /** Start key of range (inclusive) */
+    @Nullable
+    private ByteArray startKey;
+
+    /** End key of range (inclusive) */
+    @Nullable
+    private ByteArray endKey;

Review comment:
       done

##########
File path: 
modules/vault/src/main/java/org/apache/ignite/internal/vault/impl/VaultServiceImpl.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.internal.vault.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.vault.common.*;
+import org.apache.ignite.internal.vault.service.VaultService;
+import org.apache.ignite.lang.ByteArray;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Simple in-memory representation of vault. Only for test purposes.
+ */
+public class VaultServiceImpl implements VaultService {
+    /** Map to store values. */
+    private TreeMap<ByteArray, byte[]> storage = new TreeMap<>();
+
+    /**
+     * Special key for vault where applied revision for {@code putAll} 
operation is stored.
+     */
+    private static ByteArray APPLIED_REV = 
ByteArray.fromString("applied_revision");
+
+    /** Mutex. */
+    private final Object mux = new Object();
+
+    private final WatcherImpl watcher;
+
+    public VaultServiceImpl() {
+        this.watcher = new WatcherImpl();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<VaultEntry> get(ByteArray key) {
+        synchronized (mux) {
+            return CompletableFuture.completedFuture(new VaultEntry(key, 
storage.get(key)));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public CompletableFuture<Long> appliedRevision() {
+        synchronized (mux) {
+            return 
CompletableFuture.completedFuture(IgniteUtils.bytesToLong(storage.get(APPLIED_REV),
 0));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> put(ByteArray key, byte[] val) {
+        synchronized (mux) {
+            storage.put(key, val);
+
+            watcher.notify(new VaultEntry(key, val));
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public CompletableFuture<Void> remove(ByteArray key) {
+        synchronized (mux) {
+            storage.remove(key);
+
+            return CompletableFuture.allOf();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<VaultEntry> range(ByteArray fromKey, ByteArray 
toKey) {

Review comment:
       let's do that in a separate ticket 
https://issues.apache.org/jira/browse/IGNITE-14654




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


Reply via email to