Exemple #1
0
  @Test
  public void compact_record_file_used() throws IOException {
    e = openEngine();
    Map<Long, String> m = fill(e);
    e.commit();
    e.close();

    // now create fake compaction file, that should be ignored since seal is broken
    String csealFile = e.getWalFileName("c");
    Volume cseal = new Volume.FileChannelVol(new File(csealFile));
    cseal.ensureAvailable(16);
    cseal.putLong(8, 234238492376748923L);
    cseal.close();

    // create record wal file
    String r0 = e.getWalFileName("r0");
    Volume r = new Volume.FileChannelVol(new File(r0));
    r.ensureAvailable(100000);
    r.putLong(8, StoreWAL.WAL_SEAL);

    long offset = 16;
    // modify all records in map via record wal
    for (long recid : m.keySet()) {
      r.putUnsignedByte(offset++, 5 << 4);
      r.putSixLong(offset, recid);
      offset += 6;
      String val = "aa" + recid;
      m.put(recid, val);
      DataIO.DataOutputByteArray b = new DataIO.DataOutputByteArray();
      Serializer.STRING.serialize(b, val);
      int size = b.pos;
      r.putInt(offset, size);
      offset += 4;
      r.putData(offset, b.buf, 0, size);
      offset += size;
    }
    r.putUnsignedByte(offset, 0);
    r.sync();
    r.putLong(8, StoreWAL.WAL_SEAL);
    r.sync();
    r.close();

    // reopen engine, record WAL should be replayed
    e = openEngine();

    // check content of log file replayed into main store
    for (long recid : m.keySet()) {
      assertEquals(m.get(recid), e.get(recid, Serializer.STRING));
    }
    e.close();
  }