You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by co...@apache.org on 2015/09/11 19:59:19 UTC

[2/4] phoenix git commit: PHOENIX-2227 Added the ability to Pherf to define a DDL statement that will be executed before a scenario is run to support dynamically creating multi-tenant views we are going to write and read from

PHOENIX-2227 Added the ability to Pherf to define a DDL statement that will be executed before a scenario is run to support dynamically creating multi-tenant views we are going to write and read from


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6789fe7e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6789fe7e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6789fe7e

Branch: refs/heads/4.x-HBase-0.98
Commit: 6789fe7e36062793a1d03871347b146f7e6d5357
Parents: f9a5a92
Author: Jan <jf...@salesforce.com>
Authored: Thu Sep 3 17:48:18 2015 -0700
Committer: Cody Marcel <cm...@cmarcel-wsl1.internal.salesforce.com>
Committed: Fri Sep 11 10:58:20 2015 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/pherf/DataIngestIT.java  | 21 +++++++++++++++++++-
 .../phoenix/pherf/configuration/Scenario.java   | 13 ++++++++++++
 .../apache/phoenix/pherf/util/PhoenixUtil.java  | 21 ++++++++++++++++++++
 .../phoenix/pherf/workload/WriteWorkload.java   |  5 ++++-
 .../test/resources/scenario/test_scenario.xml   |  6 ++++++
 5 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6789fe7e/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
index b821c7b..1098799 100644
--- a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
+++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
@@ -20,7 +20,6 @@ package org.apache.phoenix.pherf;
 
 import com.jcabi.jdbc.JdbcSession;
 import com.jcabi.jdbc.Outcome;
-
 import org.apache.phoenix.pherf.PherfConstants.GeneratePhoenixStats;
 import org.apache.phoenix.pherf.configuration.Column;
 import org.apache.phoenix.pherf.configuration.DataModel;
@@ -173,6 +172,26 @@ public class DataIngestIT extends ResultBaseTestIT {
 
     }
 
+    
+    @Test
+    public void testMultiTenantScenarioRunBeforeWriteWorkload() throws Exception {
+        // Arrange
+        Scenario scenario = parser.getScenarioByName("testMTDdlWriteScenario");
+        WorkloadExecutor executor = new WorkloadExecutor();
+        executor.add(new WriteWorkload(util, parser, scenario, GeneratePhoenixStats.NO));
+        
+        // Act
+        try {
+            // Wait for data to load up.
+            executor.get();
+            executor.shutdown();
+        } catch (Exception e) {
+            fail("Failed to load data. An exception was thrown: " + e.getMessage());
+        }
+
+        assertExpectedNumberOfRecordsWritten(scenario);
+    }
+    
     private void assertExpectedNumberOfRecordsWritten(Scenario scenario) throws Exception,
             SQLException {
         Connection connection = util.getConnection(scenario.getTenantId());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6789fe7e/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
index 6c949d8..200fdc5 100644
--- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
+++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
@@ -39,6 +39,7 @@ public class Scenario {
     private WriteParams writeParams;
     private String name;
     private String tenantId;
+    private String ddl;
 
     public Scenario() {
         writeParams = new WriteParams();
@@ -178,6 +179,18 @@ public class Scenario {
         this.tenantId = tenantId;
     }
 
+    /**
+     * Scenario level DDL that is executed before running the scenario.
+     */
+    @XmlAttribute
+    public String getDdl() {
+        return ddl;
+    }
+    
+    public void setDdl(String ddl) {
+        this.ddl = ddl;
+    }
+    
     public WriteParams getWriteParams() {
         return writeParams;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6789fe7e/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
index fad06a1..57858a3 100644
--- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
+++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
@@ -243,6 +243,27 @@ public class PhoenixUtil {
             }
         }
     }
+    
+    /**
+     * Executes any ddl defined at the scenario level. This is executed before we commence
+     * the data load.
+     * 
+     * @throws Exception
+     */
+    public void executeScenarioDdl(Scenario scenario) throws Exception {
+        if (null != scenario.getDdl()) {
+            Connection conn = null;
+            try {
+                logger.info("\nExecuting DDL:" + scenario.getDdl() + " on tenantId:"
+                        + scenario.getTenantId());
+                executeStatement(scenario.getDdl(), conn = getConnection(scenario.getTenantId()));
+            } finally {
+                if (null != conn) {
+                    conn.close();
+                }
+            }
+        }
+    }
 
     public static String getZookeeper() {
         return zookeeper;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6789fe7e/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
index f9d1ee6..7b5276b 100644
--- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
+++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
@@ -164,7 +164,10 @@ public class WriteWorkload implements Workload {
             DataLoadThreadTime dataLoadThreadTime, Scenario scenario) throws Exception {
         logger.info("\nLoading " + scenario.getRowCount() + " rows for " + scenario.getTableName());
         long start = System.currentTimeMillis();
-
+        
+        // Execute any Scenario DDL before running workload
+        pUtil.executeScenarioDdl(scenario);
+        
         List<Future> writeBatches = getBatches(dataLoadThreadTime, scenario);
 
         waitForBatches(dataLoadTimeSummary, scenario, start, writeBatches);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6789fe7e/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
index b5fe564..735e690 100644
--- a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
+++ b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
@@ -223,5 +223,11 @@
         <!-- Test writing to a Multi-tenant View -->
         <scenario tableName="PHERF.TEST_VIEW" tenantId="abcdefghijklmno" rowCount="100" name="testMTWriteScenario">
         </scenario>
+        <!--  Test scenario DDL -->
+        <scenario tableName="PHERF.TEST_MT_VIEW" tenantId="abcdefghijklmno" 
+                    ddl="CREATE VIEW IF NOT EXISTS PHERF.TEST_MT_VIEW (field1 VARCHAR) AS SELECT * FROM PHERF.TEST_MULTI_TENANT_TABLE" 
+                    rowCount="100" name="testMTDdlWriteScenario">
+        </scenario>
+        
     </scenarios>
 </datamodel>
\ No newline at end of file