anmolnar commented on code in PR #8044: URL: https://github.com/apache/hbase/pull/8044#discussion_r3087275377
########## hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.security.access; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Set; +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.ActiveClusterSuffix; +import org.apache.hadoop.hbase.Coprocessor; +import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; +import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.hadoop.hbase.master.MasterFileSystem; +import org.apache.hadoop.hbase.master.region.MasterRegionFactory; +import org.apache.hadoop.hbase.util.FSUtils; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + [email protected](HBaseInterfaceAudience.CONFIG) +public abstract class AbstractReadOnlyController implements Coprocessor { + private static final Logger LOG = LoggerFactory.getLogger(AbstractReadOnlyController.class); + + private static final Set<TableName> writableTables = + Set.of(TableName.META_TABLE_NAME, MasterRegionFactory.TABLE_NAME); + + public static boolean + isWritableInReadOnlyMode(final ObserverContext<? extends RegionCoprocessorEnvironment> c) { + return writableTables.contains(c.getEnvironment().getRegionInfo().getTable()); + } + + public static boolean isWritableInReadOnlyMode(final TableName tableName) { + return writableTables.contains(tableName); + } + + protected void internalReadOnlyGuard() throws WriteAttemptedOnReadOnlyClusterException { + throw new WriteAttemptedOnReadOnlyClusterException("Operation not allowed in Read-Only Mode"); + } + + @Override + public void start(CoprocessorEnvironment env) throws IOException { + } + + @Override + public void stop(CoprocessorEnvironment env) { + } + + public static void manageActiveClusterIdFile(boolean readOnlyEnabled, MasterFileSystem mfs) { + FileSystem fs = mfs.getFileSystem(); + Path rootDir = mfs.getRootDir(); + Path activeClusterFile = new Path(rootDir, HConstants.ACTIVE_CLUSTER_SUFFIX_FILE_NAME); + + try { + if (readOnlyEnabled) { + // ENABLING READ-ONLY (false -> true), delete the active cluster file. Review Comment: There's an "else" branch as well in this code. You should not fail fast here. -- 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]
