Apache9 commented on code in PR #5256:
URL: https://github.com/apache/hbase/pull/5256#discussion_r1214501736


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/FlushTableProcedure.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.master.procedure;
+
+import java.io.IOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionReplicaUtil;
+import 
org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableProcedureStateData;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableState;
+
[email protected]
+public class FlushTableProcedure extends 
AbstractStateMachineTableProcedure<FlushTableState> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FlushTableProcedure.class);
+
+  private TableName tableName;
+
+  private byte[] columnFamily;
+
+  public FlushTableProcedure() {
+    super();
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName) {
+    this(env, tableName, null);
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName, 
byte[] columnFamily) {
+    super(env);
+    this.tableName = tableName;
+    this.columnFamily = columnFamily;
+  }
+
+  @Override
+  protected LockState acquireLock(MasterProcedureEnv env) {

Review Comment:
   Do we always need to acquireLock here? I can not recall, is it possible to 
not acquire a lock at all when executing a procedure?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/FlushTableProcedure.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.master.procedure;
+
+import java.io.IOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionReplicaUtil;
+import 
org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableProcedureStateData;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableState;
+
[email protected]
+public class FlushTableProcedure extends 
AbstractStateMachineTableProcedure<FlushTableState> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FlushTableProcedure.class);
+
+  private TableName tableName;
+
+  private byte[] columnFamily;
+
+  public FlushTableProcedure() {
+    super();
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName) {
+    this(env, tableName, null);
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName, 
byte[] columnFamily) {
+    super(env);
+    this.tableName = tableName;
+    this.columnFamily = columnFamily;
+  }
+
+  @Override
+  protected LockState acquireLock(MasterProcedureEnv env) {

Review Comment:
   Checked the code, this may not work as expected, as in the procedure 
scheduler, we will not schedule any other procedures for a given queue if a 
procedure has held the exclusive lock, even if your procedure does not require 
any locks.
   
   So here, I suggest you still make it require a shared lock, and add a 
comment here to say that actually we do not need any lock here, and use another 
issue to add the support, as it requires changing the procedure scheduler, 
which is not related to the core feature here.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/FlushRegionCallable.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.regionserver;
+
+import java.io.IOException;
+import java.util.Collections;
+import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.client.IsolationLevel;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.executor.EventType;
+import org.apache.hadoop.hbase.procedure2.BaseRSProcedureCallable;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushRegionParameter;
+
[email protected]
+public class FlushRegionCallable extends BaseRSProcedureCallable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(FlushRegionCallable.class);
+
+  private RegionInfo regionInfo;
+
+  private byte[] columnFamily;
+
+  @Override
+  protected void doCall() throws Exception {
+    HRegion region = rs.getRegion(regionInfo.getEncodedName());
+    if (region == null) {
+      throw new NotServingRegionException("region=" + 
regionInfo.getRegionNameAsString());
+    }
+    LOG.debug("Starting region operation on {}", region);
+    region.startRegionOperation();
+    try {
+      long readPt = region.getReadPoint(IsolationLevel.READ_COMMITTED);
+      HRegion.FlushResult res;
+      if (columnFamily == null) {
+        res = region.flush(true);
+      } else {
+        res = region.flushcache(Collections.singletonList(columnFamily), false,

Review Comment:
   Do we want to support flush several families at once? Do we have this 
support in the old flush procedure?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/FlushRegionCallable.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.regionserver;
+
+import java.io.IOException;
+import java.util.Collections;
+import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.client.IsolationLevel;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.executor.EventType;
+import org.apache.hadoop.hbase.procedure2.BaseRSProcedureCallable;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushRegionParameter;
+
[email protected]
+public class FlushRegionCallable extends BaseRSProcedureCallable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(FlushRegionCallable.class);
+
+  private RegionInfo regionInfo;
+
+  private byte[] columnFamily;
+
+  @Override
+  protected void doCall() throws Exception {
+    HRegion region = rs.getRegion(regionInfo.getEncodedName());
+    if (region == null) {
+      throw new NotServingRegionException("region=" + 
regionInfo.getRegionNameAsString());
+    }
+    LOG.debug("Starting region operation on {}", region);
+    region.startRegionOperation();
+    try {
+      long readPt = region.getReadPoint(IsolationLevel.READ_COMMITTED);
+      HRegion.FlushResult res;
+      if (columnFamily == null) {
+        res = region.flush(true);
+      } else {
+        res = region.flushcache(Collections.singletonList(columnFamily), false,
+          FlushLifeCycleTracker.DUMMY);
+      }
+      if (res.getResult() == HRegion.FlushResult.Result.CANNOT_FLUSH) {
+        region.waitForFlushes();

Review Comment:
   Should we wait here? Or just fail the remote procedure call, and let the 
master schedule again?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/FlushTableProcedure.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.master.procedure;
+
+import java.io.IOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.RegionReplicaUtil;
+import 
org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableProcedureStateData;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.FlushTableState;
+
[email protected]
+public class FlushTableProcedure extends 
AbstractStateMachineTableProcedure<FlushTableState> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(FlushTableProcedure.class);
+
+  private TableName tableName;
+
+  private byte[] columnFamily;
+
+  public FlushTableProcedure() {
+    super();
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName) {
+    this(env, tableName, null);
+  }
+
+  public FlushTableProcedure(MasterProcedureEnv env, TableName tableName, 
byte[] columnFamily) {
+    super(env);
+    this.tableName = tableName;
+    this.columnFamily = columnFamily;
+  }
+
+  @Override
+  protected LockState acquireLock(MasterProcedureEnv env) {
+    // Here we don't acquire table lock because the flush operation and other 
operations (like
+    // split or merge) are not mutually exclusive. Region will flush memstore 
when being closed.
+    // It's safe even if we don't have lock.
+    return LockState.LOCK_ACQUIRED;
+  }
+
+  @Override
+  protected void releaseLock(MasterProcedureEnv env) {
+    // nothing to do since we don't acquire lock
+  }
+
+  @Override
+  protected Flow executeFromState(MasterProcedureEnv env, FlushTableState 
state)
+    throws ProcedureSuspendedException, ProcedureYieldException, 
InterruptedException {
+    LOG.info("{} execute state={}", this, state);
+
+    try {
+      switch (state) {
+        case FLUSH_TABLE_PREPARE:
+          preflightChecks(env, true);
+          setNextState(FlushTableState.FLUSH_TABLE_FLUSH_REGIONS);
+          return Flow.HAS_MORE_STATE;
+        case FLUSH_TABLE_FLUSH_REGIONS:
+          addChildProcedure(createFlushRegionProcedures(env));
+          return Flow.NO_MORE_STATE;
+        default:
+          throw new UnsupportedOperationException("unhandled state=" + state);
+      }
+    } catch (IOException e) {
+      setFailure("master-flush-table", e);
+    }
+    return Flow.HAS_MORE_STATE;
+  }
+
+  @Override
+  protected void rollbackState(MasterProcedureEnv env, FlushTableState 
flushTableState)

Review Comment:
   Better throw UnsupportedOperationException if this should not happen.



-- 
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]

Reply via email to