Browse Source

Rename memory to RAM in LiveVersionMap (#104450)

A follow-up to this comment:
https://github.com/elastic/elasticsearch/pull/103979#discussion_r1449907971.
I've tried to limit it to LVM. Also due some basic interfaces and
utilities, not all could be renamed. I've kept `byte` in some places
since it still shows the unit.
Pooya Salehi 1 year ago
parent
commit
1f85ebe196

+ 26 - 26
server/src/main/java/org/elasticsearch/index/engine/LiveVersionMap.java

@@ -40,7 +40,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
 
         /** Tracks bytes used by current map, i.e. what is freed on refresh. For deletes, which are also added to tombstones,
          *  we only account for the CHM entry here, and account for BytesRef/VersionValue against the tombstones, since refresh would not
-         *  clear this RAM. */
+         *  clear this from RAM. */
         final AtomicLong ramBytesUsed = new AtomicLong();
 
         private static final VersionLookup EMPTY = new VersionLookup(Collections.emptyMap());
@@ -70,7 +70,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
                 existingEntriesSize += existingValue == null ? 0 : mapEntryBytesUsed(entry.getKey(), existingValue);
             }
             map.putAll(versionLookup.map);
-            adjustRam(versionLookup.ramBytesUsed() - existingEntriesSize);
+            adjustRamUsage(versionLookup.ramBytesUsed() - existingEntriesSize);
             minDeleteTimestamp.accumulateAndGet(versionLookup.minDeleteTimestamp(), Math::min);
         }
 
@@ -87,7 +87,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
             long ramAccounting = mapEntryBytesUsed(key, value);
             VersionValue previousValue = map.put(key, value);
             ramAccounting += previousValue == null ? 0 : -mapEntryBytesUsed(key, previousValue);
-            adjustRam(ramAccounting);
+            adjustRamUsage(ramAccounting);
             return previousValue;
         }
 
@@ -110,7 +110,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
         VersionValue remove(BytesRef uid) {
             VersionValue previousValue = map.remove(uid);
             if (previousValue != null) {
-                adjustRam(-mapEntryBytesUsed(uid, previousValue));
+                adjustRamUsage(-mapEntryBytesUsed(uid, previousValue));
             }
             return previousValue;
         }
@@ -123,7 +123,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
             return minDeleteTimestamp.get();
         }
 
