This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new ef213b520b replaces sorted map w/ list for key vals in tablet metadata 
(#4600)
ef213b520b is described below

commit ef213b520b2485f356cec7fd65f3ff4b66f43840
Author: Keith Turner <ktur...@apache.org>
AuthorDate: Fri May 24 12:08:08 2024 -0400

    replaces sorted map w/ list for key vals in tablet metadata (#4600)
    
    This change was made in elasticity as part of a larger change
    to speedup merge, see #4574.  Backported just the part that
    replaced a sortedmap w/ a list in TabletMetadata to speed up
    the code that tracks a tablets key/values.
---
 .../core/metadata/schema/TabletMetadata.java         | 20 +++++++++-----------
 .../core/metadata/schema/TabletMetadataTest.java     | 10 ++++++----
 .../accumulo/server/util/MetadataTableUtil.java      |  8 ++++----
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java
 
b/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java
index f2ad719fd8..33d307ce59 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java
@@ -37,7 +37,6 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.OptionalLong;
 import java.util.Set;
-import java.util.SortedMap;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.clientImpl.ClientContext;
@@ -78,7 +77,6 @@ import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSortedMap;
 import com.google.common.collect.ImmutableSortedMap.Builder;
 import com.google.common.net.HostAndPort;
 
@@ -102,7 +100,7 @@ public class TabletMetadata {
   private final String dirName;
   private final MetadataTime time;
   private final String cloned;
-  private final SortedMap<Key,Value> keyValues;
+  private final List<Entry<Key,Value>> keyValues;
   private final OptionalLong flush;
   private final List<LogEntry> logs;
   private final OptionalLong compact;
@@ -127,8 +125,8 @@ public class TabletMetadata {
     this.dirName = tmBuilder.dirName;
     this.time = tmBuilder.time;
     this.cloned = tmBuilder.cloned;
-    this.keyValues = 
Optional.ofNullable(tmBuilder.keyValues).map(ImmutableSortedMap.Builder::build)
-        .orElse(null);
+    this.keyValues =
+        
Optional.ofNullable(tmBuilder.keyValues).map(ImmutableList.Builder::build).orElse(null);
     this.flush = tmBuilder.flush;
     this.logs = Objects.requireNonNull(tmBuilder.logs.build());
     this.compact = Objects.requireNonNull(tmBuilder.compact);
@@ -382,7 +380,7 @@ public class TabletMetadata {
     return merged;
   }
 
-  public SortedMap<Key,Value> getKeyValues() {
+  public List<Entry<Key,Value>> getKeyValues() {
     Preconditions.checkState(keyValues != null, "Requested key values when it 
was not saved");
     return keyValues;
   }
@@ -430,7 +428,7 @@ public class TabletMetadata {
       final String qual = key.getColumnQualifierData().toString();
 
       if (buildKeyValueMap) {
-        tmBuilder.keyValue(key, kv.getValue());
+        tmBuilder.keyValue(kv);
       }
 
       if (row == null) {
@@ -579,7 +577,7 @@ public class TabletMetadata {
     private String dirName;
     private MetadataTime time;
     private String cloned;
-    private ImmutableSortedMap.Builder<Key,Value> keyValues;
+    private ImmutableList.Builder<Entry<Key,Value>> keyValues;
     private OptionalLong flush = OptionalLong.empty();
     private final ImmutableList.Builder<LogEntry> logs = 
ImmutableList.builder();
     private OptionalLong compact = OptionalLong.empty();
@@ -676,11 +674,11 @@ public class TabletMetadata {
       this.merged = merged;
     }
 
-    void keyValue(Key key, Value value) {
+    void keyValue(Entry<Key,Value> kv) {
       if (this.keyValues == null) {
-        this.keyValues = ImmutableSortedMap.naturalOrder();
+        this.keyValues = ImmutableList.builder();
       }
-      this.keyValues.put(key, value);
+      this.keyValues.add(kv);
     }
 
     TabletMetadata build(EnumSet<ColumnType> fetchedCols) {
diff --git 
a/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java
 
b/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java
index 3b2b4a85ac..8c3d84de2c 100644
--- 
a/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java
+++ 
b/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java
@@ -40,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.lang.reflect.Constructor;
+import java.util.AbstractMap;
 import java.util.EnumSet;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -160,7 +161,9 @@ public class TabletMetadataTest {
     assertEquals(Set.of(tf1, tf2), Set.copyOf(tm.getFiles()));
     assertEquals(Map.of(tf1, dfv1, tf2, dfv2), tm.getFilesMap());
     assertEquals(6L, tm.getFlushId().getAsLong());
-    assertEquals(rowMap, tm.getKeyValues());
+    TreeMap<Key,Value> actualRowMap = new TreeMap<>();
+    tm.getKeyValues().forEach(entry -> actualRowMap.put(entry.getKey(), 
entry.getValue()));
+    assertEquals(rowMap, actualRowMap);
     assertEquals(Map.of(new StoredTabletFile(bf1), 56L, new 
StoredTabletFile(bf2), 59L),
         tm.getLoaded());
     assertEquals(HostAndPort.fromParts("server1", 8555), 
tm.getLocation().getHostAndPort());
@@ -388,7 +391,7 @@ public class TabletMetadataTest {
     b.log(LogEntry.fromPath("localhost+8020/" + UUID.randomUUID()));
     b.scan(stf);
     b.loadedFile(stf, 0L);
-    b.keyValue(new Key(), new Value());
+    b.keyValue(new AbstractMap.SimpleImmutableEntry<>(new Key(), new Value()));
     var tm2 = b.build(EnumSet.allOf(ColumnType.class));
 
     assertEquals(1, tm2.getExternalCompactions().size());
@@ -407,8 +410,7 @@ public class TabletMetadataTest {
     assertEquals(1, tm2.getLoaded().size());
     assertThrows(UnsupportedOperationException.class, () -> 
tm2.getLoaded().put(stf, 0L));
     assertEquals(1, tm2.getKeyValues().size());
-    assertThrows(UnsupportedOperationException.class,
-        () -> tm2.getKeyValues().put(new Key(), new Value()));
+    assertThrows(UnsupportedOperationException.class, () -> 
tm2.getKeyValues().remove(null));
 
   }
 
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
 
b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
index 9209f82e60..e53c908907 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java
@@ -398,12 +398,12 @@ public class MetadataTableUtil {
   }
 
   private static Mutation createCloneMutation(TableId srcTableId, TableId 
tableId,
-      Map<Key,Value> tablet) {
+      Iterable<Entry<Key,Value>> tablet) {
 
-    KeyExtent ke = 
KeyExtent.fromMetaRow(tablet.keySet().iterator().next().getRow());
+    KeyExtent ke = 
KeyExtent.fromMetaRow(tablet.iterator().next().getKey().getRow());
     Mutation m = new Mutation(TabletsSection.encodeRow(tableId, ke.endRow()));
 
-    for (Entry<Key,Value> entry : tablet.entrySet()) {
+    for (Entry<Key,Value> entry : tablet) {
       if (entry.getKey().getColumnFamily().equals(DataFileColumnFamily.NAME)) {
         String cf = entry.getKey().getColumnQualifier().toString();
         if (!cf.startsWith("../") && !cf.contains(":")) {
@@ -538,7 +538,7 @@ public class MetadataTableUtil {
         // delete existing cloned tablet entry
         Mutation m = new Mutation(cloneTablet.getExtent().toMetaRow());
 
-        for (Entry<Key,Value> entry : cloneTablet.getKeyValues().entrySet()) {
+        for (Entry<Key,Value> entry : cloneTablet.getKeyValues()) {
           Key k = entry.getKey();
           m.putDelete(k.getColumnFamily(), k.getColumnQualifier(), 
k.getTimestamp());
         }

Reply via email to