Example #1
0
  public void recoverBookieData(
      final Set<BookieSocketAddress> bookiesSrc, boolean dryrun, boolean skipOpenLedgers)
      throws InterruptedException, BKException {
    SyncObject sync = new SyncObject();
    // Call the async method to recover bookie data.
    asyncRecoverBookieData(
        bookiesSrc,
        dryrun,
        skipOpenLedgers,
        new RecoverCallback() {
          @Override
          public void recoverComplete(int rc, Object ctx) {
            LOG.info("Recover bookie operation completed with rc: " + rc);
            SyncObject syncObj = (SyncObject) ctx;
            synchronized (syncObj) {
              syncObj.rc = rc;
              syncObj.value = true;
              syncObj.notify();
            }
          }
        },
        sync);

    // Wait for the async method to complete.
    synchronized (sync) {
      while (sync.value == false) {
        sync.wait();
      }
    }
    if (sync.rc != BKException.Code.OK) {
      throw BKException.create(sync.rc);
    }
  }
Example #2
0
 public SortedMap<Long, LedgerMetadata> getLedgersContainBookies(Set<BookieSocketAddress> bookies)
     throws InterruptedException, BKException {
   final SyncObject sync = new SyncObject();
   final AtomicReference<SortedMap<Long, LedgerMetadata>> resultHolder =
       new AtomicReference<SortedMap<Long, LedgerMetadata>>(null);
   asyncGetLedgersContainBookies(
       bookies,
       new GenericCallback<SortedMap<Long, LedgerMetadata>>() {
         @Override
         public void operationComplete(int rc, SortedMap<Long, LedgerMetadata> result) {
           LOG.info("GetLedgersContainBookies completed with rc : {}", rc);
           synchronized (sync) {
             sync.rc = rc;
             sync.value = true;
             resultHolder.set(result);
             sync.notify();
           }
         }
       });
   synchronized (sync) {
     while (sync.value == false) {
       sync.wait();
     }
   }
   if (sync.rc != BKException.Code.OK) {
     throw BKException.create(sync.rc);
   }
   return resultHolder.get();
 }
  /** @see com.emc.atmos.sync.plugins.SyncPlugin#filter(com.emc.atmos.sync.plugins.SyncObject) */
  @Override
  public synchronized void filter(SyncObject obj) {
    try {
      if (out == null) {
        out = new PrintWriter(new BufferedWriter(new FileWriter(new File(filename))));
      }
    } catch (IOException e) {
      throw new RuntimeException("Error writing to ID log file: " + e.getMessage(), e);
    }

    try {
      getNext().filter(obj);
      out.println(obj.getSourceURI().toASCIIString() + ", " + obj.getDestURI().toASCIIString());
    } catch (RuntimeException e) {
      // Log the error
      out.println(obj.getSourceURI().toASCIIString() + ", FAILED: " + e.getMessage());
      throw e;
    }
  }
