VersionsStore - use long intead of Long to decrease heap size

This commit is contained in:
Volodymyr Babak 2025-06-03 15:47:19 +03:00
parent 46a58ca82b
commit ccdcbc6350

View File

@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
@Slf4j @Slf4j
public class VersionsStore { public class VersionsStore {
private final ConcurrentMap<EdqsObjectKey, TimedValue<Long>> versions = new ConcurrentHashMap<>(); private final ConcurrentMap<EdqsObjectKey, TimedValue> versions = new ConcurrentHashMap<>();
private final long expirationMillis; private final long expirationMillis;
private final ScheduledExecutorService cleaner = Executors.newSingleThreadScheduledExecutor(); private final ScheduledExecutorService cleaner = Executors.newSingleThreadScheduledExecutor();
@ -43,7 +43,7 @@ public class VersionsStore {
versions.compute(key, (k, prevVersion) -> { versions.compute(key, (k, prevVersion) -> {
if (prevVersion == null || prevVersion.value <= version) { if (prevVersion == null || prevVersion.value <= version) {
isNew.set(true); isNew.set(true);
return new TimedValue<>(version); return new TimedValue(version);
} else { } else {
log.debug("[{}] Version {} is outdated, the latest is {}", key, version, prevVersion); log.debug("[{}] Version {} is outdated, the latest is {}", key, version, prevVersion);
return prevVersion; return prevVersion;
@ -55,7 +55,7 @@ public class VersionsStore {
private void startCleanupTask() { private void startCleanupTask() {
cleaner.scheduleAtFixedRate(() -> { cleaner.scheduleAtFixedRate(() -> {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (Map.Entry<EdqsObjectKey, TimedValue<Long>> entry : versions.entrySet()) { for (Map.Entry<EdqsObjectKey, TimedValue> entry : versions.entrySet()) {
if (now - entry.getValue().lastUpdated > expirationMillis) { if (now - entry.getValue().lastUpdated > expirationMillis) {
versions.remove(entry.getKey(), entry.getValue()); versions.remove(entry.getKey(), entry.getValue());
} }
@ -67,11 +67,11 @@ public class VersionsStore {
cleaner.shutdown(); cleaner.shutdown();
} }
private static class TimedValue<V> { private static class TimedValue {
private final long lastUpdated; private final long lastUpdated;
private final V value; private final long value;
public TimedValue(V value) { public TimedValue(long value) {
this.value = value; this.value = value;
this.lastUpdated = System.currentTimeMillis(); this.lastUpdated = System.currentTimeMillis();
} }