keith-turner commented on a change in pull request #2117:
URL: https://github.com/apache/accumulo/pull/2117#discussion_r647691304
##########
File path:
server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
##########
@@ -189,4 +194,134 @@ public String toString() {
}
throw new RuntimeException("Unknown type of entry: " + event);
}
+
+ /**
+ * Converts LogFileKey to Key. Creates a Key containing all of the
LogFileKey fields. The fields
+ * are stored so the Key sorts maintaining the legacy sort order. The row of
the Key is composed
+ * of 3 fields: EventNum + tabletID + seq. The EventNum is the byte returned
by eventType(). The
+ * column family is always the event. The column qualifier is dependent of
the type of event and
+ * could be empty.
+ *
+ * <pre>
+ * Key Schema:
+ * Row = EventNum + tabletID + seq
+ * Family = event
+ * Qualifier = tserverSession OR filename OR KeyExtent
+ * </pre>
+ */
+ public Key toKey() throws IOException {
+ byte[] formattedRow;
+ byte eventByte = getEventByte(eventType(event));
+ Text family = new Text(event.name());
+ var kb = Key.builder();
+ switch (event) {
+ case OPEN:
+ formattedRow = formatRow(eventByte, 0, 0);
+ return kb.row(formattedRow).family(family).qualifier(new
Text(tserverSession)).build();
+ case COMPACTION_START:
+ formattedRow = formatRow(eventByte, tabletId, seq);
+ return kb.row(formattedRow).family(family).qualifier(new
Text(filename)).build();
+ case MUTATION:
+ case MANY_MUTATIONS:
+ case COMPACTION_FINISH:
+ return kb.row(formatRow(eventByte, tabletId,
seq)).family(family).build();
+ case DEFINE_TABLET:
+ formattedRow = formatRow(eventByte, tabletId, seq);
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ tablet.writeTo(buffer);
+ var q = copyOf(buffer.getData(), buffer.getLength());
+ buffer.close();
+ return kb.row(formattedRow).family(family).qualifier(q).build();
+ default:
+ throw new AssertionError("Invalid event type in LogFileKey: " + event);
+ }
+ }
+
+ private byte getEventByte(int evenTypeInteger) {
+ return (byte) (evenTypeInteger & 0xff);
+ }
+
+ /**
+ * Format the row using 13 bytes. 1 for event number + 4 for tabletId + 8
for sequence
+ */
+ private byte[] formatRow(byte eventNum, int tabletId, long seq) {
+ byte[] row = new byte[13];
Review comment:
```suggestion
// These will not sort properly when encoded if negative. Negative is
not expected currently, defending against future changes and/or bugs.
Preconditions.checkArgument(eventNum >=0 && seq >= 0);
byte[] row = new byte[13];
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]