Exemplo n.º 1
0
  /**
   * Destroy the store
   *
   * @throws IOException if it has difficulty removing the log files
   */
  public void destroy() throws IOException {
    // Prep all the sub-stores to be destroyed
    for (SubStore subStore : subStores) {
      subStore.prepareDestroy();
    }

    log.deletePersistentStore();
    FileSystem.destroy(storeLocation, true);
  }
Exemplo n.º 2
0
 /**
  * Log an update. Will flush to disk before returning.
  *
  * @param o Update argument
  * @throws IllegalStateException if the current thread does not hold a non-exclusive mutator lock
  * @throws IOException If errors accessing the file system occur
  */
 public void update(Object o) throws IOException {
   final Long lockStateVal = lockState.get();
   if (lockStateVal == null || lockStateVal == 0)
     throw new IllegalStateException(
         "PersistentStrore.update:" + "Must acquire mutator lock before calling update()");
   synchronized (this) {
     log.update(o, true);
     updateCount++;
     snapshotHandler.updatePerformed(updateCount);
   }
 }
Exemplo n.º 3
0
  /**
   * Close this PersistentStore without destroying its contents
   *
   * @throws IOException If file system access errors are encountered
   */
  public void close() throws IOException {
    try {
      // Using write lock because we want an exclusive lock
      mutatorLock.writeLock();
      updateCount = 0;

      // Don't need to sync on this because
      // mutatorLock.writeLock() gives us an exclusive lock
      log.close();
    } finally {
      // Using write lock because we want an exclusive lock
      mutatorLock.writeUnlock();
    }
  }
Exemplo n.º 4
0
  /**
   * Construct a store that will persist its data to the specified directory.
   *
   * @param logDir Directory where the store should persist its data. must exist.
   * @param logHandler Object that will process the log and last snapshot to recover the server's
   *     state
   * @param snapshotHandler the server is called back after an update so it can decide whether or
   *     not to do a snapshot.
   * @throws StoreException if there is a problem setting up the store
   */
  public PersistentStore(String logDir, LogHandler logHandler, SnapshotHandler snapshotHandler)
      throws StoreException {
    this.snapshotHandler = snapshotHandler;
    storeLocation = new File(logDir);

    try {
      log = new ReliableLog(storeLocation.getCanonicalPath(), logHandler);
    } catch (IOException e) {
      throw new CorruptedStoreException("Failure creating reliable log", e);
    }

    try {
      log.recover();
    } catch (IOException e) {
      throw new CorruptedStoreException("Failure recovering reliable log", e);
    }
  }