keith-turner commented on a change in pull request #2117:
URL: https://github.com/apache/accumulo/pull/2117#discussion_r646830017
##########
File path:
server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogFileKey.java
##########
@@ -189,4 +195,90 @@ 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 (separated by underscore). The
EventNum is the integer
+ * 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 {
+ String row = "";
+ int eventNum = eventType(event);
+ String family = event.name();
+ String qual = "";
+ switch (event) {
+ case OPEN:
+ row = formatRow(eventNum, 0, 0);
+ qual = tserverSession;
+ break;
+ case COMPACTION_START:
+ row = formatRow(eventNum, tabletId, seq);
+ if (filename != null)
+ qual = filename;
+ break;
+ case MUTATION:
+ case MANY_MUTATIONS:
+ case COMPACTION_FINISH:
+ row = formatRow(eventNum, tabletId, seq);
+ break;
+ case DEFINE_TABLET:
+ row = formatRow(eventNum, tabletId, seq);
+ // Base64 encode KeyExtent
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ tablet.writeTo(buffer);
+ qual = Base64.getEncoder().encodeToString(copyOf(buffer.getData(),
buffer.getLength()));
+ buffer.close();
+ break;
+ }
+ return new Key(new Text(row), new Text(family), new Text(qual));
+ }
+
+ // format row = 1_000001_0000000001
+ private String formatRow(int eventNum, int tabletId, long seq) {
+ return String.format("%d_%06d_%010d", eventNum, tabletId, seq);
+ }
Review comment:
If possible would be better to avoid Text and use byte[]. Could use
Key.builder() if there is a need to mix types like byte[] and String when
creating a Key.
--
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]