Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RATIS-1855 Fix some sonar code smell and bugs in ratis-server #892

Merged
merged 3 commits into from
Jul 8, 2023

Conversation

OneSizeFitsQuorum
Copy link
Contributor

see jira1855

Signed-off-by: OneSizeFitQuorum <[email protected]>
@OneSizeFitsQuorum
Copy link
Contributor Author

PTAL @szetszwo

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

@OneSizeFitsQuorum , thanks a lot for working on this! Please see the comments inlined.

@@ -39,7 +40,7 @@ public class RaftStorageImpl implements RaftStorage {
private final StartupOption startupOption;
private final CorruptionPolicy logCorruptionPolicy;
private volatile StorageState state = StorageState.UNINITIALIZED;
private volatile RaftStorageMetadataFileImpl metaFile;
private final AtomicReference<RaftStorageMetadataFileImpl> metaFile = new AtomicReference<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a class:

  static class MetaFile {
    private final AtomicReference<RaftStorageMetadataFileImpl> ref = new AtomicReference<>();

    RaftStorageMetadataFile get() {
      return ref.get();
    }

    RaftStorageMetadataFile set(File file) {
      final RaftStorageMetadataFileImpl impl = new RaftStorageMetadataFileImpl(file);
      ref.set(impl);
      return impl;
    }
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good advice~

Comment on lines 95 to 96
metaFile.set(new RaftStorageMetadataFileImpl(storageDir.getMetaFile()));
metaFile.get().persist(RaftStorageMetadata.getDefault());
Copy link
Contributor

Choose a reason for hiding this comment

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

After created a class, this becomes a single llne

    metaFile.set(storageDir.getMetaFile()).persist(RaftStorageMetadata.getDefault());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Comment on lines 116 to 117
metaFile.set(new RaftStorageMetadataFileImpl(f));
final RaftStorageMetadata metadata = metaFile.get().getMetadata();
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, this becomes a single llne

      final RaftStorageMetadata metadata = metaFile.set(f).getMetadata();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@@ -150,7 +152,7 @@ private RaftStorageImpl format() throws IOException {
}
throw new IOException("Failed to FORMAT a new storage dir for " + storageDirName + " from " + dirsInConf);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep this empty line.

@@ -130,13 +131,14 @@ RaftStorageImpl run() throws IOException {
}
}

@SuppressWarnings("java:S1181")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment at the end for this and the other SuppressWarnings?

@SuppressWarnings("java:S1181") // catch Throwable
@SuppressWarnings("java:S2095") // return Closable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Signed-off-by: OneSizeFitQuorum <[email protected]>
Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

+1 the change looks good.

@szetszwo szetszwo merged commit ada2c1c into apache:master Jul 8, 2023
10 checks passed
@OneSizeFitsQuorum OneSizeFitsQuorum deleted the jira1855 branch July 8, 2023 05:42
symious pushed a commit to symious/ratis that referenced this pull request Mar 19, 2024
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.

2 participants