예제 #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();
  }
예제 #2
0
  protected void walCompactSwap(boolean seal) {
    e = openEngine();
    Map<Long, String> m = fill(e);
    e.commit();
    e.close();

    // copy file into new location
    String compactTarget = e.getWalFileName("c.compactXXX");
    Volume f0 = new Volume.FileChannelVol(f);
    Volume f = new Volume.FileChannelVol(new File(compactTarget));
    f0.copyEntireVolumeTo(f);
    f0.close();
    f.sync();
    f.close();

    e = openEngine();
    // modify orig file and close
    Long recid = m.keySet().iterator().next();
    e.update(recid, "aaa", Serializer.STRING);
    if (!seal) m.put(recid, "aaa");
    e.commit();
    e.close();

    // now move file so it is valid compacted file
    assertTrue(new File(compactTarget).renameTo(new File(e.getWalFileName("c.compact"))));

    // create compaction seal
    String compactSeal = e.getWalFileName("c");
    Volume sealVol = new Volume.FileChannelVol(new File(compactSeal));
    sealVol.ensureAvailable(16);
    sealVol.putLong(8, StoreWAL.WAL_SEAL + (seal ? 0 : 1));
    sealVol.sync();
    sealVol.close();

    // now reopen file and check its content
    // change should be reverted, since compaction file was used
    e = openEngine();

    for (Long recid2 : m.keySet()) {
      assertEquals(m.get(recid2), e.get(recid2, Serializer.STRING));
    }
  }