Exemplo n.º 1
0
  @Test
  public void open_ignores_rollback() {
    File f = TT.tempDbFile();
    WriteAheadLog wal = new WriteAheadLog(f.getPath());
    wal.walPutLong(1L, 11L);
    wal.commit();
    wal.walPutLong(2L, 33L);
    wal.rollback();
    wal.walPutLong(3L, 33L);
    wal.commit();
    wal.seal();
    wal.close();

    wal = new WriteAheadLog(f.getPath());
    wal.open(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeLong, 1L, 11L},
            new Object[] {WALSequence.commit},
            // 2L is ignored, rollback section is skipped on hard replay
            new Object[] {WALSequence.writeLong, 3L, 33L},
            new Object[] {WALSequence.commit}));
    wal.destroyWalFiles();
    wal.close();

    f.delete();
  }
Exemplo n.º 2
0
  @Test
  public void skip_rollback_last_rollback() {
    WriteAheadLog wal = new WriteAheadLog(null);
    wal.walPutLong(1L, 11L);
    wal.commit();
    long o1 = wal.fileOffset;
    wal.walPutLong(2L, 33L);
    wal.commit();
    long o2 = wal.fileOffset;
    wal.walPutLong(3L, 33L);
    wal.rollback();
    wal.seal();

    assertEquals(o1, wal.skipRollbacks(o1));
    assertEquals(0, wal.skipRollbacks(o2));
  }
Exemplo n.º 3
0
  @Test
  public void rollback() {
    WriteAheadLog wal = new WriteAheadLog(null);
    wal.open(WriteAheadLog.NOREPLAY);
    wal.startNextFile();

    wal.walPutLong(111L, 1000);
    wal.rollback();
    wal.seal();

    wal.replayWAL(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeLong, 111L, 1000L},
            new Object[] {WALSequence.rollback}));
  }
Exemplo n.º 4
0
  @Test
  public void cut_broken_end_rollback() {
    String f = TT.tempDbFile().getPath();
    WriteAheadLog wal = new WriteAheadLog(f);
    wal.walPutLong(1L, 11L);
    wal.commit();
    wal.walPutLong(2L, 22L);
    wal.commit();
    wal.walPutLong(3L, 33L);
    wal.rollback();
    wal.walPutLong(4L, 44L);
    wal.curVol.sync();
    wal.close();

    wal = new WriteAheadLog(f);
    wal.open(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeLong, 1L, 11L},
            new Object[] {WALSequence.commit},
            new Object[] {WALSequence.writeLong, 2L, 22L},
            new Object[] {WALSequence.commit}));
  }