Пример #1
0
  @Override
  protected void configure() throws JournalException {
    writeLock = LockManager.lockExclusive(getLocation());
    if (writeLock == null || !writeLock.isValid()) {
      close();
      throw new JournalException("Journal is already open for APPEND at %s", getLocation());
    }
    if (txLog.isEmpty()) {
      commit(Tx.TX_NORMAL, 0L, 0L);
    }
    txLog.head(tx);

    File meta = new File(getLocation(), JournalConfiguration.FILE_NAME);
    if (!meta.exists()) {
      try (UnstructuredFile hb = new UnstructuredFile(meta, 12, JournalMode.APPEND)) {
        getMetadata().write(hb);
      }
    }

    super.configure();

    beginTx();
    rollback();
    rollbackPartitionDirs();

    if (tx.journalMaxRowID > 0
        && getPartitionCount() <= Rows.toPartitionIndex(tx.journalMaxRowID)) {
      beginTx();
      commit();
    }
    if (getMetadata().getLag() != -1) {
      this.partitionCleaner = new PartitionCleaner(this, getLocation().getName());
      this.partitionCleaner.start();
    }
  }
Пример #2
0
  @Override
  public final void close() {
    if (open) {
      if (partitionCleaner != null) {
        partitionCleaner.halt();
        partitionCleaner = null;
      }
      try {
        if (isCommitOnClose()) {
          commit();
          purgeUnusedTempPartitions(txLog);
        }
        super.close();
        if (writeLock != null) {
          LockManager.release(writeLock);
          writeLock = null;
        }

        if (discardTxtRaf != null) {
          try {
            discardSink.close();
            discardTxtRaf.close();
          } catch (IOException e) {
            LOGGER.warn("Failed to close discard file");
          }
        }
      } catch (JournalException e) {
        throw new JournalRuntimeException(e);
      }
    }
  }
Пример #3
0
 public void append(Journal<T> journal) throws JournalException {
   try (ConcurrentIterator<T> iterator = journal.concurrentIterator()) {
     for (T obj : iterator) {
       append(obj);
     }
   }
 }
Пример #4
0
 @Override
 void closePartitions() {
   super.closePartitions();
   appendPartition = null;
   appendTimestampHi = -1;
 }