Search in sources :

Example 1 with ProtobufLogReader

use of org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader in project hbase by apache.

the class WALPrettyPrinter method processFile.

/**
   * reads a log file and outputs its contents, one transaction at a time, as
   * specified by the currently configured options
   *
   * @param conf
   *          the HBase configuration relevant to this log file
   * @param p
   *          the path of the log file to be read
   * @throws IOException
   *           may be unable to access the configured filesystem or requested
   *           file.
   */
public void processFile(final Configuration conf, final Path p) throws IOException {
    FileSystem fs = p.getFileSystem(conf);
    if (!fs.exists(p)) {
        throw new FileNotFoundException(p.toString());
    }
    if (!fs.isFile(p)) {
        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) {
        out.print("[");
        firstTxn = true;
    }
    try {
        WAL.Entry entry;
        while ((entry = log.next()) != null) {
            WALKey key = entry.getKey();
            WALEdit edit = entry.getEdit();
            // begin building a transaction structure
            Map<String, Object> txn = key.toStringMap();
            long writeTime = key.getWriteTime();
            // check output filters
            if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence)
                continue;
            if (region != null && !((String) txn.get("region")).equals(region))
                continue;
            // initialize list into which we will store atomic actions
            List<Map> actions = new ArrayList<>();
            for (Cell cell : edit.getCells()) {
                // add atomic operation to txn
                Map<String, Object> op = new HashMap<>(toStringMap(cell));
                if (outputValues)
                    op.put("value", Bytes.toStringBinary(CellUtil.cloneValue(cell)));
                // check row output filter
                if (row == null || ((String) op.get("row")).equals(row)) {
                    actions.add(op);
                }
            }
            if (actions.isEmpty())
                continue;
            txn.put("actions", actions);
            if (outputJSON) {
                // JSON output is a straightforward "toString" on the txn object
                if (firstTxn)
                    firstTxn = false;
                else
                    out.print(",");
                // encode and print JSON
                out.print(MAPPER.writeValueAsString(txn));
            } else {
                // Pretty output, complete with indentation by atomic action
                out.println("Sequence=" + txn.get("sequence") + " " + ", region=" + txn.get("region") + " at write timestamp=" + new Date(writeTime));
                for (int i = 0; i < actions.size(); i++) {
                    Map op = actions.get(i);
                    out.println("row=" + op.get("row") + ", column=" + op.get("family") + ":" + op.get("qualifier"));
                    if (op.get("tag") != null) {
                        out.println("    tag: " + op.get("tag"));
                    }
                    if (outputValues)
                        out.println("    value: " + op.get("value"));
                }
            }
        }
    } finally {
        log.close();
    }
    if (outputJSON && !persistentOutput) {
        out.print("]");
    }
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) WALEdit(org.apache.hadoop.hbase.regionserver.wal.WALEdit) FileSystem(org.apache.hadoop.fs.FileSystem) ProtobufLogReader(org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader) HashMap(java.util.HashMap) Map(java.util.Map) Cell(org.apache.hadoop.hbase.Cell)

Example 2 with ProtobufLogReader

use of org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader in project hbase by apache.

the class WALEntryStream method currentTrailerSize.

private long currentTrailerSize() {
    long size = -1L;
    if (reader instanceof ProtobufLogReader) {
        final ProtobufLogReader pblr = (ProtobufLogReader) reader;
        size = pblr.trailerSize();
    }
    return size;
}
Also used : ProtobufLogReader(org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader)

Aggregations

ProtobufLogReader (org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Cell (org.apache.hadoop.hbase.Cell)1 WALEdit (org.apache.hadoop.hbase.regionserver.wal.WALEdit)1