This is an automated email from the ASF dual-hosted git repository.
mmiller 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 89b411c Adds tests to LogFileKeyTest (#2177)
89b411c is described below
commit 89b411c391675cb3f1faed83f2dd4451b2ac6d12
Author: Mike Miller
AuthorDate: Wed Jun 23 09:57:31 2021 -0400
Adds tests to LogFileKeyTest (#2177)
---
.../apache/accumulo/tserver/logger/LogFileKey.java | 15 ++-
.../accumulo/tserver/log/LogFileKeyTest.java | 49 ++
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git
a/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
index cf5dc21..b860be5 100644
---
a/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
+++
b/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
@@ -28,6 +28,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.util.Arrays;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
@@ -36,10 +37,13 @@ import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
public class LogFileKey implements WritableComparable {
+ private static final Logger log = LoggerFactory.getLogger(LogFileKey.class);
public LogEvents event;
public String filename = null;
@@ -258,7 +262,9 @@ public class LogFileKey implements
WritableComparable {
/**
* Format the row using 13 bytes encoded to allow proper sorting of the
RFile Key. The highest
- * byte is for the event number, 4 bytes for the tabletId and 8 bytes for
the sequence long.
+ * byte is for the event number, 4 bytes for the tabletId and 8 bytes for
the sequence long. The
+ * conversions of integer to byte[] and long to byte[] is similar to what
DataOutputStream does
+ * for writeInt() and writeLong()
*/
private byte[] formatRow(int tabletId, long seq) {
byte eventNum = getEventByte();
@@ -283,11 +289,14 @@ public class LogFileKey implements
WritableComparable {
row[10] = (byte) ((seq >>> 16) & mask);
row[11] = (byte) ((seq >>> 8) & mask);
row[12] = (byte) (seq & mask);
+
+log.trace("Convert {} {} {} to row {}", event, tabletId, seq,
Arrays.toString(row));
return row;
}
/**
- * Extract the tabletId integer from the byte encoded Row.
+ * Extract the tabletId integer from the byte encoded Row. Similar to what
DataInputStream does
+ * for readInt()
*/
private static int getTabletId(byte[] row) {
int mask = 0xff; // use a mask of int type to convert byte to int without
sign extension
@@ -335,6 +344,8 @@ public class LogFileKey implements
WritableComparable {
if (eventType(logFileKey.event) != rowParts[0]) {
throw new AssertionError("Event in row differs from column family. Key:
" + key);
}
+log.trace("From row {} get {} {} {}", Arrays.toString(rowParts),
logFileKey.event,
+logFileKey.tabletId, logFileKey.seq);
// handle special cases of what is stored in the qualifier
switch (logFileKey.event) {
diff --git
a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java
b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java
index 72cc339..0f04aca 100644
---
a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java
+++
b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java
@@ -20,12 +20,17 @@ package org.apache.accumulo.tserver.log;
import static org.junit.Assert.assertEquals;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.tserver.logger.LogEvents;
import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.hadoop.io.Text;
import org.junit.Test;
public class LogFileKeyTest {
@@ -98,4 +103,48 @@ public class LogFileKeyTest {
}
}
+
+ private void testToFromKey(int tabletId, long seq) throws IOException {
+var logFileKey = nk(LogEvents.DEFINE_TABLET, tabletId, seq);
+logFileKey.tablet = new KeyExtent(TableId.of("5"), new Text("b"), null);
+Key k = logFileKey.toKey();
+
+var converted = LogFileKey.fromKey(k);
+assertEquals("Failed to convert tabletId = " + tabletId + " seq = " + seq,
logFileKey,
+converted);
+