You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sk...@apache.org on 2020/01/16 05:01:19 UTC

[phoenix] 01/02: PHOENIX-5675: IndexUpgradeTool should allow verify options for IndexTool run

This is an automated email from the ASF dual-hosted git repository.

skadam pushed a commit to branch 4.x-HBase-1.5
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 6fcf2f451f8636c70105a7189b80d76a05b32a61
Author: s.kadam <s....@salesforce.com>
AuthorDate: Tue Jan 14 15:02:53 2020 -0800

    PHOENIX-5675: IndexUpgradeTool should allow verify options for IndexTool run
---
 .../phoenix/mapreduce/index/IndexUpgradeTool.java  | 38 ++++++++++++------
 .../apache/phoenix/index/IndexUpgradeToolTest.java | 45 ++++++++++++++++------
 2 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
index 8246d51..729a147 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
@@ -83,26 +83,31 @@ public class IndexUpgradeTool extends Configured implements Tool {
 
     private static final Option OPERATION_OPTION = new Option("o", "operation",
             true,
-            "[Required]Operation to perform (upgrade/rollback)");
+            "[Required] Operation to perform (upgrade/rollback)");
     private static final Option TABLE_OPTION = new Option("tb", "table", true,
-            "[Required]Tables list ex. table1,table2");
+            "[Required] Tables list ex. table1,table2");
     private static final Option TABLE_CSV_FILE_OPTION = new Option("f", "file",
             true,
-            "[Optional]Tables list in a csv file");
+            "[Optional] Tables list in a csv file");
     private static final Option DRY_RUN_OPTION = new Option("d", "dry-run",
             false,
-            "[Optional]If passed this will output steps that will be executed");
+            "[Optional] If passed this will output steps that will be executed");
     private static final Option HELP_OPTION = new Option("h", "help",
             false, "Help");
     private static final Option LOG_FILE_OPTION = new Option("lf", "logfile",
             true,
-            "Log file path where the logs are written");
+            "[Optional] Log file path where the logs are written");
     private static final Option INDEX_SYNC_REBUILD_OPTION = new Option("sr",
             "index-sync-rebuild",
             false,
-            "[Optional]Whether or not synchronously rebuild the indexes; "
+            "[Optional] Whether or not synchronously rebuild the indexes; "
                     + "default rebuild asynchronous");
 
+    private static final Option INDEX_VERIFY_OPTION = new Option("v",
+            "verify",
+            true,
+            "[Optional] mode to run indexTool with verify options");
+
     public static final String UPGRADE_OP = "upgrade";
     public static final String ROLLBACK_OP = "rollback";
     private static final String GLOBAL_INDEX_ID = "#NA#";