-        void adjustRam(long value) {
+        void adjustRamUsage(long value) {
             if (value != 0) {
                 long v = ramBytesUsed.addAndGet(value);
                 assert v >= 0 : "bytes=" + v;
@@ -273,7 +273,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
     /**
      * Tracks bytes used by tombstones (deletes)
      */
-    private final AtomicLong ramBytesUsedTombstones = new AtomicLong();
+    private final AtomicLong ramBytesUsedForTombstones = new AtomicLong();
 
     @Override
     public void beforeRefresh() throws IOException {
@@ -391,16 +391,16 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
     }
 
     private void putTombstone(BytesRef uid, DeleteVersionValue version) {
-        long uidRAMBytesUsed = BASE_BYTES_PER_BYTESREF + uid.bytes.length;
-        // Also enroll the delete into tombstones, and account for its RAM too:
+        long uidRamBytesUsed = BASE_BYTES_PER_BYTESREF + uid.bytes.length;
+        // Also enroll the delete into tombstones, and account for its RAM usage too:
         final VersionValue prevTombstone = tombstones.put(uid, version);
-        long accountRam = (BASE_BYTES_PER_CHM_ENTRY + version.ramBytesUsed() + uidRAMBytesUsed);
+        long ramBytes = (BASE_BYTES_PER_CHM_ENTRY + version.ramBytesUsed() + uidRamBytesUsed);
         // Deduct tombstones bytes used for the version we just removed or replaced:
         if (prevTombstone != null) {
-            accountRam -= (BASE_BYTES_PER_CHM_ENTRY + prevTombstone.ramBytesUsed() + uidRAMBytesUsed);
+            ramBytes -= (BASE_BYTES_PER_CHM_ENTRY + prevTombstone.ramBytesUsed() + uidRamBytesUsed);
         }
-        if (accountRam != 0) {
-            long v = ramBytesUsedTombstones.addAndGet(accountRam);
+        if (ramBytes != 0) {
+            long v = ramBytesUsedForTombstones.addAndGet(ramBytes);
             assert v >= 0 : "bytes=" + v;
         }
     }
@@ -410,11 +410,11 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
      */
     void removeTombstoneUnderLock(BytesRef uid) {
         assert assertKeyedLockHeldByCurrentThread(uid);
-        long uidRAMBytesUsed = BASE_BYTES_PER_BYTESREF + uid.bytes.length;
+        long uidRamBytesUsed = BASE_BYTES_PER_BYTESREF + uid.bytes.length;
         final VersionValue prev = tombstones.remove(uid);
         if (prev != null) {
             assert prev.isDelete();
-            long v = ramBytesUsedTombstones.addAndGet(-(BASE_BYTES_PER_CHM_ENTRY + prev.ramBytesUsed() + uidRAMBytesUsed));
+            long v = ramBytesUsedForTombstones.addAndGet(-(BASE_BYTES_PER_CHM_ENTRY + prev.ramBytesUsed() + uidRamBytesUsed));
             assert v >= 0 : "bytes=" + v;
         }
     }
@@ -465,14 +465,14 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
         maps = new Maps();
         tombstones.clear();
         // NOTE: we can't zero this here, because a refresh thread could be calling InternalEngine.pruneDeletedTombstones at the same time,
-        // and this will lead to an assert trip. Presumably it's fine if our ramBytesUsedTombstones is non-zero after clear since the
+        // and this will lead to an assert trip. Presumably it's fine if our ramBytesUsedForTombstones is non-zero after clear since the
         // index is being closed:
-        // ramBytesUsedTombstones.set(0);
+        // ramBytesUsedForTombstones.set(0);
     }
 
     @Override
     public long ramBytesUsed() {
-        return maps.ramBytesUsed() + ramBytesUsedTombstones.get() + ramBytesUsedForArchive();
+        return maps.ramBytesUsed() + ramBytesUsedForTombstones.get() + ramBytesUsedForArchive();
     }
 
     /**
@@ -480,7 +480,7 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
      * archive, if any.
      */
     long ramBytesUsedForRefresh() {
-        return maps.ramBytesUsed() + archive.getMemoryBytesUsed();
+        return maps.ramBytesUsed() + archive.getRamBytesUsed();
     }
 
     /**
@@ -489,29 +489,29 @@ public final class LiveVersionMap implements ReferenceManager.RefreshListener, A
      * In stateful, this is the RAM usage of the current version map, and could be reclaimed by refreshing. It doesn't include tombstones
      * since they don't get cleared on refresh, nor the old version map that is being reclaimed.
      * <p>
-     * In stateless, this is the RAM usage of current and old version map plus the RAM usage of the parts of the archive that require a
-     * new unpromotable refresh. To reclaim all three components we need to refresh AND flush.
+     * In stateless, this is the RAM usage of current and old version map plus the RAM usage of the parts of the archive that require
+     * a new unpromotable refresh. To reclaim all three components we need to refresh AND flush.
      */
     long reclaimableRefreshRamBytes() {
         return archive == LiveVersionMapArchive.NOOP_ARCHIVE
             ? maps.current.ramBytesUsed.get()
-            : maps.ramBytesUsed() + archive.getReclaimableMemoryBytes();
+            : maps.ramBytesUsed() + archive.getReclaimableRamBytes();
     }
 
     /**
      * Returns how much RAM would be freed up by cleaning out the LiveVersionMapArchive.
      */
     long ramBytesUsedForArchive() {
-        return archive.getMemoryBytesUsed();
+        return archive.getRamBytesUsed();
     }
 
     /**
-     * Returns how much RAM is current being freed up by refreshing. In Stateful, this is the RAM usage of the previous version map that
-     * needs to stay around until operations are safely recorded in the Lucene index. In Stateless, this is the RAM usage of a fraction
-     * of the Archive entries that are kept around until an ongoing unpromotable refresh is finished.
+     * Returns how much RAM is current being freed up by refreshing. In Stateful, this is the RAM usage of the previous version map
+     * that needs to stay around until operations are safely recorded in the Lucene index. In Stateless, this is the RAM usage of a
+     * fraction of the Archive entries that are kept around until an ongoing unpromotable refresh is finished.
      */
     long getRefreshingBytes() {
-        return archive == LiveVersionMapArchive.NOOP_ARCHIVE ? maps.old.ramBytesUsed.get() : archive.getRefreshingMemoryBytes();
+        return archive == LiveVersionMapArchive.NOOP_ARCHIVE ? maps.old.ramBytesUsed.get() : archive.getRefreshingRamBytes();
     }
 
     /**

+ 3 - 3
server/src/main/java/org/elasticsearch/index/engine/LiveVersionMapArchive.java

@@ -42,21 +42,21 @@ public interface LiveVersionMapArchive {
     /**
      * Returns the total memory usage if the Archive.
      */
-    default long getMemoryBytesUsed() {
+    default long getRamBytesUsed() {
         return 0L;
     }
 
     /**
      * Returns how much memory could be freed up by creating a new commit and issuing a new unpromotable refresh.
      */
-    default long getReclaimableMemoryBytes() {
+    default long getReclaimableRamBytes() {
         return 0;
     }
 
     /**
      * Returns how much memory will be freed once the current ongoing unpromotable refresh is finished.
      */
-    default long getRefreshingMemoryBytes() {
+    default long getRefreshingRamBytes() {
         return 0;
     }