use of org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureWALEntry in project hbase by apache.
the class ProcedureWALFormatReader method read.
public void read(ProcedureWALFile log) throws IOException {
localTracker = log.getTracker();
if (localTracker.isPartial()) {
LOG.info("Rebuilding tracker for {}", log);
}
long count = 0;
FSDataInputStream stream = log.getStream();
try {
boolean hasMore = true;
while (hasMore) {
ProcedureWALEntry entry = ProcedureWALFormat.readEntry(stream);
if (entry == null) {
LOG.warn("Nothing left to decode. Exiting with missing EOF, log={}", log);
break;
}
count++;
switch(entry.getType()) {
case PROCEDURE_WAL_INIT:
readInitEntry(entry);
break;
case PROCEDURE_WAL_INSERT:
readInsertEntry(entry);
break;
case PROCEDURE_WAL_UPDATE:
case PROCEDURE_WAL_COMPACT:
readUpdateEntry(entry);
break;
case PROCEDURE_WAL_DELETE:
readDeleteEntry(entry);
break;
case PROCEDURE_WAL_EOF:
hasMore = false;
break;
default:
throw new CorruptedWALProcedureStoreException("Invalid entry: " + entry);
}
}
LOG.info("Read {} entries in {}", count, log);
} catch (InvalidProtocolBufferException e) {
LOG.error("While reading entry #{} in {}", count, log, e);
loader.markCorruptedWAL(log, e);
}
if (!localProcedureMap.isEmpty()) {
log.setProcIds(localProcedureMap.getMinModifiedProcId(), localProcedureMap.getMaxModifiedProcId());
if (localTracker.isPartial()) {
localTracker.setMinMaxModifiedProcIds(localProcedureMap.getMinModifiedProcId(), localProcedureMap.getMaxModifiedProcId());
}
procedureMap.merge(localProcedureMap);
}
// Do not reset the partial flag for local tracker, as here the local tracker only know the
// procedures which are modified in this file.
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureWALEntry in project hbase by apache.
the class ProcedureWALFormat method readTrailer.
public static ProcedureWALTrailer readTrailer(FSDataInputStream stream, long startPos, long size) throws IOException {
// Beginning of the Trailer Jump. 17 = 1 byte version + 8 byte magic + 8 byte offset
long trailerPos = size - 17;
if (trailerPos < startPos) {
throw new InvalidWALDataException("Missing trailer: size=" + size + " startPos=" + startPos);
}
stream.seek(trailerPos);
int version = stream.read();
if (version != TRAILER_VERSION) {
throw new InvalidWALDataException("Invalid Trailer version. got " + version + " expected " + TRAILER_VERSION);
}
long magic = StreamUtils.readLong(stream);
if (magic != TRAILER_MAGIC) {
throw new InvalidWALDataException("Invalid Trailer magic. got " + magic + " expected " + TRAILER_MAGIC);
}
long trailerOffset = StreamUtils.readLong(stream);
stream.seek(trailerOffset);
ProcedureWALEntry entry = readEntry(stream);
if (entry.getType() != ProcedureWALEntry.Type.PROCEDURE_WAL_EOF) {
throw new InvalidWALDataException("Invalid Trailer begin");
}
ProcedureWALTrailer trailer = ProcedureWALTrailer.newBuilder().setVersion(version).setTrackerPos(stream.getPos()).build();
return trailer;
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureWALEntry in project hbase by apache.
the class ProcedureWALPrettyPrinter method processProcedureWALFile.
public void processProcedureWALFile(ProcedureWALFile log) throws IOException {
log.open();
ProcedureWALHeader header = log.getHeader();
printHeader(header);
FSDataInputStream stream = log.getStream();
try {
boolean hasMore = true;
while (hasMore) {
ProcedureWALEntry entry = ProcedureWALFormat.readEntry(stream);
if (entry == null) {
out.println("No more entry, exiting with missing EOF");
hasMore = false;
break;
}
switch(entry.getType()) {
case PROCEDURE_WAL_EOF:
hasMore = false;
break;
default:
printEntry(entry);
}
}
} catch (IOException e) {
out.println("got an exception while reading the procedure WAL " + e.getMessage());
} finally {
log.close();
}
}
Aggregations