kgeisz commented on code in PR #8006:
URL: https://github.com/apache/hbase/pull/8006#discussion_r3012930774
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java:
##########
@@ -597,122 +595,52 @@ public static ClusterId getClusterId(FileSystem fs, Path
rootdir) throws IOExcep
in = fs.open(idPath);
try {
cid = in.readUTF();
- clusterId = new ClusterId(cid);
- } catch (EOFException eof) {
- LOG.warn("Cluster ID file {} is empty", idPath);
- } finally {
- in.close();
- }
- rewriteAsPb(fs, rootdir, idPath, clusterId);
- }
- return clusterId;
- } else {
- LOG.warn("Cluster ID file does not exist at {}", idPath);
- }
- return clusterId;
- }
-
- public static ActiveClusterSuffix getActiveClusterSuffix(FileSystem fs, Path
rootdir)
- throws IOException {
- Path idPath = new Path(rootdir,
HConstants.ACTIVE_CLUSTER_SUFFIX_FILE_NAME);
- ActiveClusterSuffix cs = null;
- FileStatus status = fs.exists(idPath) ? fs.getFileStatus(idPath) : null;
- if (status != null) {
- int len = Ints.checkedCast(status.getLen());
- byte[] content = new byte[len];
- FSDataInputStream in = fs.open(idPath);
- try {
- in.readFully(content);
- } catch (EOFException eof) {
- LOG.warn("Cluster Suffix file {} is empty ", idPath);
- } finally {
- in.close();
- }
- try {
- cs = ActiveClusterSuffix.parseFrom(content);
- } catch (DeserializationException e) {
- throw new IOException("content=" + Bytes.toString(content), e);
- }
- // If not pb'd, make it so.
- if (!ProtobufUtil.isPBMagicPrefix(content)) {
- String data = null;
- in = fs.open(idPath);
- try {
- data = in.readUTF();
- cs = new ActiveClusterSuffix(data);
+ cs = parser.readString(cid);
} catch (EOFException eof) {
- LOG.warn("[Read-replica Feature] Active Cluster id file {} is empty
", idPath);
+ LOG.warn("Cluster file {} is empty", idPath);
} finally {
in.close();
}
- rewriteAsPb(fs, rootdir, idPath, cs);
+ rewriteAsPb(fs, rootdir, idPath, parser.getFileName(), cs);
}
return cs;
} else {
- throw new FileNotFoundException(
- "[Read-replica feature] Active Cluster Suffix File " + idPath + " not
found");
+ LOG.warn("Cluster file does not exist at {}", idPath);
}
+ return cs;
}
- private static void rewriteAsPb(final FileSystem fs, final Path rootdir,
final Path p,
- final ClusterId cid) throws IOException {
+ private static <T extends ClusterIdFile> void rewriteAsPb(final FileSystem
fs, final Path rootdir,
+ final Path p, final String fileName, final T cs) throws IOException {
// Rewrite the file as pb. Move aside the old one first, write new
// then delete the moved-aside file.
Path movedAsideName = new Path(p + "." +
EnvironmentEdgeManager.currentTime());
if (!fs.rename(p, movedAsideName)) throw new IOException("Failed rename of
" + p);
- setClusterId(fs, rootdir, cid, 100);
+ setClusterIdFile(fs, rootdir, fileName, cs, 100);
if (!fs.delete(movedAsideName, false)) {
throw new IOException("Failed delete of " + movedAsideName);
}
- LOG.debug("Rewrote the hbase.id file as pb");
- }
-
- private static void rewriteAsPb(final FileSystem fs, final Path rootdir,
final Path p,
- final ActiveClusterSuffix cs) throws IOException {
- // Rewrite the file as pb. Move aside the old one first, write new
- // then delete the moved-aside file.
- Path movedAsideName = new Path(p + "." +
EnvironmentEdgeManager.currentTime());
- if (!fs.rename(p, movedAsideName)) throw new IOException("Failed rename of
" + p);
- setActiveClusterSuffix(fs, rootdir, cs, 100);
- if (!fs.delete(movedAsideName, false)) {
- throw new IOException("Failed delete of " + movedAsideName);
- }
- LOG.debug("Rewrote the active.cluster.suffix.id file as pb");
+ LOG.debug("Rewrote the {}} file as pb", fileName);
Review Comment:
nit
```suggestion
LOG.debug("Rewrote the {} file as pb", fileName);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]