sanpwc commented on a change in pull request #114:
URL: https://github.com/apache/ignite-3/pull/114#discussion_r627781091
##########
File path:
modules/runner/src/main/java/org/apache/ignite/internal/storage/LocalConfigurationStorage.java
##########
@@ -49,47 +70,122 @@ public LocalConfigurationStorage(VaultManager vaultMgr) {
this.vaultMgr = vaultMgr;
}
- /** Map to store values. */
- private Map<String, Serializable> map = new ConcurrentHashMap<>();
-
/** Change listeners. */
private List<ConfigurationStorageListener> listeners = new
CopyOnWriteArrayList<>();
/** Storage version. */
- private AtomicLong version = new AtomicLong(0);
+ private AtomicLong ver = new AtomicLong(0);
+
+ /** Start key in range for searching local configuration keys. */
+ private static final ByteArray locKeysStartRange =
ByteArray.fromString(LOC_PREFIX + ".");
+
+ /** End key in range for searching local configuration keys. */
+ private static final ByteArray locKeysEndRange =
ByteArray.fromString(LOC_PREFIX + (char)('.' + 1));
/** {@inheritDoc} */
@Override public synchronized Data readAll() throws StorageException {
- return new Data(new HashMap<>(map), version.get(), 0);
+ Iterator<Entry> iter =
+ vaultMgr.range(locKeysStartRange, locKeysEndRange);
+
+ HashMap<String, Serializable> data = new HashMap<>();
+
+ while (iter.hasNext()) {
+ Entry val = iter.next();
+
+ data.put(val.key().toString().replaceFirst(LOC_PREFIX + ".", ""),
+ (Serializable)ByteUtils.fromBytes(val.value()));
+ }
+
+ // TODO: Need to restore version from pds when restart will be
developed
+ return new Data(data, ver.get());
}
/** {@inheritDoc} */
- @Override public synchronized CompletableFuture<Boolean> write(Map<String,
Serializable> newValues, long version) {
- if (version != this.version.get())
+ @Override public synchronized CompletableFuture<Boolean> write(Map<String,
Serializable> newValues, long sentVersion) {
+ if (sentVersion != ver.get())
return CompletableFuture.completedFuture(false);
+ CompletableFuture[] futs = new CompletableFuture[newValues.size()];
+
+ int i = 0;
+
+ latch = new CountDownLatch(newValues.size());
+
for (Map.Entry<String, Serializable> entry : newValues.entrySet()) {
+ ByteArray key = ByteArray.fromString(LOC_PREFIX + "." +
entry.getKey());
+
if (entry.getValue() != null)
- map.put(entry.getKey(), entry.getValue());
+ futs[i++] = vaultMgr.put(key,
ByteUtils.toBytes(entry.getValue()));
else
- map.remove(entry.getKey());
+ futs[i++] = vaultMgr.remove(key);
}
- this.version.incrementAndGet();
+ try {
+ CompletableFuture.allOf(futs).get();
+
+ latch.await();
+
+ for (Map.Entry<String, Serializable> entry : newValues.entrySet())
{
+ ByteArray key = ByteArray.fromString(LOC_PREFIX + "." +
entry.getKey());
+
+ Entry e = vaultMgr.get(key).get();
Review comment:
Seems that it's incorrect, at the moment of processing notification for
val1, it's possible to have val2 for the same key inside vault, and it's
perfectly fine. So that returning false is incorrect here.
--
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]