@@ -117,6 +122,7 @@ public class IndexUpgradeTool extends Configured implements Tool {
     private String inputTables;
     private String logFile;
     private String inputFile;
+    private String verify;
 
     private boolean test = false;
     private boolean isWaitComplete = false;
@@ -138,10 +144,12 @@ public class IndexUpgradeTool extends Configured implements Tool {
     }
 
     public void setTest(boolean test) { this.test = test; }
+
     public boolean getIsWaitComplete() { return this.isWaitComplete; }
-    public boolean getDryRun() {
-        return this.dryRun;
-    }
+
+    public boolean getDryRun() { return this.dryRun; }
+
+    public String getVerify() { return this.verify; }
 
     public String getInputTables() {
         return this.inputTables;
@@ -152,7 +160,7 @@ public class IndexUpgradeTool extends Configured implements Tool {
     }
 
     public String getOperation() {
-        return operation;
+        return this.operation;
     }
 
     public IndexUpgradeTool(String mode, String tables, String inputFile,
@@ -252,7 +260,8 @@ public class IndexUpgradeTool extends Configured implements Tool {
         options.addOption(HELP_OPTION);
         INDEX_SYNC_REBUILD_OPTION.setOptionalArg(true);
         options.addOption(INDEX_SYNC_REBUILD_OPTION);
-
+        INDEX_VERIFY_OPTION.setOptionalArg(true);
+        options.addOption(INDEX_VERIFY_OPTION);
         return options;
     }
 
@@ -264,6 +273,7 @@ public class IndexUpgradeTool extends Configured implements Tool {
         inputFile = cmdLine.getOptionValue(TABLE_CSV_FILE_OPTION.getOpt());
         dryRun = cmdLine.hasOption(DRY_RUN_OPTION.getOpt());
         syncRebuild = cmdLine.hasOption(INDEX_SYNC_REBUILD_OPTION.getOpt());
+        verify = cmdLine.getOptionValue(INDEX_VERIFY_OPTION.getOpt());
     }
 
     @VisibleForTesting
@@ -692,7 +702,7 @@ public class IndexUpgradeTool extends Configured implements Tool {
         return 0;
     }
 
-    private String[] getIndexToolArgValues(String schema, String baseTable, String indexName,
+    public String[] getIndexToolArgValues(String schema, String baseTable, String indexName,
             String outFile, String tenantId) {
         String args[] = { "-s", schema, "-dt", baseTable, "-it", indexName,
                 "-direct", "-op", outFile };
@@ -704,6 +714,10 @@ public class IndexUpgradeTool extends Configured implements Tool {
         if (syncRebuild) {
             list.add("-runfg");
         }
+        if(!Strings.isNullOrEmpty(verify)) {
+            list.add("-v");
+            list.add(verify);
+        }
         return list.toArray(new String[list.size()]);
     }
 
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/index/IndexUpgradeToolTest.java b/phoenix-core/src/test/java/org/apache/phoenix/index/IndexUpgradeToolTest.java
index 937ac1b..87655a2 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/index/IndexUpgradeToolTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/index/IndexUpgradeToolTest.java
@@ -22,11 +22,13 @@ import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.UPGRADE_OP;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.UUID;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.phoenix.mapreduce.index.IndexUpgradeTool;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -36,25 +38,46 @@ import org.junit.runners.Parameterized.Parameters;
 public class IndexUpgradeToolTest {
     private static final String INPUT_LIST = "TEST.MOCK1,TEST1.MOCK2,TEST.MOCK3";
     private final boolean upgrade;
+    private static final String DUMMY_STRING_VALUE = "anyValue";
+    private IndexUpgradeTool indexUpgradeTool=null;
+    private String outputFile;
 
     public IndexUpgradeToolTest(boolean upgrade) {
         this.upgrade = upgrade;
     }
 
+    @Before
+    public void setup() {
+        outputFile = "/tmp/index_upgrade_" + UUID.randomUUID().toString();
+        String [] args = {"-o", upgrade ? UPGRADE_OP : ROLLBACK_OP, "-tb",
+                INPUT_LIST, "-lf", outputFile, "-d", "-v", DUMMY_STRING_VALUE};
+        indexUpgradeTool = new IndexUpgradeTool();
+        CommandLine cmd = indexUpgradeTool.parseOptions(args);
+        indexUpgradeTool.initializeTool(cmd);
+    }
+
     @Test
     public void testCommandLineParsing() {
+        Assert.assertEquals(indexUpgradeTool.getDryRun(),true);
+        Assert.assertEquals(indexUpgradeTool.getInputTables(), INPUT_LIST);
+        Assert.assertEquals(indexUpgradeTool.getOperation(), upgrade ? UPGRADE_OP : ROLLBACK_OP);
+        Assert.assertEquals(indexUpgradeTool.getLogFile(), outputFile);
+    }
 
-        String outputFile = "/tmp/index_upgrade_" + UUID.randomUUID().toString();
-        String [] args = {"-o", upgrade ? UPGRADE_OP : ROLLBACK_OP, "-tb",
-                INPUT_LIST, "-lf", outputFile, "-d"};
-        IndexUpgradeTool iut = new IndexUpgradeTool();
-
-        CommandLine cmd = iut.parseOptions(args);
-        iut.initializeTool(cmd);
-        Assert.assertEquals(iut.getDryRun(),true);
-        Assert.assertEquals(iut.getInputTables(), INPUT_LIST);
-        Assert.assertEquals(iut.getOperation(), upgrade ? UPGRADE_OP : ROLLBACK_OP);
-        Assert.assertEquals(iut.getLogFile(), outputFile);
+    @Test
+    public void testIfVerifyOptionIsPassedToTool() {
+        if (!upgrade) {
+            return;
+        }
+        Assert.assertEquals("value passed with verify option does not match with provided value",
+                DUMMY_STRING_VALUE, indexUpgradeTool.getVerify());
+        String [] values = indexUpgradeTool.getIndexToolArgValues(DUMMY_STRING_VALUE,
+                DUMMY_STRING_VALUE, DUMMY_STRING_VALUE, DUMMY_STRING_VALUE, DUMMY_STRING_VALUE);
+        List<String> argList =  Arrays.asList(values);
+        Assert.assertTrue(argList.contains(DUMMY_STRING_VALUE));
+        Assert.assertTrue(argList.contains("-v"));
+        Assert.assertEquals("verify option and value are not passed consecutively", 1,
+                argList.indexOf(DUMMY_STRING_VALUE) - argList.indexOf("-v"));
     }
 
     @Parameters(name ="IndexUpgradeToolTest_mutable={1}")