alievmirza commented on a change in pull request #114:
URL: https://github.com/apache/ignite-3/pull/114#discussion_r631009441
##########
File path:
modules/runner/src/main/java/org/apache/ignite/internal/storage/LocalConfigurationStorage.java
##########
@@ -49,52 +54,72 @@ 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 LOC_KEYS_START_RANGE =
ByteArray.fromString(LOC_PREFIX);
+
+ /** End key in range for searching local configuration keys. */
+ private static final ByteArray LOC_KEYS_END_RANGE =
ByteArray.fromString(LOC_PREFIX.substring(0, LOC_PREFIX.length() - 1) +
(char)('.' + 1));
/** {@inheritDoc} */
@Override public synchronized Data readAll() throws StorageException {
- return new Data(new HashMap<>(map), version.get(), 0);
+ Iterator<Entry> iter =
+ vaultMgr.range(LOC_KEYS_START_RANGE, LOC_KEYS_END_RANGE);
+
+ HashMap<String, Serializable> data = new HashMap<>();
+
+ while (iter.hasNext()) {
+ Entry val = iter.next();
+
+
data.put(val.key().toString().substring(LOC_KEYS_START_RANGE.toString().length()),
+ (Serializable)ByteUtils.fromBytes(val.value()));
+ }
+
+ // TODO: Need to restore version from pds when restart will be
developed
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-14697
+ 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);
- for (Map.Entry<String, Serializable> entry : newValues.entrySet()) {
- if (entry.getValue() != null)
- map.put(entry.getKey(), entry.getValue());
- else
- map.remove(entry.getKey());
- }
+ Map<ByteArray, byte[]> data = new HashMap<>();
+
+ for (Map.Entry<String, Serializable> e: newValues.entrySet()) {
+ ByteArray key = ByteArray.fromString(LOC_PREFIX + e.getKey());
- this.version.incrementAndGet();
+ data.put(key, e.getValue() == null ? null :
ByteUtils.toBytes(e.getValue()));
+ }
- listeners.forEach(listener -> listener.onEntriesChanged(new
Data(newValues, this.version.get(), 0)));
+ return vaultMgr.putAll(data).thenApply(res -> {
+ listeners.forEach(listener -> listener.onEntriesChanged(new
Data(newValues, ver.incrementAndGet())));
Review comment:
There will be only one listener, which updates the configuration. There
is a ticket for refactoring that
https://issues.apache.org/jira/browse/IGNITE-14689 and also see todo in
org.apache.ignite.configuration.storage.ConfigurationStorage#addListener method
##########
File path:
modules/runner/src/main/java/org/apache/ignite/internal/storage/LocalConfigurationStorage.java
##########
@@ -49,52 +54,72 @@ 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 LOC_KEYS_START_RANGE =
ByteArray.fromString(LOC_PREFIX);
+
+ /** End key in range for searching local configuration keys. */
+ private static final ByteArray LOC_KEYS_END_RANGE =
ByteArray.fromString(LOC_PREFIX.substring(0, LOC_PREFIX.length() - 1) +
(char)('.' + 1));
/** {@inheritDoc} */
@Override public synchronized Data readAll() throws StorageException {
- return new Data(new HashMap<>(map), version.get(), 0);
+ Iterator<Entry> iter =
+ vaultMgr.range(LOC_KEYS_START_RANGE, LOC_KEYS_END_RANGE);
+
+ HashMap<String, Serializable> data = new HashMap<>();
+
+ while (iter.hasNext()) {
+ Entry val = iter.next();
+
+
data.put(val.key().toString().substring(LOC_KEYS_START_RANGE.toString().length()),
+ (Serializable)ByteUtils.fromBytes(val.value()));
+ }
+
+ // TODO: Need to restore version from pds when restart will be
developed
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-14697
+ 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);
- for (Map.Entry<String, Serializable> entry : newValues.entrySet()) {
- if (entry.getValue() != null)
- map.put(entry.getKey(), entry.getValue());
- else
- map.remove(entry.getKey());
- }
+ Map<ByteArray, byte[]> data = new HashMap<>();
+
+ for (Map.Entry<String, Serializable> e: newValues.entrySet()) {
+ ByteArray key = ByteArray.fromString(LOC_PREFIX + e.getKey());
- this.version.incrementAndGet();
+ data.put(key, e.getValue() == null ? null :
ByteUtils.toBytes(e.getValue()));
+ }
- listeners.forEach(listener -> listener.onEntriesChanged(new
Data(newValues, this.version.get(), 0)));
+ return vaultMgr.putAll(data).thenApply(res -> {
+ listeners.forEach(listener -> listener.onEntriesChanged(new
Data(newValues, ver.incrementAndGet())));
Review comment:
There will be only one listener, which updates the configuration. There
is a ticket for refactoring that
https://issues.apache.org/jira/browse/IGNITE-14689 and also see todo in
`org.apache.ignite.configuration.storage.ConfigurationStorage#addListener`
method
--
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]