private void writeWALTrailer() { try { int trailerSize = 0; if (this.trailer == null) { // use default trailer. LOG.warn("WALTrailer is null. Continuing with default."); this.trailer = buildWALTrailer(WALTrailer.newBuilder()); trailerSize = this.trailer.getSerializedSize(); } else if ((trailerSize = this.trailer.getSerializedSize()) > this.trailerWarnSize) { // continue writing after warning the user. LOG.warn("Please investigate WALTrailer usage. Trailer size > maximum size : " + trailerSize + " > " + this.trailerWarnSize); } this.trailer.writeTo(output); output.writeInt(trailerSize); output.write(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC); this.trailerWritten = true; } catch (IOException ioe) { LOG.warn("Failed to write trailer, non-fatal, continuing...", ioe); } }
private void writeWALTrailer() { try { int trailerSize = 0; if (this.trailer == null) { // use default trailer. LOG.warn("WALTrailer is null. Continuing with default."); this.trailer = buildWALTrailer(WALTrailer.newBuilder()); trailerSize = this.trailer.getSerializedSize(); } else if ((trailerSize = this.trailer.getSerializedSize()) > this.trailerWarnSize) { // continue writing after warning the user. LOG.warn("Please investigate WALTrailer usage. Trailer size > maximum size : " + trailerSize + " > " + this.trailerWarnSize); } this.trailer.writeTo(output); output.writeInt(trailerSize); output.write(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC); this.trailerWritten = true; } catch (IOException ioe) { LOG.error("Got IOException while writing trailer", ioe); } }
private void writeWALTrailer() { try { int trailerSize = 0; if (this.trailer == null) { // use default trailer. LOG.warn("WALTrailer is null. Continuing with default."); this.trailer = WALTrailer.newBuilder().build(); trailerSize = this.trailer.getSerializedSize(); } else if ((trailerSize = this.trailer.getSerializedSize()) > this.trailerWarnSize) { // continue writing after warning the user. LOG.warn("Please investigate WALTrailer usage. Trailer size > maximum size : " + trailerSize + " > " + this.trailerWarnSize); } this.trailer.writeTo(output); this.output.writeInt(trailerSize); this.output.write(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC); this.trailerWritten = true; } catch (IOException ioe) { LOG.error("Got IOException while writing trailer", ioe); } }
/** * To check whether a trailer is present in a WAL, it seeks to position (fileLength - * PB_WAL_COMPLETE_MAGIC.size() - Bytes.SIZEOF_INT). It reads the int value to know the size of * the trailer, and checks whether the trailer is present at the end or not by comparing the last * PB_WAL_COMPLETE_MAGIC.size() bytes. In case trailer is not present, it returns false; * otherwise, sets the trailer and sets this.walEditsStopOffset variable up to the point just * before the trailer. * <ul> * The trailer is ignored in case: * <li>fileLength is 0 or not correct (when file is under recovery, etc). * <li>the trailer size is negative. * </ul> * <p> * In case the trailer size > this.trailerMaxSize, it is read after a WARN message. * @return true if a valid trailer is present * @throws IOException */ private boolean setTrailerIfPresent() { try { long trailerSizeOffset = this.fileLength - (PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT); if (trailerSizeOffset <= 0) return false;// no trailer possible. this.seekOnFs(trailerSizeOffset); // read the int as trailer size. int trailerSize = this.inputStream.readInt(); ByteBuffer buf = ByteBuffer.allocate(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC.length); this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity()); if (!Arrays.equals(buf.array(), PB_WAL_COMPLETE_MAGIC)) { LOG.trace("No trailer found."); return false; } if (trailerSize < 0) { LOG.warn("Invalid trailer Size " + trailerSize + ", ignoring the trailer"); return false; } else if (trailerSize > this.trailerWarnSize) { // continue reading after warning the user. LOG.warn("Please investigate WALTrailer usage. Trailer size > maximum configured size : " + trailerSize + " > " + this.trailerWarnSize); } // seek to the position where trailer starts. long positionOfTrailer = trailerSizeOffset - trailerSize; this.seekOnFs(positionOfTrailer); // read the trailer. buf = ByteBuffer.allocate(trailerSize);// for trailer. this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity()); trailer = WALTrailer.parseFrom(buf.array()); this.walEditsStopOffset = positionOfTrailer; return true; } catch (IOException ioe) { LOG.warn("Got IOE while reading the trailer. Continuing as if no trailer is present.", ioe); } return false; }
WALTrailer buildWALTrailer(WALTrailer.Builder builder) { return builder.build(); }
void setWALTrailer(WALTrailer walTrailer) { this.trailer = walTrailer; }
@Override public WALTrailer getWALTrailer() { return trailer; }
@Override public WALTrailer getWALTrailer() { return null; }
protected WALTrailer buildWALTrailer(WALTrailer.Builder builder) { return builder.build(); }
@Override public void setWALTrailer(WALTrailer walTrailer) { this.trailer = walTrailer; }
/** * This method is empty as trailer is added only in Protobuf based hlog readers/writers. */ @Override public void setWALTrailer(WALTrailer walTrailer) { }
/** * @return the WALTrailer of the current HLog. It may be null in case of legacy or corrupt WAL * files. */ // TODO: What we need a trailer on WAL for? WALTrailer getWALTrailer();
/** * Sets HLog's WALTrailer. This trailer is appended at the end of WAL on closing. * @param walTrailer trailer to append to WAL. */ void setWALTrailer(WALTrailer walTrailer);
/** * @return the WALTrailer of the current HLog. It may be null in case of legacy or corrupt WAL * files. */ // TODO: What we need a trailer on WAL for? It won't be present on last WAL most of the time. // What then? WALTrailer getWALTrailer();
/** * Sets HLog/WAL's WALTrailer. This trailer is appended at the end of WAL on closing. * @param walTrailer trailer to append to WAL. */ // TODO: Why a trailer on the log? void setWALTrailer(WALTrailer walTrailer);