Skip to content

HBASE-29959 Cluster started in read-only mode mistakenly deletes suffix file during startup#7881

Open
sharmaar12 wants to merge 2 commits intoapache:HBASE-29081from
sharmaar12:suffix-file
Open

HBASE-29959 Cluster started in read-only mode mistakenly deletes suffix file during startup#7881
sharmaar12 wants to merge 2 commits intoapache:HBASE-29081from
sharmaar12:suffix-file

Conversation

@sharmaar12
Copy link

No description provided.

@sharmaar12 sharmaar12 marked this pull request as ready for review March 7, 2026 10:14
Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the logging issue, otherwise lgtm.

byte[] actualClusterFileData = IOUtils.toByteArray(in);
byte[] expectedClusterFileData = mfs.getSuffixFileDataToWrite();
if (Arrays.equals(actualClusterFileData, expectedClusterFileData)) {
fs.delete(activeClusterFile, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LOG message should be inside the IF branch, because that's the case when you actually delete the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for pointing it out.

@sharmaar12 sharmaar12 requested a review from anmolnar March 9, 2026 17:29
if (fs.exists(activeClusterFile)) {
fs.delete(activeClusterFile, false);
LOG.info("Successfully deleted active cluster file: {}", activeClusterFile);
FSDataInputStream in = fs.open(activeClusterFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FSDataInputStream in is opened but never closed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

LOG.info("Successfully deleted active cluster file: {}", activeClusterFile);
FSDataInputStream in = fs.open(activeClusterFile);
byte[] actualClusterFileData = IOUtils.toByteArray(in);
byte[] expectedClusterFileData = mfs.getSuffixFileDataToWrite();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSuffixFileDataToWrite() mutates activeClusterSuffix in MasterFileSystem.java (line#453). Would this have any unintended side effects?
Because currently for read only clusters, this.activeClusterSuffix value is not set in MasterFileSystem.java but this PR changes it.

public byte[] getSuffixFileDataToWrite() {
String str = getClusterId().toString() + ":" + getActiveClusterSuffixFromConfig(conf);
this.activeClusterSuffix = new ActiveClusterSuffix(str);
return str.getBytes(StandardCharsets.UTF_8);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice catch. Getters should not mutate anything. Let's extract the mutation and move it to callers' level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants