예제 #1
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);
      }
    }
  }
예제 #2
0
  public void purgeUnusedTempPartitions(TxLog txLog) throws JournalException {
    final Tx tx = new Tx();
    final String lagPartitionName =
        hasIrregularPartition() ? getIrregularPartition().getName() : null;

    File[] files =
        getLocation()
            .listFiles(
                new FileFilter() {
                  public boolean accept(File f) {
                    return f.isDirectory()
                        && f.getName().startsWith(Constants.TEMP_DIRECTORY_PREFIX)
                        && (lagPartitionName == null || !lagPartitionName.equals(f.getName()));
                  }
                });

    if (files != null) {

      Arrays.sort(files);

      for (int i = 0; i < files.length; i++) {

        if (!txLog.isEmpty()) {
          txLog.head(tx);
          if (files[i].getName().equals(tx.lagName)) {
            continue;
          }
        }

        // get exclusive lock
        Lock lock = LockManager.lockExclusive(files[i]);
        try {
          if (lock != null && lock.isValid()) {
            LOGGER.trace("Purging : %s", files[i]);
            if (!Files.delete(files[i])) {
              LOGGER.info("Could not purge: %s", files[i]);
            }
          } else {
            LOGGER.trace("Partition in use: %s", files[i]);
          }
        } finally {
          LockManager.release(lock);
        }
      }
    }
  }
  public V get(K key) {
    V v = cache.getIfPresent(key);
    if (v == null) {
      try {
        lockManager.hold(locks, key);
        if (v == null) {
          v = loader.load(key);
          cache.put(key, v);
        }
      } catch (Exception ex) {
        PGException.pgThrow(ex);
      } finally {
        lockManager.release(locks, key);
      }
    }

    return v;
  }