use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class LockPoolTest method getKeys.
private Thread getKeys(int low, int high) {
Thread t = new Thread(() -> {
for (int i = low; i < high; i++) {
try (LockResource resource = mPool.get(i, LockMode.READ)) {
// Empty.
}
}
});
t.start();
return t;
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class LockPoolTest method insertValueTest.
@Test(timeout = 10000)
public void insertValueTest() throws Exception {
// Fills cache until high watermark.
for (int key = 0; key < HIGH_WATERMARK; key++) {
assertEquals(key, mPool.size());
try (LockResource resource = mPool.get(key, LockMode.READ)) {
assertTrue(mPool.containsKey(key));
assertEquals(key + 1, mPool.size());
}
}
// Exceeds high watermark, will be evicted until low watermark.
try (LockResource r = mPool.get(HIGH_WATERMARK, LockMode.READ)) {
assertTrue(mPool.containsKey(HIGH_WATERMARK));
CommonUtils.waitFor("Pool size to go below low watermark", () -> mPool.size() <= LOW_WATERMARK);
assertEquals(LOW_WATERMARK, mPool.size());
}
// Fills cache until high watermark again.
for (int newLock = 1; newLock <= HIGH_WATERMARK - LOW_WATERMARK; newLock++) {
int key = HIGH_WATERMARK + newLock;
try (LockResource resource = mPool.get(key, LockMode.READ)) {
assertTrue(mPool.containsKey(key));
assertEquals(LOW_WATERMARK + newLock, mPool.size());
}
}
// Exceeds high watermark, will be evicted until low watermark.
try (LockResource r = mPool.get(2 * HIGH_WATERMARK, LockMode.READ)) {
assertTrue(mPool.containsKey(2 * HIGH_WATERMARK));
CommonUtils.waitFor("Pool size to go below low watermark", () -> mPool.size() <= LOW_WATERMARK);
assertEquals(LOW_WATERMARK, mPool.size());
}
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class MountTable method resolve.
/**
* Resolves the given Alluxio path. If the given Alluxio path is nested under a mount point, the
* resolution maps the Alluxio path to the corresponding UFS path. Otherwise, the resolution is a
* no-op.
*
* @param uri an Alluxio path URI
* @return the {@link Resolution} representing the UFS path
* @throws InvalidPathException if an invalid path is encountered
*/
public Resolution resolve(AlluxioURI uri) throws InvalidPathException {
try (LockResource r = new LockResource(mReadLock)) {
String path = uri.getPath();
LOG.debug("Resolving {}", path);
PathUtils.validatePath(uri.getPath());
// This will re-acquire the read lock, but that is allowed.
String mountPoint = getMountPoint(uri);
if (mountPoint != null) {
MountInfo info = mState.getMountTable().get(mountPoint);
AlluxioURI ufsUri = info.getUfsUri();
UfsManager.UfsClient ufsClient;
AlluxioURI resolvedUri;
try {
ufsClient = mUfsManager.get(info.getMountId());
try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length()));
}
} catch (NotFoundException | UnavailableException e) {
throw new RuntimeException(String.format("No UFS information for %s for mount Id %d, we should never reach here", uri, info.getMountId()), e);
}
return new Resolution(resolvedUri, ufsClient, info.getOptions().getShared(), info.getMountId());
}
// TODO(binfan): throw exception as we should never reach here
return new Resolution(uri, null, false, IdUtils.INVALID_MOUNT_ID);
}
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class HeartbeatScheduler method schedule.
/**
* Schedules execution of a heartbeat for the given thread.
*
* @param threadName a name of the thread for which heartbeat is to be executed
*/
public static void schedule(String threadName) {
try (LockResource r = new LockResource(sLock)) {
ScheduledTimer timer = sTimers.get(threadName);
if (timer == null) {
throw new RuntimeException("Timer for thread " + threadName + " not found.");
}
timer.schedule();
}
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class ScheduledTimer method tick.
/**
* Waits until the heartbeat is scheduled for execution.
*
* @throws InterruptedException if the thread is interrupted while waiting
*/
public void tick() throws InterruptedException {
try (LockResource r = new LockResource(mLock)) {
HeartbeatScheduler.addTimer(this);
// Wait in a loop to handle spurious wakeups
while (!mScheduled) {
mTickCondition.await();
}
mScheduled = false;
}
}
Aggregations