Skip to content

Commit

Permalink
Revert "HBASE-27043 Let lock wait timeout to improve performance of S…
Browse files Browse the repository at this point in the history
…napshotHFileCleaner (apache#4437)"

This reverts commit 4e62e84.
  • Loading branch information
wenwj0 committed Jun 14, 2022
1 parent 1aa6b97 commit 512d766
Showing 1 changed file with 28 additions and 39 deletions.
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -98,8 +97,6 @@ Collection<String> filesUnderSnapshot(final FileSystem fs, final Path snapshotDi
private ImmutableMap<String, SnapshotDirectoryInfo> snapshots = ImmutableMap.of();
private final Timer refreshTimer;

private static final int LOCK_TIMEOUT_MS = 30000;

/**
* Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the
* filesystem.
Expand Down Expand Up @@ -195,47 +192,39 @@ public Iterable<FileStatus> getUnreferencedFiles(Iterable<FileStatus> files,
if (snapshotManager != null) {
lock = snapshotManager.getTakingSnapshotLock().writeLock();
}
try {
if (lock == null || lock.tryLock(LOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
try {
if (snapshotManager != null && snapshotManager.isTakingAnySnapshot()) {
LOG.warn("Not checking unreferenced files since snapshot is running, it will "
+ "skip to clean the HFiles this time");
return unReferencedFiles;
}
ImmutableSet<String> currentCache = cache;
for (FileStatus file : files) {
String fileName = file.getPath().getName();
if (!refreshed && !currentCache.contains(fileName)) {
synchronized (this) {
refreshCache();
currentCache = cache;
refreshed = true;
}
}
if (currentCache.contains(fileName)) {
continue;
}
if (snapshotsInProgress == null) {
snapshotsInProgress = getSnapshotsInProgress();
}
if (snapshotsInProgress.contains(fileName)) {
continue;
if (lock == null || lock.tryLock()) {
try {
if (snapshotManager != null && snapshotManager.isTakingAnySnapshot()) {
LOG.warn("Not checking unreferenced files since snapshot is running, it will "
+ "skip to clean the HFiles this time");
return unReferencedFiles;
}
ImmutableSet<String> currentCache = cache;
for (FileStatus file : files) {
String fileName = file.getPath().getName();
if (!refreshed && !currentCache.contains(fileName)) {
synchronized (this) {
refreshCache();
currentCache = cache;
refreshed = true;
}
unReferencedFiles.add(file);
}
} finally {
if (lock != null) {
lock.unlock();
if (currentCache.contains(fileName)) {
continue;
}
if (snapshotsInProgress == null) {
snapshotsInProgress = getSnapshotsInProgress();
}
if (snapshotsInProgress.contains(fileName)) {
continue;
}
unReferencedFiles.add(file);
}
} finally {
if (lock != null) {
lock.unlock();
}
} else {
LOG.warn("Failed to acquire write lock on taking snapshot after waiting {}ms",
LOCK_TIMEOUT_MS);
}
} catch (InterruptedException e) {
LOG.warn("Interrupted while acquiring write lock on taking snapshot");
Thread.currentThread().interrupt(); // restore the interrupt flag
}
return unReferencedFiles;
}
Expand Down

0 comments on commit 512d766

Please sign in to comment.