Ejemplo n.º 1
0
  @Override
  public void initOpen() {
    // TODO disable readonly feature for this store

    realVol = vol;

    if (readonly && !Volume.isEmptyFile(fileName + ".wal.0"))
      throw new DBException.WrongConfig(
          "There is dirty WAL file, but storage is read-only. Can not replay file");

    wal.open(
        new WriteAheadLog.WALReplay() {

          @Override
          public void beforeReplayStart() {}

          @Override
          public void writeLong(long offset, long value) {
            if (CC.ASSERT && offset % 8 != 0) throw new AssertionError();
            realVol.ensureAvailable(Fun.roundUp(offset + 8, StoreDirect.PAGE_SIZE));
            realVol.putLong(offset, value);
          }

          @Override
          public void writeRecord(long recid, long walId, Volume vol, long volOffset, int length) {
            throw new DBException.DataCorruption();
          }

          @Override
          public void writeByteArray(
              long offset, long walId, Volume vol, long volOffset, int length) {
            if (CC.ASSERT && offset % 8 != 0) throw new AssertionError();
            realVol.ensureAvailable(Fun.roundUp(offset + length, StoreDirect.PAGE_SIZE));
            vol.transferInto(volOffset, realVol, offset, length);
          }

          @Override
          public void beforeDestroyWAL() {}

          @Override
          public void commit() {}

          @Override
          public void rollback() {
            throw new DBException.DataCorruption();
          }

          @Override
          public void writeTombstone(long recid) {
            throw new DBException.DataCorruption();
          }

          @Override
          public void writePreallocate(long recid) {
            throw new DBException.DataCorruption();
          }
        });
    realVol.sync();
    wal.destroyWalFiles();

    initOpenPost();

    // TODO reenable this assertion
    //        if(CC.PARANOID)
    //            storeCheck();
  }