Example #4
0
  @Override
  public void run() {
    String sourceId = objectContext.getSourceSummary().getIdentifier();

    if (!syncControl.isRunning()) {
      log.debug("aborting sync task because terminate() was called: " + sourceId);
      return;
    }

    boolean processed = false, recordExists = false;
    SyncRecord record;
    try {

      // this should lazy-load all but metadata from the storage; this is so we see
      // ObjectNotFoundException here
      objectContext.setObject(source.loadObject(sourceId));

      ObjectMetadata metadata = objectContext.getObject().getMetadata();

      // truncate milliseconds (the DB only stores to the second)
      Date mtime = null;
      if (metadata.getModificationTime() != null)
        mtime = new Date(metadata.getModificationTime().getTime() / 1000 * 1000);

      record = dbService.getSyncRecord(objectContext);
      recordExists = record != null;
      if (record != null && record.getTargetId() != null)
        objectContext.setTargetId(record.getTargetId());

      if (!objectContext.getOptions().isVerifyOnly()) {
        if (record == null
            || !record.getStatus().isSuccess()
            || (mtime != null && record.getMtime() != null && mtime.after(record.getMtime()))) {

          log.debug(
              "O--+ syncing {} {}", metadata.isDirectory() ? "directory" : "object", sourceId);

          objectContext.setStatus(ObjectStatus.InTransfer);
          recordExists = dbService.setStatus(objectContext, null, !recordExists);

          try {
            filterChain.filter(objectContext);
          } catch (Throwable t) {
            if (t instanceof NonRetriableException) throw t;
            retryHandler.submitForRetry(source, objectContext, t);
            return;
          }

          if (metadata.isDirectory()) log.info("O--O finished syncing directory {}", sourceId);
          else
            log.info(
                "O--O finished syncing object {} ({} bytes transferred)",
                sourceId,
                objectContext.getObject().getBytesRead());

          objectContext.setStatus(ObjectStatus.Transferred);
          dbService.setStatus(objectContext, null, false);
          processed = true;
        } else {
          log.info("O--* skipping {} because it is up-to-date in the target", sourceId);
        }
      }

      if (objectContext.getOptions().isVerify() || objectContext.getOptions().isVerifyOnly()) {
        if (record == null
            || record.getStatus() != ObjectStatus.Verified
            || (mtime != null && record.getMtime() != null && mtime.after(record.getMtime()))) {

          log.debug(
              "O==? verifying {} {}", sourceId, metadata.isDirectory() ? "directory" : "object");

          objectContext.setStatus(ObjectStatus.InVerification);
          recordExists = dbService.setStatus(objectContext, null, !recordExists);

          try {
            SyncObject targetObject = filterChain.reverseFilter(objectContext);

            try {
              verifier.verify(objectContext.getObject(), targetObject);
            } finally {
              try {
                // be sure to close all object resources
                targetObject.close();
              } catch (Throwable t) {
                log.warn("could not close target object resources", t);
              }
            }

          } catch (Throwable t) {
            if (!objectContext
                .getOptions()
                .isVerifyOnly()) { // if we just copied the data and verification failed, we should
                                   // retry
              retryHandler.submitForRetry(source, objectContext, t);
              return;
            } else throw t;
          }

          log.info("O==O verification successful for {}", sourceId);
          objectContext.setStatus(ObjectStatus.Verified);
          dbService.setStatus(objectContext, null, false);
          processed = true;
        } else {
          log.info("O==* skipping {} because it has already been verified", sourceId);
        }
      }

      if (processed) {
        syncStats.incObjectsComplete();
        syncStats.incBytesComplete(objectContext.getObject().getBytesRead());
      } else {
        syncStats.incObjectsSkipped();
        syncStats.incBytesSkipped(objectContext.getSourceSummary().getSize());
      }

      try { // delete object if the source supports deletion (implements the delete() method)
        if (objectContext.getOptions().isDeleteSource()) {
          source.delete(sourceId);
          log.info("X--O deleted {} from source", sourceId);
          dbService.setDeleted(objectContext, !recordExists);
        }
      } catch (Throwable t) {
        log.warn("!--O could not delete {} from source: {}", sourceId, t);
      }

    } catch (Throwable t) {
      try {
        objectContext.setStatus(ObjectStatus.Error);
        dbService.setStatus(objectContext, SyncUtil.summarize(t), !recordExists);
      } catch (Throwable t2) {
        log.warn("error setting DB status", t2);
      }

      log.warn("O--! object " + sourceId + " failed", SyncUtil.getCause(t));

      syncStats.incObjectsFailed();
      if (objectContext.getOptions().isRememberFailed()) syncStats.addFailedObject(sourceId);

    } finally {
      try {
        // be sure to close all object resources
        if (objectContext.getObject() != null) objectContext.getObject().close();
      } catch (Throwable t) {
        log.warn("could not close object resources", t);
      }
    }
  }