Skip to content

Commit cf81c71

Browse files
z-yorkApache9
authored andcommitted
HBASE-21070 Add Test for SnapshotFileCache for HBase backed by S3 (apache#209)
SnapshotFileCache depends on getting the last modified time of the snapshot directory, however, S3 FileSystem's do not update the last modified time of the top 'folder' when objects are added/removed. This commit adds a test for the previously fixed SnapshotFileCache.
1 parent 8920ca3 commit cf81c71

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ public class TestSnapshotFileCache {
6868

6969
private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotFileCache.class);
7070
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
71+
// don't refresh the cache unless we tell it to
72+
private static final long PERIOD = Long.MAX_VALUE;
7173
private static FileSystem fs;
7274
private static Path rootDir;
75+
private static Path snapshotDir;
7376

7477
@BeforeClass
7578
public static void startCluster() throws Exception {
7679
UTIL.startMiniDFSCluster(1);
7780
fs = UTIL.getDFSCluster().getFileSystem();
7881
rootDir = UTIL.getDefaultRootDirPath();
82+
snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir);
7983
}
8084

8185
@AfterClass
@@ -86,56 +90,59 @@ public static void stopCluster() throws Exception {
8690
@After
8791
public void cleanupFiles() throws Exception {
8892
// cleanup the snapshot directory
89-
Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir);
9093
fs.delete(snapshotDir, true);
9194
}
9295

9396
@Test
9497
public void testLoadAndDelete() throws IOException {
95-
// don't refresh the cache unless we tell it to
96-
long period = Long.MAX_VALUE;
97-
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
98+
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, PERIOD, 10000000,
9899
"test-snapshot-file-cache-refresh", new SnapshotFiles());
99100

100-
createAndTestSnapshotV1(cache, "snapshot1a", false, true);
101-
createAndTestSnapshotV1(cache, "snapshot1b", true, true);
101+
createAndTestSnapshotV1(cache, "snapshot1a", false, true, false);
102+
createAndTestSnapshotV1(cache, "snapshot1b", true, true, false);
102103

103-
createAndTestSnapshotV2(cache, "snapshot2a", false, true);
104-
createAndTestSnapshotV2(cache, "snapshot2b", true, true);
104+
createAndTestSnapshotV2(cache, "snapshot2a", false, true, false);
105+
createAndTestSnapshotV2(cache, "snapshot2b", true, true, false);
105106
}
106107

107108
@Test
108109
public void testReloadModifiedDirectory() throws IOException {
109-
// don't refresh the cache unless we tell it to
110-
long period = Long.MAX_VALUE;
111-
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
110+
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, PERIOD, 10000000,
112111
"test-snapshot-file-cache-refresh", new SnapshotFiles());
113112

114-
createAndTestSnapshotV1(cache, "snapshot1", false, true);
113+
createAndTestSnapshotV1(cache, "snapshot1", false, true, false);
115114
// now delete the snapshot and add a file with a different name
116-
createAndTestSnapshotV1(cache, "snapshot1", false, false);
115+
createAndTestSnapshotV1(cache, "snapshot1", false, false, false);
117116

118-
createAndTestSnapshotV2(cache, "snapshot2", false, true);
117+
createAndTestSnapshotV2(cache, "snapshot2", false, true, false);
119118
// now delete the snapshot and add a file with a different name
120-
createAndTestSnapshotV2(cache, "snapshot2", false, false);
119+
createAndTestSnapshotV2(cache, "snapshot2", false, false, false);
121120
}
122121

123122
@Test
124123
public void testSnapshotTempDirReload() throws IOException {
125-
long period = Long.MAX_VALUE;
126-
// This doesn't refresh cache until we invoke it explicitly
127-
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
124+
SnapshotFileCache cache =
125+
new SnapshotFileCache(fs, rootDir, PERIOD, 10000000, "test-snapshot-file-cache-refresh", new SnapshotFiles());
126+
127+
// Add a new non-tmp snapshot
128+
createAndTestSnapshotV1(cache, "snapshot0v1", false, false, false);
129+
createAndTestSnapshotV1(cache, "snapshot0v2", false, false, false);
130+
}
131+
132+
@Test
133+
public void testCacheUpdatedWhenLastModifiedOfSnapDirNotUpdated() throws IOException {
134+
SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, PERIOD, 10000000,
128135
"test-snapshot-file-cache-refresh", new SnapshotFiles());
129136

