Skip to content

Commit 6c5c65a

Browse files
committed
HBASE-27590 Change Iterable to List in SnapshotFileCache (#4995)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit d2c5af1)
1 parent c580835 commit 6c5c65a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,11 @@ public synchronized void triggerCacheRefreshForTesting() {
178178
* at that point, cache will still think the file system contains that file and return
179179
* <tt>true</tt>, even if it is no longer present (false positive). However, if the file never was
180180
* on the filesystem, we will never find it and always return <tt>false</tt>.
181-
* @param files file to check, NOTE: Relies that files are loaded from hdfs before method is
182-
* called (NOT LAZY)
181+
* @param files file to check
183182
* @return <tt>unReferencedFiles</tt> the collection of files that do not have snapshot references
184183
* @throws IOException if there is an unexpected error reaching the filesystem.
185184
*/
186-
// XXX this is inefficient to synchronize on the method, when what we really need to guard against
187-
// is an illegal access to the cache. Really we could do a mutex-guarded pointer swap on the
188-
// cache, but that seems overkill at the moment and isn't necessarily a bottleneck.
189-
public Iterable<FileStatus> getUnreferencedFiles(Iterable<FileStatus> files,
185+
public Iterable<FileStatus> getUnreferencedFiles(List<FileStatus> files,
190186
final SnapshotManager snapshotManager) throws IOException {
191187
List<FileStatus> unReferencedFiles = Lists.newArrayList();
192188
List<String> snapshotsInProgress = null;

hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotHFileCleaner.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import java.io.IOException;
2121
import java.util.Collection;
2222
import java.util.Collections;
23+
import java.util.List;
2324
import java.util.Map;
25+
import java.util.stream.Collectors;
26+
import java.util.stream.StreamSupport;
2427
import org.apache.hadoop.conf.Configuration;
2528
import org.apache.hadoop.fs.FileStatus;
2629
import org.apache.hadoop.fs.FileSystem;
@@ -64,8 +67,15 @@ public class SnapshotHFileCleaner extends BaseHFileCleanerDelegate {
6467

6568
@Override
6669
public Iterable<FileStatus> getDeletableFiles(Iterable<FileStatus> files) {
70+
// The Iterable is lazy evaluated, so if we just pass this Iterable in, we will access the HFile
71+
// storage inside the snapshot lock, which could take a lot of time (for example, several
72+
// seconds), and block all other operations, especially other cleaners.
73+
// So here we convert it to List first, to force it evaluated before calling
74+
// getUnreferencedFiles, so we will not hold snapshot lock for a long time.
75+
List<FileStatus> filesList =
76+
StreamSupport.stream(files.spliterator(), false).collect(Collectors.toList());
6777
try {
68-
return cache.getUnreferencedFiles(files, master.getSnapshotManager());
78+
return cache.getUnreferencedFiles(filesList, master.getSnapshotManager());
6979
} catch (CorruptedSnapshotException cse) {
7080
LOG.debug("Corrupted in-progress snapshot file exception, ignored ", cse);
7181
} catch (IOException e) {

0 commit comments

Comments
 (0)