Esempio n. 1
0
  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;
  }
Esempio n. 2
0
 public static void writeEntry(
     ByteSlot slot, ProcedureWALEntry.Type type, Procedure proc, Procedure[] subprocs)
     throws IOException {
   ProcedureWALEntry.Builder builder = ProcedureWALEntry.newBuilder();
   builder.setType(type);
   builder.addProcedure(Procedure.convert(proc));
   if (subprocs != null) {
     for (int i = 0; i < subprocs.length; ++i) {
       builder.addProcedure(Procedure.convert(subprocs[i]));
     }
   }
   builder.build().writeDelimitedTo(slot);
 }
Esempio n. 3
0
  /*
   * +-----------------+
   * | END OF WAL DATA | <---+
   * +-----------------+     |
   * |                 |     |
   * |     Tracker     |     |
   * |                 |     |
   * +-----------------+     |
   * |     version     |     |
   * +-----------------+     |
   * |  TRAILER_MAGIC  |     |
   * +-----------------+     |
   * |      offset     |-----+
   * +-----------------+
   */
  public static long writeTrailer(FSDataOutputStream stream, ProcedureStoreTracker tracker)
      throws IOException {
    long offset = stream.getPos();

    // Write EOF Entry
    ProcedureWALEntry.newBuilder()
        .setType(ProcedureWALEntry.Type.PROCEDURE_WAL_EOF)
        .build()
        .writeDelimitedTo(stream);

    // Write Tracker
    tracker.writeTo(stream);

    stream.write(TRAILER_VERSION);
    StreamUtils.writeLong(stream, TRAILER_MAGIC);
    StreamUtils.writeLong(stream, offset);
    return stream.getPos() - offset;
  }
Esempio n. 4
0
 public static void writeDelete(ByteSlot slot, long procId) throws IOException {
   ProcedureWALEntry.Builder builder = ProcedureWALEntry.newBuilder();
   builder.setType(ProcedureWALEntry.Type.PROCEDURE_WAL_DELETE);
   builder.setProcId(procId);
   builder.build().writeDelimitedTo(slot);
 }
Esempio n. 5
0
 public static ProcedureWALEntry readEntry(InputStream stream) throws IOException {
   return ProcedureWALEntry.parseDelimitedFrom(stream);
 }