alievmirza commented on a change in pull request #114:
URL: https://github.com/apache/ignite-3/pull/114#discussion_r627622460
##########
File path:
modules/runner/src/main/java/org/apache/ignite/internal/storage/LocalConfigurationStorage.java
##########
@@ -49,47 +69,121 @@ 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);
+ /** Start key in ragne for searching local configuration keys. */
+ private ByteArray localKeysStartRange = ByteArray.fromString(LOCAL_PREFIX
+ ".");
+
+ /** End key in range for searching local configuration keys. */
+ private ByteArray localKeysEndRange = ByteArray.fromString(LOCAL_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(localKeysStartRange, localKeysEndRange);
+
+ HashMap<String, Serializable> data = new HashMap<>();
+
+ while (iter.hasNext()) {
+ Entry val = iter.next();
+
+ data.put(val.key().toString().replaceFirst(LOCAL_PREFIX + ".", ""),
+ (Serializable)ByteUtils.fromBytes(val.value()));
+ }
+
+ return new Data(data, version.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 != version.get())
return CompletableFuture.completedFuture(false);
+ CompletableFuture[] futs = new CompletableFuture[newValues.size()];
+
+ int i = 0;
+
for (Map.Entry<String, Serializable> entry : newValues.entrySet()) {
+ ByteArray key = ByteArray.fromString(LOCAL_PREFIX + "." +
entry.getKey());
+
if (entry.getValue() != null)
- map.put(entry.getKey(), entry.getValue());
+ futs[i++] = vaultMgr.put(key,
ByteUtils.toBytes(entry.getValue()));
Review comment:
@sanpwc Could you please clarify, is it true, that it is possible that
some configuration keys might be set bypassing
`LocalConfigurationStorage#write` method? We discussed with @ibessonov in
private and seems that such things should be restricted.
--
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]