Example #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();
  }
Example #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));
  }
Example #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}));
  }
Example #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}));
  }
Example #5
0
  @Override
  public void rollback() throws UnsupportedOperationException {
    commitLock.lock();
    try {
      // flush modified records
      for (int segment = 0; segment < locks.length; segment++) {
        Lock lock = locks[segment].writeLock();
        lock.lock();
        try {
          writeCache[segment].clear();
          if (caches != null) {
            caches[segment].clear();
          }
          uncommittedDataLongs[segment].clear();
          uncommittedIndexTable[segment].clear();
        } finally {
          lock.unlock();
        }
      }

      structuralLock.lock();
      try {
        uncommittedStackPages.clear();

        // restore headVol from backup
        headVol.putData(0, headVolBackup, 0, headVolBackup.length);
        indexPages = indexPagesBackup.clone();

        wal.rollback();
        wal.sync();
      } finally {
        structuralLock.unlock();
      }
    } finally {
      commitLock.unlock();
    }
  }