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

ctubbsii 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 a28b27a  Add extent to metadata update failure logs (#2086)
a28b27a is described below

commit a28b27a442f919dc94bfa1483f1361ba2a08c6c8
Author: jeff <jffry.schm...@gmail.com>
AuthorDate: Tue May 11 17:58:59 2021 -0400

    Add extent to metadata update failure logs (#2086)
---
 .../org/apache/accumulo/core/data/Mutation.java    | 32 ++++++++++++++++++++++
 .../apache/accumulo/core/data/MutationTest.java    | 20 ++++++++++++++
 .../accumulo/server/util/MetadataTableUtil.java    | 13 ++++++---
 .../accumulo/test/MetaConstraintRetryIT.java       |  2 +-
 4 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java 
b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
index 03d01e0..f0261b2 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
@@ -18,6 +18,7 @@
  */
 package org.apache.accumulo.core.data;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Objects.requireNonNull;
 
 import java.io.DataInput;
@@ -1772,4 +1773,35 @@ public class Mutation implements Writable {
     return this.useOldDeserialize ? SERIALIZED_FORMAT.VERSION1 : 
SERIALIZED_FORMAT.VERSION2;
   }
 
+  /**
+   * Creates a multi-lined, human-readable String for this mutation.
+   *
+   * This method creates many intermediate Strings and should not be used for 
large volumes of
+   * Mutations.
+   *
+   * @return A multi-lined, human-readable String for this mutation.
+   *
+   * @since 2.1.0
+   */
+  public String prettyPrint() {
+    StringBuilder sb = new StringBuilder();
+
+    sb.append("mutation: ").append(new String(row, UTF_8)).append('\n');
+    for (ColumnUpdate update : getUpdates()) {
+      sb.append(" update: ");
+      sb.append(new String(update.getColumnFamily(), UTF_8));
+      sb.append(':');
+      sb.append(new String(update.getColumnQualifier(), UTF_8));
+      sb.append(" value ");
+
+      if (update.isDeleted()) {
+        sb.append("[delete]");
+      } else {
+        sb.append(new String(update.getValue(), UTF_8));
+      }
+      sb.append('\n');
+    }
+
+    return sb.toString();
+  }
 }
diff --git a/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java 
b/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
index 0e74ecb..be3c29d 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
@@ -920,4 +920,24 @@ public class MutationTest {
     m.estRowAndLargeValSize += (Long.MAX_VALUE / 2);
     m.put("cf", "cq2", "v");
   }
+
+  @Test
+  public void testPrettyPrint() {
+    String row = "row";
+    String fam1 = "fam1";
+    String fam2 = "fam2";
+    String qual1 = "qual1";
+    String qual2 = "qual2";
+    String value1 = "value1";
+
+    Mutation m = new Mutation("row");
+    m.put(fam1, qual1, value1);
+    m.putDelete(fam2, qual2);
+    m.getUpdates(); // serialize
+
+    String expected = "mutation: " + row + "\n update: " + fam1 + ":" + qual1 
+ " value " + value1
+        + "\n update: " + fam2 + ":" + qual2 + " value [delete]\n";
+
+    assertEquals(expected, m.prettyPrint());
+  }
 }
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 27c53ac..544b515 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
@@ -144,10 +144,11 @@ public class MetadataTableUtil {
   public static void update(ServerContext context, ServiceLock zooLock, 
Mutation m,
       KeyExtent extent) {
     Writer t = extent.isMeta() ? getRootTable(context) : 
getMetadataTable(context);
-    update(context, t, zooLock, m);
+    update(context, t, zooLock, m, extent);
   }
 
-  public static void update(ServerContext context, Writer t, ServiceLock 
zooLock, Mutation m) {
+  public static void update(ServerContext context, Writer t, ServiceLock 
zooLock, Mutation m,
+      KeyExtent extent) {
     if (zooLock != null)
       putLockID(context, zooLock, m);
     while (true) {
@@ -155,9 +156,9 @@ public class MetadataTableUtil {
         t.update(m);
         return;
       } catch (AccumuloException | TableNotFoundException | 
AccumuloSecurityException e) {
-        log.error("{}", e.getMessage(), e);
+        logUpdateFailure(m, extent, e);
       } catch (ConstraintViolationException e) {
-        log.error("{}", e.getMessage(), e);
+        logUpdateFailure(m, extent, e);
         // retrying when a CVE occurs is probably futile and can cause 
problems, see ACCUMULO-3096
         throw new RuntimeException(e);
       }
@@ -165,6 +166,10 @@ public class MetadataTableUtil {
     }
   }
 
+  private static void logUpdateFailure(Mutation m, KeyExtent extent, Exception 
e) {
+    log.error("Failed to write metadata updates for extent {} {}", extent, 
m.prettyPrint(), e);
+  }
+
   public static void updateTabletFlushID(KeyExtent extent, long flushID, 
ServerContext context,
       ServiceLock zooLock) {
     TabletMutator tablet = context.getAmple().mutateTablet(extent);
diff --git 
a/test/src/main/java/org/apache/accumulo/test/MetaConstraintRetryIT.java 
b/test/src/main/java/org/apache/accumulo/test/MetaConstraintRetryIT.java
index a38f7d5..9e0476e 100644
--- a/test/src/main/java/org/apache/accumulo/test/MetaConstraintRetryIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/MetaConstraintRetryIT.java
@@ -55,7 +55,7 @@ public class MetaConstraintRetryIT extends 
AccumuloClusterHarness {
       m.put("badcolfam", "badcolqual", "3");
 
       try {
-        MetadataTableUtil.update(context, w, null, m);
+        MetadataTableUtil.update(context, w, null, m, extent);
       } catch (RuntimeException e) {
         if 
(e.getCause().getClass().equals(ConstraintViolationException.class)) {
           throw (ConstraintViolationException) e.getCause();

Reply via email to