joshelser commented on a change in pull request #4030:
URL: https://github.com/apache/hbase/pull/4030#discussion_r785330809



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
##########
@@ -2590,7 +2620,20 @@ String getOperationType() {
 
     @Override
     String getOperationType() {
-      return "ENABLE";
+      return "MODIFY";
+    }
+  }
+
+  private static class ModifyTableStoreFileTrackerProcedureBiConsumer
+    extends TableProcedureBiConsumer {
+
+    ModifyTableStoreFileTrackerProcedureBiConsumer(AsyncAdmin admin, TableName 
tableName) {
+      super(tableName);
+    }
+
+    @Override
+    String getOperationType() {
+      return "MODIFY_STORE_FILE_TRACKER";

Review comment:
       `MODIFY_TABLE_STORE_FILE_TRACKER` for consistency? Or you think we just 
assume it is table-level operation if we dont' specify "COLUMN_FAMILY"?

##########
File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin3.java
##########
@@ -393,4 +398,156 @@ public void testDeleteEditUnknownColumnFamilyAndOrTable() 
throws IOException {
       ADMIN.deleteTable(tableName);
     }
   }
+
+  private static final String SRC_IMPL = 
"hbase.store.file-tracker.migration.src.impl";
+
+  private static final String DST_IMPL = 
"hbase.store.file-tracker.migration.dst.impl";
+
+  private void verifyModifyTableResult(TableName tableName, byte[] family, 
byte[] qual, byte[] row,
+    byte[] value, String sft) throws IOException {
+    TableDescriptor td = ADMIN.getDescriptor(tableName);
+    assertEquals(sft, td.getValue(StoreFileTrackerFactory.TRACKER_IMPL));
+    // no migration related configs
+    assertNull(td.getValue(SRC_IMPL));
+    assertNull(td.getValue(DST_IMPL));
+    try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
+      assertArrayEquals(value, table.get(new Get(row)).getValue(family, qual));
+    }
+  }
+
+  @Test
+  public void testModifyTableStoreFileTracker() throws IOException {
+    TableName tableName = TableName.valueOf(name.getMethodName());
+    byte[] family = Bytes.toBytes("info");
+    byte[] qual = Bytes.toBytes("q");
+    byte[] row = Bytes.toBytes(0);
+    byte[] value = Bytes.toBytes(1);
+    try (Table table = TEST_UTIL.createTable(tableName, family)) {
+      table.put(new Put(row).addColumn(family, qual, value));
+    }
+    // change to FILE
+    ADMIN.modifyTableStoreFileTracker(tableName, 
StoreFileTrackerFactory.Trackers.FILE.name());
+    verifyModifyTableResult(tableName, family, qual, row, value,
+      StoreFileTrackerFactory.Trackers.FILE.name());
+
+    // change to FILE again, should have no effect
+    ADMIN.modifyTableStoreFileTracker(tableName, 
StoreFileTrackerFactory.Trackers.FILE.name());
+    verifyModifyTableResult(tableName, family, qual, row, value,
+      StoreFileTrackerFactory.Trackers.FILE.name());
+
+    // change to MIGRATION, and then to FILE
+    
ADMIN.modifyTable(TableDescriptorBuilder.newBuilder(ADMIN.getDescriptor(tableName))
+      .setValue(StoreFileTrackerFactory.TRACKER_IMPL,
+        StoreFileTrackerFactory.Trackers.MIGRATION.name())
+      .setValue(SRC_IMPL,
+        StoreFileTrackerFactory.Trackers.FILE.name())
+      .setValue(DST_IMPL,
+        StoreFileTrackerFactory.Trackers.DEFAULT.name())
+      .build());

Review comment:
       Just making sure - you're testing "case 4" from your above comments in 
the Procedure? (migration class is set but dst is a different impl than what we 
want)

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/ModifyStoreFileTrackerProcedure.java
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.storefiletracker;
+
+import java.io.IOException;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableNotEnabledException;
+import org.apache.hadoop.hbase.TableNotFoundException;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import 
org.apache.hadoop.hbase.master.procedure.AbstractStateMachineTableProcedure;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.ModifyTableProcedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+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.ModifyStoreFileTrackerState;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ModifyStoreFileTrackerStateData;
+
+/**
+ * This procedure is used to change the store file tracker implementation.
+ * <p/>
+ * Typically we need to schedule two {@link ModifyTableProcedure} (or three if 
the table is already
+ * in {@code MIGRATION} but the {@code dstSFT} is not what we expected) to do 
this, so we introduce
+ * this procedure to simplify the work of our users.
+ */
[email protected]
+public abstract class ModifyStoreFileTrackerProcedure
+  extends AbstractStateMachineTableProcedure<ModifyStoreFileTrackerState> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ModifyStoreFileTrackerProcedure.class);
+
+  private TableName tableName;
+
+  private String dstSFT;
+
+  protected ModifyStoreFileTrackerProcedure() {
+  }
+
+  protected ModifyStoreFileTrackerProcedure(MasterProcedureEnv env, TableName 
tableName,
+    String dstSFT) throws HBaseIOException {
+    super(env);
+    checkDstSFT(dstSFT);
+    this.tableName = tableName;
+    this.dstSFT = dstSFT;
+    preflightChecks(env, true);
+  }
+
+  private void checkDstSFT(String dstSFT) throws DoNotRetryIOException {
+    if (MigrationStoreFileTracker.class
+      .isAssignableFrom(StoreFileTrackerFactory.getTrackerClass(dstSFT))) {
+      throw new DoNotRetryIOException("Do not need to transfer to " + dstSFT);
+    }
+  }
+
+  @Override
+  public TableName getTableName() {
+    return tableName;
+  }
+
+  @Override
+  public TableOperationType getTableOperationType() {
+    return TableOperationType.EDIT;
+  }
+
+  private enum StoreFileTrackerState {
+    NEED_RESTORE, NEED_MIGRATION, NEED_FINISH_MIGRATION, ALREADY_FINISHED

Review comment:
       `NEED_RESTORE` was a bit confusing to me and I had to read to understand 
what it meant. What about:
   
   * `NEED_RESTORE` -> `NEED_SET_MIGRATION`
   * `NEED_MIGRATION` -> `NEED_START_MIGRATION`
   * `NEED_FINISH_MIGRATION` (perfect)
   
   If you like this, should also change the constant up in proto.

##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
##########
@@ -2590,7 +2620,20 @@ String getOperationType() {
 
     @Override
     String getOperationType() {
-      return "ENABLE";
+      return "MODIFY";

Review comment:
       :) good catch

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/ModifyTableStoreFileTrackerProcedure.java
##########
@@ -0,0 +1,71 @@
+/**
+ * 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.storefiletracker;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CompoundConfiguration;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.yetus.audience.InterfaceAudience;
+
[email protected]
+public class ModifyTableStoreFileTrackerProcedure extends 
ModifyStoreFileTrackerProcedure {
+
+  public ModifyTableStoreFileTrackerProcedure() {
+  }
+
+  public ModifyTableStoreFileTrackerProcedure(MasterProcedureEnv env, 
TableName tableName,
+    String dstSFT) throws HBaseIOException {
+    super(env, tableName, dstSFT);
+  }
+
+  @Override
+  protected void preCheck(TableDescriptor current) {

Review comment:
       Can assume that table still exists if we got 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]


Reply via email to