130137
// Add a new non-tmp snapshot
131-
createAndTestSnapshotV1(cache, "snapshot0v1", false, false);
132-
createAndTestSnapshotV1(cache, "snapshot0v2", false, false);
138+
createAndTestSnapshotV1(cache, "snapshot1v1", false, false, true);
139+
createAndTestSnapshotV1(cache, "snapshot1v2", false, false, true);
133140

134141
// Add a new tmp snapshot
135-
createAndTestSnapshotV2(cache, "snapshot1", true, false);
142+
createAndTestSnapshotV2(cache, "snapshot2v1", true, false, true);
136143

137144
// Add another tmp snapshot
138-
createAndTestSnapshotV2(cache, "snapshot2", true, false);
145+
createAndTestSnapshotV2(cache, "snapshot2v2", true, false, true);
139146
}
140147

141148
@Test
@@ -160,7 +167,7 @@ List<String> getSnapshotsInProgress()
160167
};
161168

162169
SnapshotMock.SnapshotBuilder complete =
163-
createAndTestSnapshotV1(cache, "snapshot", false, false);
170+
createAndTestSnapshotV1(cache, "snapshot", false, false, false);
164171

165172
int countBeforeCheck = count.get();
166173

@@ -214,23 +221,24 @@ public Collection<String> filesUnderSnapshot(final Path snapshotDir) throws IOEx
214221
};
215222

216223
private SnapshotMock.SnapshotBuilder createAndTestSnapshotV1(final SnapshotFileCache cache,
217-
final String name, final boolean tmp, final boolean removeOnExit) throws IOException {
224+
final String name, final boolean tmp, final boolean removeOnExit, boolean setFolderTime)
225+
throws IOException {
218226
SnapshotMock snapshotMock = new SnapshotMock(UTIL.getConfiguration(), fs, rootDir);
219227
SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV1(name, name);
220-
createAndTestSnapshot(cache, builder, tmp, removeOnExit);
228+
createAndTestSnapshot(cache, builder, tmp, removeOnExit, setFolderTime);
221229
return builder;
222230
}
223231

224232
private void createAndTestSnapshotV2(final SnapshotFileCache cache, final String name,
225-
final boolean tmp, final boolean removeOnExit) throws IOException {
233+
final boolean tmp, final boolean removeOnExit, boolean setFolderTime) throws IOException {
226234
SnapshotMock snapshotMock = new SnapshotMock(UTIL.getConfiguration(), fs, rootDir);
227235
SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2(name, name);
228-
createAndTestSnapshot(cache, builder, tmp, removeOnExit);
236+
createAndTestSnapshot(cache, builder, tmp, removeOnExit, setFolderTime);
229237
}
230238

231239
private void createAndTestSnapshot(final SnapshotFileCache cache,
232240
final SnapshotMock.SnapshotBuilder builder,
233-
final boolean tmp, final boolean removeOnExit) throws IOException {
241+
final boolean tmp, final boolean removeOnExit, boolean setFolderTime) throws IOException {
234242
List<Path> files = new ArrayList<>();
235243
for (int i = 0; i < 3; ++i) {
236244
for (Path filePath: builder.addRegion()) {
@@ -249,6 +257,10 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,
249257
builder.commit();
250258
}
251259

260+
if (setFolderTime) {
261+
fs.setTimes(snapshotDir, 0, -1);
262+
}
263+
252264
// Make sure that all files are still present
253265
for (Path path: files) {
254266
assertFalse("Cache didn't find " + path, contains(getNonSnapshotFiles(cache, path), path));

0 commit comments

Comments
 (0)