Skip to content
Permalink
Browse files

HBASE-19275 TestSnapshotFileCache never worked properly

Signed-off-by: Andrew Purtell <apurtell@apache.org>
  • Loading branch information
xcangCRM authored and apurtell committed Jul 23, 2018
1 parent baeeaa1 commit e8e4beacb039299a9e56cd355e3ada08784a7acb
@@ -57,6 +57,7 @@

private static final Log LOG = LogFactory.getLog(TestSnapshotFileCache.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static long sequenceId = 0;
private static FileSystem fs;
private static Path rootDir;

@@ -153,6 +154,9 @@ public void testWeNeverCacheTmpDirAndLoadIt() throws Exception {
SnapshotMock.SnapshotBuilder complete =
createAndTestSnapshotV1(cache, "snapshot", false, false);

SnapshotMock.SnapshotBuilder inProgress =
createAndTestSnapshotV1(cache, "snapshotInProgress", true, false);

int countBeforeCheck = count.get();

FSUtils.logFileSystemState(fs, rootDir, LOG);
@@ -224,11 +228,12 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,
List<Path> files = new ArrayList<Path>();
for (int i = 0; i < 3; ++i) {
for (Path filePath: builder.addRegion()) {
String fileName = filePath.getName();
if (tmp) {
// We should be able to find all the files while the snapshot creation is in-progress
FSUtils.logFileSystemState(fs, rootDir, LOG);
assertFalse("Cache didn't find " + filePath,
contains(getNonSnapshotFiles(cache, filePath), filePath));
Iterable<FileStatus> nonSnapshot = getNonSnapshotFiles(cache, filePath);
assertFalse("Cache didn't find " + fileName, Iterables.contains(nonSnapshot, fileName));
}
files.add(filePath);
}
@@ -241,7 +246,9 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,

// Make sure that all files are still present
for (Path path: files) {
assertFalse("Cache didn't find " + path, contains(getNonSnapshotFiles(cache, path), path));
Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, path);
assertFalse("Cache didn't find " + path.getName(),
Iterables.contains(nonSnapshotFiles, path.getName()));
}

FSUtils.logFileSystemState(fs, rootDir, LOG);
@@ -252,31 +259,24 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,

// The files should be in cache until next refresh
for (Path filePath: files) {
assertFalse("Cache didn't find " + filePath,
contains(getNonSnapshotFiles(cache, filePath), filePath));
Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, filePath);
assertFalse("Cache didn't find " + filePath.getName(), Iterables.contains(nonSnapshotFiles,
filePath.getName()));
}

// then trigger a refresh
cache.triggerCacheRefreshForTesting();

// and not it shouldn't find those files
for (Path filePath: files) {
assertFalse("Cache found '" + filePath + "', but it shouldn't have.",
contains(getNonSnapshotFiles(cache, filePath), filePath));
}
}
}

private static boolean contains(Iterable<FileStatus> files, Path filePath) {
for (FileStatus status: files) {
if (filePath.equals(status.getPath())) {
return true;
Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, filePath);
assertTrue("Cache found '" + filePath.getName() + "', but it shouldn't have.",
!Iterables.contains(nonSnapshotFiles, filePath.getName()));
}
}
return false;
}

private static Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile)
private Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile)
throws IOException {
return cache.getUnreferencedFiles(
Arrays.asList(FSUtils.listStatus(fs, storeFile.getParent())), null

0 comments on commit e8e4bea

Please sign in to comment.
You can’t perform that action at this time.