1919
2020import java .io .FileNotFoundException ;
2121import java .io .IOException ;
22- import java .util .Arrays ;
23- import org .apache .commons .io .IOUtils ;
2422import org .apache .hadoop .fs .FSDataInputStream ;
2523import org .apache .hadoop .fs .FileSystem ;
2624import org .apache .hadoop .fs .Path ;
25+ import org .apache .hadoop .hbase .ActiveClusterSuffix ;
2726import org .apache .hadoop .hbase .Coprocessor ;
2827import org .apache .hadoop .hbase .CoprocessorEnvironment ;
2928import org .apache .hadoop .hbase .DoNotRetryIOException ;
3029import org .apache .hadoop .hbase .HBaseInterfaceAudience ;
3130import org .apache .hadoop .hbase .HConstants ;
31+ import org .apache .hadoop .hbase .exceptions .DeserializationException ;
3232import org .apache .hadoop .hbase .master .MasterFileSystem ;
3333import org .apache .hadoop .hbase .master .MasterServices ;
3434import org .apache .hadoop .hbase .util .FSUtils ;
@@ -64,9 +64,10 @@ public static void manageActiveClusterIdFile(boolean readOnlyEnabled, MasterFile
6464 LOG .debug ("Global read-only mode is being ENABLED. Deleting active cluster file: {}" ,
6565 activeClusterFile );
6666 try (FSDataInputStream in = fs .open (activeClusterFile )) {
67- byte [] actualClusterFileData = IOUtils .toByteArray (in );
68- byte [] expectedClusterFileData = mfs .getActiveClusterSuffix ().toByteArray ();
69- if (Arrays .equals (actualClusterFileData , expectedClusterFileData )) {
67+ ActiveClusterSuffix actualClusterFileData =
68+ ActiveClusterSuffix .parseFrom (in .readAllBytes ());
69+ ActiveClusterSuffix expectedClusterFileData = mfs .getActiveClusterSuffix ();
70+ if (expectedClusterFileData .equals (actualClusterFileData )) {
7071 fs .delete (activeClusterFile , false );
7172 LOG .info ("Successfully deleted active cluster file: {}" , activeClusterFile );
7273 } else {
@@ -84,6 +85,8 @@ public static void manageActiveClusterIdFile(boolean readOnlyEnabled, MasterFile
8485 "Failed to delete active cluster file: {}. "
8586 + "Read-only flag will be updated, but file system state is inconsistent." ,
8687 activeClusterFile , e );
88+ } catch (DeserializationException e ) {
89+ LOG .error ("Failed to deserialize ActiveClusterSuffix from file {}" , activeClusterFile , e );
8790 }
8891 } else {
8992 // DISABLING READ-ONLY (true -> false), create the active cluster file id file
0 commit comments