Search in sources :

Example 51 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class TieredBlockStore method removeDir.

/**
 * Removes a storage directory.
 *
 * @param dir storage directory to be removed
 */
public void removeDir(StorageDir dir) {
    // TODO(feng): Add a command for manually removing directory
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        String tierAlias = dir.getParentTier().getTierAlias();
        dir.getParentTier().removeStorageDir(dir);
        for (BlockStoreEventListener listener : mBlockStoreEventListeners) {
            synchronized (listener) {
                dir.getBlockIds().forEach(listener::onBlockLost);
                listener.onStorageLost(tierAlias, dir.getDirPath());
                listener.onStorageLost(dir.toBlockStoreLocation());
            }
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 52 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class TieredBlockStore method getBlockWriter.

@Override
public BlockWriter getBlockWriter(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException {
    LOG.debug("getBlockWriter: sessionId={}, blockId={}", sessionId, blockId);
    // TODO(bin): Handle the case where multiple writers compete for the same block.
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        checkTempBlockOwnedBySession(sessionId, blockId);
        TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
        return new StoreBlockWriter(tempBlockMeta);
    }
}
Also used : LockResource(alluxio.resource.LockResource) StoreBlockWriter(alluxio.worker.block.io.StoreBlockWriter) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 53 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class SupportedHdfsActiveSyncProvider method getActivitySyncInfo.

/**
 * Get the activity sync info.
 *
 * @return SyncInfo object which encapsulates the necessary information about changes
 */
public SyncInfo getActivitySyncInfo() {
    if (mPollingThread == null) {
        return SyncInfo.emptyInfo();
    }
    Map<AlluxioURI, Set<AlluxioURI>> syncPointFiles = new HashMap<>();
    long txId = 0;
    try (LockResource r = new LockResource(mWriteLock)) {
        initNextWindow();
        if (mEventMissed) {
            // force sync every syncpoint
            for (AlluxioURI uri : mUfsUriList) {
                syncPointFiles.put(uri, null);
                syncSyncPoint(uri.toString());
            }
            mEventMissed = false;
            LOG.debug("Missed event, syncing all sync points\n{}", Arrays.toString(syncPointFiles.keySet().toArray()));
            SyncInfo syncInfo = new SyncInfo(syncPointFiles, true, getLastTxId());
            return syncInfo;
        }
        for (String syncPoint : mActivity.keySet()) {
            AlluxioURI syncPointURI = new AlluxioURI(syncPoint);
            // if the activity level is below the threshold or the sync point is too old, we sync
            if (mActivity.get(syncPoint) < mActiveUfsSyncMaxActivity || mAge.get(syncPoint) > mActiveUfsSyncMaxAge) {
                if (!syncPointFiles.containsKey(syncPointURI)) {
                    syncPointFiles.put(syncPointURI, mChangedFiles.get(syncPoint));
                }
                syncSyncPoint(syncPoint);
            }
        }
        txId = getLastTxId();
    }
    LOG.debug("Syncing {} files", syncPointFiles.size());
    LOG.debug("Last transaction id {}", txId);
    SyncInfo syncInfo = new SyncInfo(syncPointFiles, false, txId);
    return syncInfo;
}
Also used : ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) Set(java.util.Set) LockResource(alluxio.resource.LockResource) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SyncInfo(alluxio.SyncInfo) AlluxioURI(alluxio.AlluxioURI)

Example 54 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class SupportedHdfsActiveSyncProvider method processEvent.

private boolean processEvent(Event event, List<AlluxioURI> syncPointList, long txId) {
    boolean fileMatch = false;
    String filePath = "";
    String renameFilePath = "";
    switch(event.getEventType()) {
        case CREATE:
            Event.CreateEvent createEvent = (Event.CreateEvent) event;
            filePath = createEvent.getPath();
            break;
        case UNLINK:
            Event.UnlinkEvent unlinkEvent = (Event.UnlinkEvent) event;
            filePath = unlinkEvent.getPath();
            break;
        case APPEND:
            Event.AppendEvent appendEvent = (Event.AppendEvent) event;
            filePath = appendEvent.getPath();
            break;
        case RENAME:
            Event.RenameEvent renameEvent = (Event.RenameEvent) event;
            filePath = renameEvent.getSrcPath();
            renameFilePath = renameEvent.getDstPath();
            break;
        case METADATA:
            Event.MetadataUpdateEvent metadataUpdateEvent = (Event.MetadataUpdateEvent) event;
            filePath = metadataUpdateEvent.getPath();
            break;
        default:
            break;
    }
    if (filePath.isEmpty()) {
        return false;
    }
    for (AlluxioURI syncPoint : syncPointList) {
        try {
            // find out if the changed file falls under one of the sync points
            if (PathUtils.hasPrefix(filePath, syncPoint.getPath())) {
                fileMatch = true;
                recordFileChanged(syncPoint.toString(), filePath, txId);
            }
        } catch (InvalidPathException e) {
            LOG.info("Invalid path encountered {} ", filePath);
        }
        try {
            // find out if the changed file falls under one of the sync points
            if ((!renameFilePath.isEmpty()) && PathUtils.hasPrefix(renameFilePath, syncPoint.getPath())) {
                fileMatch = true;
                recordFileChanged(syncPoint.toString(), renameFilePath, txId);
            }
        } catch (InvalidPathException e) {
            LOG.info("Invalid path encountered {} ", renameFilePath);
        }
    }
    try (LockResource r = new LockResource(mWriteLock)) {
        mCurrentTxId = txId;
    }
    return fileMatch;
}
Also used : InvalidPathException(alluxio.exception.InvalidPathException) LockResource(alluxio.resource.LockResource) Event(org.apache.hadoop.hdfs.inotify.Event) AlluxioURI(alluxio.AlluxioURI)

Example 55 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class SupportedHdfsActiveSyncProvider method recordFileChanged.

private void recordFileChanged(String syncPoint, String filePath, long txId) {
    AlluxioURI syncPointUri = new AlluxioURI(syncPoint);
    mChangedFiles.computeIfAbsent(syncPoint, (key) -> {
        mActivity.put(syncPoint, 0);
        mAge.put(syncPoint, 0);
        mTxIdMap.put(syncPoint, txId);
        return new ConcurrentHashSet<>();
    });
    try (LockResource r = new LockResource(mWriteLock)) {
        mChangedFiles.get(syncPoint).add(new AlluxioURI(syncPointUri.getScheme(), syncPointUri.getAuthority(), filePath));
        mActivity.put(syncPoint, mActivity.get(syncPoint) + 1);
    }
}
Also used : LockResource(alluxio.resource.LockResource) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) AlluxioURI(alluxio.AlluxioURI)

Aggregations

LockResource (alluxio.resource.LockResource)116 IOException (java.io.IOException)14 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)13 HashMap (java.util.HashMap)12 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)11 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)11 Map (java.util.Map)11 AlluxioURI (alluxio.AlluxioURI)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)10 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)9 ArrayList (java.util.ArrayList)9 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)8 InvalidPathException (alluxio.exception.InvalidPathException)7 NotFoundException (alluxio.exception.status.NotFoundException)7 List (java.util.List)7 Lock (java.util.concurrent.locks.Lock)7 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)6 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)6 UnavailableException (alluxio.exception.status.UnavailableException)6