Skip to content

Commit ab319e4

Browse files
Jaehui-Leemokai87
authored andcommitted
HBASE-29021 When StoreFileTracker is FILE, unable to recognize StoreFileListFile after upgrade from 2.5 to 2.6 (apache#6552)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Reviewed-by: Viraj Jasani <vjasani@apache.org> (cherry picked from commit d1a2965)
1 parent 4432338 commit ab319e4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/StoreFileListFile.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class StoreFileListFile {
8484

8585
static final char TRACK_FILE_SEPARATOR = '.';
8686

87-
static final Pattern TRACK_FILE_PATTERN = Pattern.compile("^f(1|2)\\.\\d+$");
87+
static final Pattern TRACK_FILE_PATTERN = Pattern.compile("^f(1|2)(\\.\\d+)?$");
8888

8989
// 16 MB, which is big enough for a tracker file
9090
private static final int MAX_FILE_SIZE = 16 * 1024 * 1024;
@@ -179,7 +179,9 @@ private NavigableMap<Long, List<Path>> listFiles() throws IOException {
179179
continue;
180180
}
181181
List<String> parts = Splitter.on(TRACK_FILE_SEPARATOR).splitToList(file.getName());
182-
map.computeIfAbsent(Long.parseLong(parts.get(1)), k -> new ArrayList<>()).add(file);
182+
// For compatibility, set the timestamp to 0 if it is missing in the file name.
183+
long timestamp = parts.size() > 1 ? Long.parseLong(parts.get(1)) : 0L;
184+
map.computeIfAbsent(timestamp, k -> new ArrayList<>()).add(file);
183185
}
184186
return map;
185187
}

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/storefiletracker/TestStoreFileListFile.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,21 @@ public void testLoadHigherVersion() throws IOException {
239239
assertEquals("Higher store file list version detected, expected " + StoreFileListFile.VERSION
240240
+ ", got " + (StoreFileListFile.VERSION + 1), error.getMessage());
241241
}
242+
243+
@Test
244+
public void testLoadOldPatternTrackFiles() throws IOException {
245+
FileSystem fs = FileSystem.get(UTIL.getConfiguration());
246+
StoreFileList storeFileList =
247+
StoreFileList.newBuilder().setTimestamp(EnvironmentEdgeManager.currentTime())
248+
.addStoreFile(StoreFileEntry.newBuilder().setName("hehe").setSize(10).build()).build();
249+
Path trackFileDir = new Path(testDir, StoreFileListFile.TRACK_FILE_DIR);
250+
StoreFileListFile.write(fs, new Path(trackFileDir, StoreFileListFile.TRACK_FILE_PREFIX),
251+
storeFileList);
252+
253+
FileStatus trackerFileStatus = getOnlyTrackerFile(fs);
254+
assertEquals(StoreFileListFile.TRACK_FILE_PREFIX, trackerFileStatus.getPath().getName());
255+
256+
StoreFileList list = storeFileListFile.load(true);
257+
assertEquals(1, list.getStoreFileCount());
258+
}
242259
}

0 commit comments

Comments
 (0)