Skip to content

Commit

Permalink
HBASE-29021 When StoreFileTracker is FILE, unable to recognize StoreF…
Browse files Browse the repository at this point in the history
…ileListFile after upgrade from 2.5 to 2.6 (#6552)

Signed-off-by: Duo Zhang <[email protected]>
Reviewed-by: Viraj Jasani <[email protected]>
  • Loading branch information
Jaehui-Lee authored Dec 23, 2024
1 parent 2990a0f commit d1a2965
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class StoreFileListFile {

static final char TRACK_FILE_SEPARATOR = '.';

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

// 16 MB, which is big enough for a tracker file
private static final int MAX_FILE_SIZE = 16 * 1024 * 1024;
Expand Down Expand Up @@ -179,7 +179,9 @@ private NavigableMap<Long, List<Path>> listFiles() throws IOException {
continue;
}
List<String> parts = Splitter.on(TRACK_FILE_SEPARATOR).splitToList(file.getName());
map.computeIfAbsent(Long.parseLong(parts.get(1)), k -> new ArrayList<>()).add(file);
// For compatibility, set the timestamp to 0 if it is missing in the file name.
long timestamp = parts.size() > 1 ? Long.parseLong(parts.get(1)) : 0L;
map.computeIfAbsent(timestamp, k -> new ArrayList<>()).add(file);
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,21 @@ public void testLoadHigherVersion() throws IOException {
assertEquals("Higher store file list version detected, expected " + StoreFileListFile.VERSION
+ ", got " + (StoreFileListFile.VERSION + 1), error.getMessage());
}

@Test
public void testLoadOldPatternTrackFiles() throws IOException {
FileSystem fs = FileSystem.get(UTIL.getConfiguration());
StoreFileList storeFileList =
StoreFileList.newBuilder().setTimestamp(EnvironmentEdgeManager.currentTime())
.addStoreFile(StoreFileEntry.newBuilder().setName("hehe").setSize(10).build()).build();
Path trackFileDir = new Path(testDir, StoreFileListFile.TRACK_FILE_DIR);
StoreFileListFile.write(fs, new Path(trackFileDir, StoreFileListFile.TRACK_FILE_PREFIX),
storeFileList);

FileStatus trackerFileStatus = getOnlyTrackerFile(fs);
assertEquals(StoreFileListFile.TRACK_FILE_PREFIX, trackerFileStatus.getPath().getName());

StoreFileList list = storeFileListFile.load(true);
assertEquals(1, list.getStoreFileCount());
}
}

0 comments on commit d1a2965

Please sign in to comment.