Search in sources :

Example 1 with AddSyncPointEntry

use of alluxio.proto.journal.File.AddSyncPointEntry in project alluxio by Alluxio.

the class ActiveSyncManager method stopSyncAndJournal.

/**
 * Stop active sync on a URI and journal the remove entry.
 *
 * @param rpcContext the master rpc or no-op context
 * @param syncPoint sync point to be stopped
 */
public void stopSyncAndJournal(RpcContext rpcContext, AlluxioURI syncPoint) throws InvalidPathException {
    if (!isSyncPoint(syncPoint)) {
        throw new InvalidPathException(String.format("%s is not a sync point", syncPoint));
    }
    try (LockResource r = new LockResource(mLock)) {
        MountTable.Resolution resolution = mMountTable.resolve(syncPoint);
        LOG.debug("stop syncPoint {}", syncPoint.getPath());
        final long mountId = resolution.getMountId();
        RemoveSyncPointEntry removeSyncPoint = File.RemoveSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).setMountId(mountId).build();
        applyAndJournal(rpcContext, removeSyncPoint);
        try {
            stopSyncInternal(syncPoint);
        } catch (Throwable e) {
            LOG.warn("Stop sync failed on {}", syncPoint, e);
            // revert state;
            AddSyncPointEntry addSyncPoint = File.AddSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).build();
            applyAndJournal(rpcContext, addSyncPoint);
            recoverFromStopSync(syncPoint);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) RemoveSyncPointEntry(alluxio.proto.journal.File.RemoveSyncPointEntry) MountTable(alluxio.master.file.meta.MountTable) InvalidPathException(alluxio.exception.InvalidPathException)

Example 2 with AddSyncPointEntry

use of alluxio.proto.journal.File.AddSyncPointEntry in project alluxio by Alluxio.

the class ActiveSyncManager method getSyncPathIterator.

private Iterator<Journal.JournalEntry> getSyncPathIterator() {
    final Iterator<AlluxioURI> it = mSyncPathList.iterator();
    return new Iterator<Journal.JournalEntry>() {

        private AlluxioURI mEntry = null;

        @Override
        public boolean hasNext() {
            if (mEntry != null) {
                return true;
            }
            if (it.hasNext()) {
                mEntry = it.next();
                return true;
            }
            return false;
        }

        @Override
        public Journal.JournalEntry next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            String syncPointPath = mEntry.getPath();
            long mountId = -1;
            while (mountId == -1) {
                try {
                    syncPointPath = mEntry.getPath();
                    String mountPoint = mMountTable.getMountPoint(mEntry);
                    MountInfo mountInfo = mMountTable.getMountTable().get(mountPoint);
                    mountId = mountInfo.getMountId();
                } catch (InvalidPathException e) {
                    LOG.info("Path resolution failed for {}, exception {}", syncPointPath, e);
                    mEntry = null;
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                }
            }
            mEntry = null;
            File.AddSyncPointEntry addSyncPointEntry = File.AddSyncPointEntry.newBuilder().setSyncpointPath(syncPointPath).setMountId(mountId).build();
            return Journal.JournalEntry.newBuilder().setAddSyncPoint(addSyncPointEntry).build();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("ActiveSyncManager#Iterator#remove is not supported.");
        }
    };
}
Also used : AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) CloseableIterator(alluxio.resource.CloseableIterator) Iterator(java.util.Iterator) Journal(alluxio.proto.journal.Journal) MountInfo(alluxio.master.file.meta.options.MountInfo) File(alluxio.proto.journal.File) NoSuchElementException(java.util.NoSuchElementException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 3 with AddSyncPointEntry

use of alluxio.proto.journal.File.AddSyncPointEntry in project alluxio by Alluxio.

the class ActiveSyncManager method startSyncAndJournal.

/**
 * Start active sync on a URI and journal the add entry.
 *
 * @param rpcContext the master rpc or no-op context
 * @param syncPoint sync point to be start
 */
public void startSyncAndJournal(RpcContext rpcContext, AlluxioURI syncPoint) throws InvalidPathException {
    try (LockResource r = new LockResource(mLock)) {
        MountTable.Resolution resolution = mMountTable.resolve(syncPoint);
        long mountId = resolution.getMountId();
        try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
            if (!ufsResource.get().supportsActiveSync()) {
                throw new UnsupportedOperationException("Active Syncing is not supported on this UFS type: " + ufsResource.get().getUnderFSType());
            }
        }
        if (isUnderSyncPoint(syncPoint)) {
            throw new InvalidPathException("URI " + syncPoint + " is already a sync point");
        }
        AddSyncPointEntry addSyncPoint = AddSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).setMountId(mountId).build();
        applyAndJournal(rpcContext, addSyncPoint);
        try {
            startSyncInternal(syncPoint, resolution);
        } catch (Throwable e) {
            LOG.warn("Start sync failed on {}", syncPoint, e);
            // revert state;
            RemoveSyncPointEntry removeSyncPoint = File.RemoveSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).build();
            applyAndJournal(rpcContext, removeSyncPoint);
            recoverFromStartSync(syncPoint, resolution.getMountId());
            throw e;
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) RemoveSyncPointEntry(alluxio.proto.journal.File.RemoveSyncPointEntry) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)3 AddSyncPointEntry (alluxio.proto.journal.File.AddSyncPointEntry)3 MountTable (alluxio.master.file.meta.MountTable)2 RemoveSyncPointEntry (alluxio.proto.journal.File.RemoveSyncPointEntry)2 LockResource (alluxio.resource.LockResource)2 AlluxioURI (alluxio.AlluxioURI)1 MountInfo (alluxio.master.file.meta.options.MountInfo)1 File (alluxio.proto.journal.File)1 Journal (alluxio.proto.journal.Journal)1 CloseableIterator (alluxio.resource.CloseableIterator)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1