You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2021/03/27 00:03:53 UTC

[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #1185: PHOENIX-6429 Add support for global connections and sequential data generators

ChinmaySKulkarni commented on a change in pull request #1185:
URL: https://github.com/apache/phoenix/pull/1185#discussion_r602635060



##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/mt/tenantoperation/PreScenarioOperationSupplier.java
##########
@@ -48,32 +49,34 @@ public PreScenarioOperationSupplier(PhoenixUtil phoenixUtil, DataModel model, Sc
 
             @Override
             public OperationStats apply(final TenantOperationInfo input) {
+                Preconditions.checkNotNull(input);
                 final PreScenarioOperation operation = (PreScenarioOperation) input.getOperation();
-                final String tenantId = input.getTenantId();
                 final String tenantGroup = input.getTenantGroupId();
                 final String opGroup = input.getOperationGroupId();
                 final String tableName = input.getTableName();
                 final String scenarioName = input.getScenarioName();
-                final String opName = String.format("%s:%s:%s:%s:%s",
-                        scenarioName, tableName, opGroup, tenantGroup, tenantId);
 
                 long startTime = EnvironmentEdgeManager.currentTimeMillis();
                 int status = 0;
                 if (!operation.getPreScenarioDdls().isEmpty()) {
-                    try (Connection conn = phoenixUtil.getConnection(tenantId)) {
-                        for (Ddl ddl : operation.getPreScenarioDdls()) {
-                            LOGGER.info("\nExecuting DDL:" + ddl + " on tenantId:" + tenantId);
+                    for (Ddl ddl : operation.getPreScenarioDdls()) {
+                        final String tenantId = ddl.isUseGlobalConnection() ? null : input.getTenantId();
+                        final String opName = String.format("%s:%s:%s:%s:%s",

Review comment:
       Like discussed offline, can you add a comment saying that `input.getTenantId()` is only used for logging purposes in the case of global connections?

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/SequentialDateDataGenerator.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.phoenix.pherf.rules;
+
+import com.google.common.base.Preconditions;
+import org.apache.phoenix.pherf.configuration.Column;
+import org.apache.phoenix.pherf.configuration.DataSequence;
+import org.apache.phoenix.pherf.configuration.DataTypeMapping;
+
+import org.joda.time.LocalDateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class SequentialDateDataGenerator implements RuleBasedDataGenerator {
+    private static DateTimeFormatter FMT = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
+    private final Column columnRule;
+    private final AtomicInteger counter;
+    private final LocalDateTime startDateTime = new LocalDateTime();
+
+    public SequentialDateDataGenerator(Column columnRule) {
+        Preconditions.checkArgument(columnRule.getDataSequence() == DataSequence.SEQUENTIAL);
+        Preconditions.checkArgument(isDateType(columnRule.getType()));
+        this.columnRule = columnRule;
+        counter = new AtomicInteger(0);
+    }
+
+    /**
+     * Note that this method rolls over for attempts to get larger than maxValue
+     * @return new DataValue
+     */
+    @Override
+    public DataValue getDataValue() {
+        LocalDateTime newDateTime = startDateTime.plusSeconds(counter.getAndIncrement());

Review comment:
       since we are using an AtomicInteger for counter, looks like we will be accessing this concurrently. In that case, we should probably also ensure atomic updates to `startDateTime` right?

##########
File path: phoenix-pherf/src/test/java/org/apache/phoenix/pherf/rules/SequentialDateDataGeneratorTest.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.phoenix.pherf.rules;
+
+import org.apache.phoenix.pherf.configuration.Column;
+import org.apache.phoenix.pherf.configuration.DataSequence;
+import org.joda.time.LocalDateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.junit.Test;
+
+import static org.apache.phoenix.pherf.configuration.DataTypeMapping.DATE;
+import static org.apache.phoenix.pherf.configuration.DataTypeMapping.VARCHAR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SequentialDateDataGeneratorTest {
+    SequentialDateDataGenerator generator;
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testRejectsNonSequential() {
+        Column columnA = new Column();
+        columnA.setType(DATE);
+        columnA.setDataSequence(DataSequence.RANDOM);
+
+        //should reject this Column
+        generator = new SequentialDateDataGenerator(columnA);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testRejectsNonDate() {
+        Column columnA = new Column();
+        columnA.setType(VARCHAR);
+        columnA.setDataSequence(DataSequence.SEQUENTIAL);
+
+        //should reject this Column
+        generator = new SequentialDateDataGenerator(columnA);
+    }
+
+    @Test
+    public void testGetDataValue() {
+        DateTimeFormatter FMT = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
+        Column columnA = new Column();
+        columnA.setType(DATE);
+        columnA.setDataSequence(DataSequence.SEQUENTIAL);
+        LocalDateTime startDateTime = new LocalDateTime();
+
+        // The increments are the of 1 sec units
+        generator = new SequentialDateDataGenerator(columnA);
+        DataValue result1 = generator.getDataValue();
+        LocalDateTime result1LocalTime = FMT.parseDateTime(result1.getValue()).toLocalDateTime();
+        assertTrue(!result1LocalTime.isBefore(startDateTime));

Review comment:
       nit: use assertFalse instead

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/SequentialVarcharDataGenerator.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.phoenix.pherf.rules;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang.StringUtils;
+import org.apache.phoenix.pherf.configuration.Column;
+import org.apache.phoenix.pherf.configuration.DataSequence;
+import org.apache.phoenix.pherf.configuration.DataTypeMapping;
+import org.joda.time.LocalDateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SequentialVarcharDataGenerator implements RuleBasedDataGenerator {

Review comment:
       nit: add class-level comment about usage?

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/SequentialListDataGenerator.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.phoenix.pherf.rules;
+
+import com.google.common.base.Preconditions;
+import org.apache.phoenix.pherf.configuration.Column;
+import org.apache.phoenix.pherf.configuration.DataSequence;
+import org.apache.phoenix.pherf.configuration.DataTypeMapping;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SequentialListDataGenerator implements RuleBasedDataGenerator {

Review comment:
       nit: add class-level comment about usage?

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/rules/SequentialDateDataGenerator.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.phoenix.pherf.rules;
+
+import com.google.common.base.Preconditions;
+import org.apache.phoenix.pherf.configuration.Column;
+import org.apache.phoenix.pherf.configuration.DataSequence;
+import org.apache.phoenix.pherf.configuration.DataTypeMapping;
+
+import org.joda.time.LocalDateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class SequentialDateDataGenerator implements RuleBasedDataGenerator {

Review comment:
       nit: Add class-level comment?

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/mt/tenantoperation/PreScenarioOperationSupplier.java
##########
@@ -48,32 +49,34 @@ public PreScenarioOperationSupplier(PhoenixUtil phoenixUtil, DataModel model, Sc
 
             @Override
             public OperationStats apply(final TenantOperationInfo input) {
+                Preconditions.checkNotNull(input);
                 final PreScenarioOperation operation = (PreScenarioOperation) input.getOperation();
-                final String tenantId = input.getTenantId();
                 final String tenantGroup = input.getTenantGroupId();
                 final String opGroup = input.getOperationGroupId();
                 final String tableName = input.getTableName();
                 final String scenarioName = input.getScenarioName();
-                final String opName = String.format("%s:%s:%s:%s:%s",
-                        scenarioName, tableName, opGroup, tenantGroup, tenantId);
 
                 long startTime = EnvironmentEdgeManager.currentTimeMillis();
                 int status = 0;
                 if (!operation.getPreScenarioDdls().isEmpty()) {
-                    try (Connection conn = phoenixUtil.getConnection(tenantId)) {
-                        for (Ddl ddl : operation.getPreScenarioDdls()) {
-                            LOGGER.info("\nExecuting DDL:" + ddl + " on tenantId:" + tenantId);
+                    for (Ddl ddl : operation.getPreScenarioDdls()) {
+                        final String tenantId = ddl.isUseGlobalConnection() ? null : input.getTenantId();
+                        final String opName = String.format("%s:%s:%s:%s:%s",
+                                scenarioName, tableName, opGroup, tenantGroup, input.getTenantId());
+
+                        try (Connection conn = phoenixUtil.getConnection(tenantId)) {
+                            LOGGER.info("\nExecuting DDL:" + ddl + ", OPERATION:" + opName);
                             phoenixUtil.executeStatement(ddl.toString(), conn);
                             if (ddl.getStatement().toUpperCase().contains(phoenixUtil.ASYNC_KEYWORD)) {
                                 phoenixUtil.waitForAsyncIndexToFinish(ddl.getTableName());
                             }
+                        } catch (SQLException sqle) {

Review comment:
       Looks like you don't need this catch block since the one below does the same thing and covers it

##########
File path: phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/LoadProfile.java
##########
@@ -37,7 +37,7 @@
      * TenantId format should typically have 2 parts -
      * 1. string fmt - that hold the tenant group id.
      * 2. int fmt - that holds a random number between 1 and max tenants
-     * for e.g DEFAULT_TENANT_ID_FMT = "00D%s%07d";
+     * for e.g DEFAULT_TENANT_ID_FMT = "T%s%07d";

Review comment:
       Maybe add the comment for global connections 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org