Skip to content

Commit

Permalink
Revert "PHOENIX-2543 Modify StatsCollectorIT to test transactional te…
Browse files Browse the repository at this point in the history
…st cases"

This reverts commit 791a27c.
  • Loading branch information
Thomas D'Silva committed Jan 28, 2016
1 parent c89903e commit 8a799b8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 152 deletions.
Expand Up @@ -30,8 +30,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -45,23 +43,14 @@
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.google.common.collect.Maps;

@RunWith(Parameterized.class)

public class StatsCollectorIT extends StatsCollectorAbstractIT {
private static final String STATS_TEST_TABLE_NAME = "S";

private final String tableDDLOptions;
private final String tableName;
private final String fullTableName;

@BeforeClass
public static void doSetup() throws Exception {
Expand All @@ -73,31 +62,30 @@ public static void doSetup() throws Exception {
props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

public StatsCollectorIT( boolean transactional) {
this.tableDDLOptions= transactional ? " TRANSACTIONAL=true" : "";
this.tableName = TestUtil.DEFAULT_DATA_TABLE_NAME + ( transactional ? "_TXN" : "");
this.fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);

@Test
public void testUpdateStatsForNonTxnTable() throws Throwable {
helpTestUpdateStats(false);
}

@Parameters(name="transactional = {0}")
public static Collection<Boolean> data() {
return Arrays.asList(false,true);
@Test
public void testUpdateStatsForTxnTable() throws Throwable {
helpTestUpdateStats(true);
}

@Test
public void testUpdateStats() throws SQLException, IOException,
private void helpTestUpdateStats(boolean transactional) throws SQLException, IOException,
InterruptedException {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
String tableName = "T" + (transactional ? "_TXN" : "");
// props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(
"CREATE TABLE " + fullTableName +" ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC))"
+ tableDDLOptions );
"CREATE TABLE " + tableName +" ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC))"
+ (transactional ? " TRANSACTIONAL=true" : ""));
String[] s;
Array array;
conn = upsertValues(props, tableName);
Expand Down Expand Up @@ -131,14 +119,14 @@ public void testNoDuplicatesAfterUpdateStats() throws Throwable {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute("CREATE TABLE " + fullTableName +" ( k VARCHAR, c1.a bigint,c2.b bigint CONSTRAINT pk PRIMARY KEY (k))" + tableDDLOptions );
conn.createStatement().execute("upsert into " + fullTableName +" values ('abc',1,3)");
conn.createStatement().execute("upsert into " + fullTableName +" values ('def',2,4)");
.execute("CREATE TABLE x ( k VARCHAR, c1.a bigint,c2.b bigint CONSTRAINT pk PRIMARY KEY (k)) \n");
conn.createStatement().execute("upsert into x values ('abc',1,3)");
conn.createStatement().execute("upsert into x values ('def',2,4)");
conn.commit();
// CAll the update statistics query here
stmt = conn.prepareStatement("UPDATE STATISTICS " + fullTableName);
stmt = conn.prepareStatement("UPDATE STATISTICS X");
stmt.execute();
rs = conn.createStatement().executeQuery("SELECT k FROM " + fullTableName);
rs = conn.createStatement().executeQuery("SELECT k FROM x");
assertTrue(rs.next());
assertEquals("abc", rs.getString(1));
assertTrue(rs.next());
Expand All @@ -149,29 +137,28 @@ public void testNoDuplicatesAfterUpdateStats() throws Throwable {

@Test
public void testUpdateStatsWithMultipleTables() throws Throwable {
String fullTableName2 = fullTableName+"_2";
Connection conn;
PreparedStatement stmt;
ResultSet rs;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
// props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(
"CREATE TABLE " + fullTableName +" ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC))" + tableDDLOptions );
"CREATE TABLE x ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC)) \n");
conn.createStatement().execute(
"CREATE TABLE " + fullTableName2 +" ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC))" + tableDDLOptions );
"CREATE TABLE z ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
+ " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC)) \n");
String[] s;
Array array;
conn = upsertValues(props, fullTableName);
conn = upsertValues(props, fullTableName2);
conn = upsertValues(props, "x");
conn = upsertValues(props, "z");
// CAll the update statistics query here
stmt = conn.prepareStatement("UPDATE STATISTICS "+fullTableName);
stmt = conn.prepareStatement("UPDATE STATISTICS X");
stmt.execute();
stmt = conn.prepareStatement("UPDATE STATISTICS "+fullTableName2);
stmt = conn.prepareStatement("UPDATE STATISTICS Z");
stmt.execute();
stmt = upsertStmt(conn, fullTableName);
stmt = upsertStmt(conn, "x");
stmt.setString(1, "z");
s = new String[] { "xyz", "def", "ghi", "jkll", null, null, "xxx" };
array = conn.createArrayOf("VARCHAR", s);
Expand All @@ -180,7 +167,7 @@ public void testUpdateStatsWithMultipleTables() throws Throwable {
array = conn.createArrayOf("VARCHAR", s);
stmt.setArray(3, array);
stmt.execute();
stmt = upsertStmt(conn, fullTableName2);
stmt = upsertStmt(conn, "z");
stmt.setString(1, "z");
s = new String[] { "xyz", "def", "ghi", "jkll", null, null, "xxx" };
array = conn.createArrayOf("VARCHAR", s);
Expand All @@ -192,9 +179,9 @@ public void testUpdateStatsWithMultipleTables() throws Throwable {
conn.close();
conn = DriverManager.getConnection(getUrl(), props);
// This analyze would not work
stmt = conn.prepareStatement("UPDATE STATISTICS "+fullTableName2);
stmt = conn.prepareStatement("UPDATE STATISTICS Z");
stmt.execute();
rs = conn.createStatement().executeQuery("SELECT k FROM "+fullTableName2);
rs = conn.createStatement().executeQuery("SELECT k FROM Z");
assertTrue(rs.next());
conn.close();
}
Expand Down
137 changes: 28 additions & 109 deletions phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
Expand Up @@ -20,8 +20,6 @@
import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
import static org.apache.phoenix.util.TestUtil.analyzeTable;
import static org.apache.phoenix.util.TestUtil.getAllSplits;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -38,6 +36,12 @@
import java.util.Map;
import java.util.Properties;

import co.cask.tephra.TransactionContext;
import co.cask.tephra.TransactionSystemClient;
import co.cask.tephra.TxConstants;
import co.cask.tephra.hbase11.TransactionAwareHTable;
import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;

import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -52,7 +56,6 @@
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
Expand All @@ -68,12 +71,6 @@
import org.junit.Ignore;
import org.junit.Test;

import co.cask.tephra.TransactionContext;
import co.cask.tephra.TransactionSystemClient;
import co.cask.tephra.TxConstants;
import co.cask.tephra.hbase11.TransactionAwareHTable;
import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

Expand All @@ -89,9 +86,8 @@ public void setUp() throws SQLException {
@BeforeClass
@Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
public static void doSetup() throws Exception {
Map<String,String> props = Maps.newHashMapWithExpectedSize(2);
Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Integer.toString(20));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

Expand Down Expand Up @@ -585,107 +581,30 @@ public void testRowTimestampDisabled() throws SQLException {
}

@Test
public void testReadOnlyViewWithStats() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl())) {
String ddl = "CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
conn.createStatement().execute(ddl);
ddl = "CREATE VIEW v (v2 VARCHAR) AS SELECT * FROM t where k>5";
conn.createStatement().execute(ddl);
for (int i = 0; i < 10; i++) {
conn.createStatement().execute("UPSERT INTO t VALUES(" + i + ")");
}
conn.commit();

// verify rows are visible for stats
analyzeTable(conn, "v", true);
List<KeyRange> splits = getAllSplits(conn, "v");
assertEquals(4, splits.size());

int count = 0;
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM t");
while (rs.next()) {
assertEquals(count++, rs.getInt(1));
}
assertEquals(10, count);

count = 0;
rs = conn.createStatement().executeQuery("SELECT k FROM v");
while (rs.next()) {
assertEquals(6+count++, rs.getInt(1));
}
assertEquals(4, count);
public void testReadOnlyView() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String ddl = "CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
conn.createStatement().execute(ddl);
ddl = "CREATE VIEW v (v2 VARCHAR) AS SELECT * FROM t where k>4";
conn.createStatement().execute(ddl);
for (int i = 0; i < 10; i++) {
conn.createStatement().execute("UPSERT INTO t VALUES(" + i + ")");
}
}

@Test
public void testReadOwnWritesWithStats() throws Exception {
try (Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
String ddl = "CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
conn1.createStatement().execute(ddl);
ddl = "CREATE VIEW v (v2 VARCHAR) AS SELECT * FROM t where k>5";
conn1.createStatement().execute(ddl);
for (int i = 0; i < 10; i++) {
conn1.createStatement().execute("UPSERT INTO t VALUES(" + i + ")");
}

// verify you can read your own writes
int count = 0;
ResultSet rs = conn1.createStatement().executeQuery("SELECT k FROM t");
while (rs.next()) {
assertEquals(count++, rs.getInt(1));
}
assertEquals(10, count);

count = 0;
rs = conn1.createStatement().executeQuery("SELECT k FROM v");
while (rs.next()) {
assertEquals(6+count++, rs.getInt(1));
}
assertEquals(4, count);

// verify stats can see the read own writes rows
analyzeTable(conn2, "v", true);
List<KeyRange> splits = getAllSplits(conn2, "v");
assertEquals(4, splits.size());
conn.commit();

int count = 0;
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM t");
while (rs.next()) {
assertEquals(count++, rs.getInt(1));
}
}

@Test
public void testInvalidRowsWithStats() throws Exception {
try (Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
String ddl = "CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
conn1.createStatement().execute(ddl);
ddl = "CREATE VIEW v (v2 VARCHAR) AS SELECT * FROM t where k>5";
conn1.createStatement().execute(ddl);
for (int i = 0; i < 10; i++) {
conn1.createStatement().execute("UPSERT INTO t VALUES(" + i + ")");
}

// verify you can read your own writes
int count = 0;
ResultSet rs = conn1.createStatement().executeQuery("SELECT k FROM t");
while (rs.next()) {
assertEquals(count++, rs.getInt(1));
}
assertEquals(10, count);

count = 0;
rs = conn1.createStatement().executeQuery("SELECT k FROM v");
while (rs.next()) {
assertEquals(6+count++, rs.getInt(1));
}
assertEquals(4, count);

Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+20000);
assertEquals("There should be one invalid transaction", 1, txManager.getInvalidSize());

// verify stats can see the rows from the invalid transaction
analyzeTable(conn2, "v", true);
List<KeyRange> splits = getAllSplits(conn2, "v");
assertEquals(4, splits.size());
assertEquals(10, count);

count = 0;
rs = conn.createStatement().executeQuery("SELECT k FROM v");
while (rs.next()) {
assertEquals(5+count++, rs.getInt(1));
}
assertEquals(5, count);
}

@Test
Expand Down

0 comments on commit 8a799b8

Please sign in to comment.