HBASE-11864 Enhance HLogPrettyPrinter to print information from WAL Header (Chuhan Yang)

This commit is contained in:
tedyu 2015-04-08 06:15:55 -07:00
parent b6756b39c2
commit a9d7c49a59
3 changed files with 39 additions and 3 deletions

View File

@ -91,6 +91,9 @@ public class ProtobufLogReader extends ReaderBase {
static { static {
writerClsNames.add(ProtobufLogWriter.class.getSimpleName()); writerClsNames.add(ProtobufLogWriter.class.getSimpleName());
} }
// cell codec classname
private String codecClsName = null;
enum WALHdrResult { enum WALHdrResult {
EOF, // stream is at EOF when method starts EOF, // stream is at EOF when method starts
@ -153,9 +156,16 @@ public class ProtobufLogReader extends ReaderBase {
/* /*
* Returns names of the accepted writer classes * Returns names of the accepted writer classes
*/ */
protected List<String> getWriterClsNames() { public List<String> getWriterClsNames() {
return writerClsNames; return writerClsNames;
} }
/*
* Returns the cell codec classname
*/
public String getCodecClsName() {
return codecClsName;
}
protected WALHdrContext readHeader(Builder builder, FSDataInputStream stream) protected WALHdrContext readHeader(Builder builder, FSDataInputStream stream)
throws IOException { throws IOException {
@ -207,6 +217,9 @@ public class ProtobufLogReader extends ReaderBase {
LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset
+ ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent); + ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent);
} }
codecClsName = hdrCtxt.getCellCodecClsName();
return hdrCtxt.getCellCodecClsName(); return hdrCtxt.getCellCodecClsName();
} }

View File

@ -51,7 +51,7 @@ public class SecureProtobufLogReader extends ProtobufLogReader {
} }
@Override @Override
protected List<String> getWriterClsNames() { public List<String> getWriterClsNames() {
return writerClsNames; return writerClsNames;
} }

View File

@ -47,6 +47,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.FSUtils;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader;
// imports for things that haven't moved yet. // imports for things that haven't moved yet.
import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
@ -242,11 +243,33 @@ public class WALPrettyPrinter {
if (!fs.isFile(p)) { if (!fs.isFile(p)) {
throw new IOException(p + " is not a file"); throw new IOException(p + " is not a file");
} }
WAL.Reader log = WALFactory.createReader(fs, p, conf);
if (log instanceof ProtobufLogReader) {
List<String> writerClsNames = ((ProtobufLogReader) log).getWriterClsNames();
if (writerClsNames != null && writerClsNames.size() > 0) {
out.print("Writer Classes: ");
for (int i = 0; i < writerClsNames.size(); i++) {
out.print(writerClsNames.get(i));
if (i != writerClsNames.size() - 1) {
out.print(" ");
}
}
out.println();
}
String cellCodecClsName = ((ProtobufLogReader) log).getCodecClsName();
if (cellCodecClsName != null) {
out.println("Cell Codec Class: " + cellCodecClsName);
}
}
if (outputJSON && !persistentOutput) { if (outputJSON && !persistentOutput) {
out.print("["); out.print("[");
firstTxn = true; firstTxn = true;
} }
WAL.Reader log = WALFactory.createReader(fs, p, conf);
try { try {
WAL.Entry entry; WAL.Entry entry;
while ((entry = log.next()) != null) { while ((entry = log.next()) != null) {