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());
}
}
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations