use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class PartialCommitIT method getConnectionWithTableOrderPreservingMutationState.
private PhoenixConnection getConnectionWithTableOrderPreservingMutationState() throws SQLException {
Connection con = driver.connect(url, new Properties());
PhoenixConnection phxCon = new PhoenixConnection(con.unwrap(PhoenixConnection.class));
final Map<TableRef, Map<ImmutableBytesPtr, MutationState.RowMutationState>> mutations = Maps.newTreeMap(new TableRefComparator());
// passing a null mutation state forces the connection.newMutationState() to be used to create the MutationState
return new PhoenixConnection(phxCon, null) {
@Override
protected MutationState newMutationState(int maxSize, int maxSizeBytes) {
return new MutationState(maxSize, maxSizeBytes, this, mutations, null, null);
}
;
};
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class MutableIndexIT method assertImmutableRows.
private void assertImmutableRows(Connection conn, String fullTableName, boolean expectedValue) throws SQLException {
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
assertEquals(expectedValue, pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).isImmutableRows());
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class LocalIndexIT method testLocalIndexAutomaticRepair.
@Test
public void testLocalIndexAutomaticRepair() throws Exception {
if (isNamespaceMapped) {
return;
}
PhoenixConnection conn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class);
try (HTableInterface metaTable = conn.getQueryServices().getTable(TableName.META_TABLE_NAME.getName());
HBaseAdmin admin = conn.getQueryServices().getAdmin()) {
Statement statement = conn.createStatement();
final String tableName = "T_AUTO_MATIC_REPAIR";
String indexName = "IDX_T_AUTO_MATIC_REPAIR";
String indexName1 = "IDX_T_AUTO_MATIC_REPAIR_1";
statement.execute("create table " + tableName + " (id integer not null,fn varchar," + "cf1.ln varchar constraint pk primary key(id)) split on (1,2,3,4,5)");
statement.execute("create local index " + indexName + " on " + tableName + " (fn,cf1.ln)");
statement.execute("create local index " + indexName1 + " on " + tableName + " (fn)");
for (int i = 0; i < 7; i++) {
statement.execute("upsert into " + tableName + " values(" + i + ",'fn" + i + "','ln" + i + "')");
}
conn.commit();
ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM " + indexName);
assertTrue(rs.next());
assertEquals(7, rs.getLong(1));
List<HRegionInfo> tableRegions = admin.getTableRegions(TableName.valueOf(tableName));
admin.disableTable(tableName);
copyLocalIndexHFiles(config, tableRegions.get(0), tableRegions.get(1), false);
copyLocalIndexHFiles(config, tableRegions.get(3), tableRegions.get(0), false);
admin.enableTable(tableName);
int count = getCount(conn, tableName, "L#0");
assertTrue(count > 14);
admin.majorCompact(TableName.valueOf(tableName));
// need to wait for rebuilding of corrupted local index region
int tryCount = 5;
while (tryCount-- > 0 && count != 14) {
Thread.sleep(15000);
count = getCount(conn, tableName, "L#0");
}
assertEquals(14, count);
rs = statement.executeQuery("SELECT COUNT(*) FROM " + indexName1);
assertTrue(rs.next());
assertEquals(7, rs.getLong(1));
statement.execute("DROP INDEX " + indexName1 + " ON " + tableName);
admin.majorCompact(TableName.valueOf(tableName));
statement.execute("DROP INDEX " + indexName + " ON " + tableName);
admin.majorCompact(TableName.valueOf(tableName));
Thread.sleep(15000);
admin.majorCompact(TableName.valueOf(tableName));
Thread.sleep(15000);
rs = statement.executeQuery("SELECT COUNT(*) FROM " + tableName);
assertTrue(rs.next());
}
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class SaltedIndexIT method makeImmutableAndDeleteData.
private static void makeImmutableAndDeleteData(String tableName, String fullTableName) throws Exception {
Connection conn = getConnection();
try {
conn.setAutoCommit(true);
conn.createStatement().execute("DELETE FROM " + fullTableName);
conn.createStatement().execute("ALTER TABLE " + fullTableName + " SET IMMUTABLE_ROWS=true");
conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName).next();
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
assertTrue(pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).isImmutableRows());
} finally {
conn.close();
}
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class MutableRollbackIT method testRollbackOfUncommittedExistingRowKeyIndexUpdate.
@Test
public void testRollbackOfUncommittedExistingRowKeyIndexUpdate() throws Exception {
String tableName1 = "TBL1_" + generateUniqueName();
String indexName1 = "IDX1_" + generateUniqueName();
String fullTableName1 = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName1);
String tableName2 = "TBL2_" + generateUniqueName();
String indexName2 = "IDX2_" + generateUniqueName();
String fullTableName2 = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName2);
Connection conn = getConnection();
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
stmt.execute("CREATE TABLE " + fullTableName2 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
stmt.execute("CREATE " + (localIndex ? " LOCAL " : "") + "INDEX " + indexName1 + " ON " + fullTableName1 + " (v1, k)");
stmt.execute("CREATE " + (localIndex ? " LOCAL " : "") + "INDEX " + indexName2 + " ON " + fullTableName2 + " (v1, k)");
stmt.executeUpdate("upsert into " + fullTableName1 + " values('x', 'y', 'a')");
conn.commit();
//assert rows exists in " + fullTableName1 + "
ResultSet rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName1);
assertTrue(rs.next());
assertEquals("x", rs.getString(1));
assertEquals("y", rs.getString(2));
assertEquals("a", rs.getString(3));
assertFalse(rs.next());
//assert rows exists in indexName1
rs = stmt.executeQuery("select /*+ INDEX(" + indexName1 + ")*/ k, v1 from " + fullTableName1);
assertTrue(rs.next());
assertEquals("x", rs.getString(1));
assertEquals("y", rs.getString(2));
assertFalse(rs.next());
//assert no rows exists in fullTableName2
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName2);
assertFalse(rs.next());
//assert no rows exists in indexName2
rs = stmt.executeQuery("select /*+ INDEX(" + indexName2 + ")*/ k, v1 from " + fullTableName2);
assertFalse(rs.next());
stmt.executeUpdate("upsert into " + fullTableName1 + " values('x', 'z', 'a')");
stmt.executeUpdate("upsert into " + fullTableName2 + " values('a', 'b', 'c')");
assertDataAndIndexRows(stmt, fullTableName1, fullTableName2, indexName1);
conn.rollback();
//assert original row exists in fullTableName1
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName1);
assertTrue(rs.next());
assertEquals("x", rs.getString(1));
assertEquals("y", rs.getString(2));
assertEquals("a", rs.getString(3));
assertFalse(rs.next());
//assert original row exists in indexName1
rs = stmt.executeQuery("select /*+ INDEX(" + indexName1 + ")*/ k, v1, v2 from " + fullTableName1);
assertTrue(rs.next());
assertEquals("x", rs.getString(1));
assertEquals("y", rs.getString(2));
assertEquals("a", rs.getString(3));
assertFalse(rs.next());
//assert no rows exists in fullTableName2
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName2);
assertFalse(rs.next());
//assert no rows exists in indexName2
rs = stmt.executeQuery("select /*+ INDEX(" + indexName1 + ")*/ k, v1 from " + fullTableName2);
assertFalse(rs.next());
stmt.executeUpdate("upsert into " + fullTableName1 + " values('x', 'z', 'a')");
stmt.executeUpdate("upsert into " + fullTableName2 + " values('a', 'b', 'c')");
conn.commit();
assertDataAndIndexRows(stmt, fullTableName1, fullTableName2, indexName1);
stmt.executeUpdate("delete from " + fullTableName1 + " where k='x'");
stmt.executeUpdate("delete from " + fullTableName2 + " where v1='b'");
//assert no rows exists in fullTableName1
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName1);
assertFalse(rs.next());
//assert no rows exists in indexName1
rs = stmt.executeQuery("select /*+ INDEX(" + indexName1 + ")*/ k, v1 from " + fullTableName1);
assertFalse(rs.next());
//assert no rows exists in fullTableName2
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName2);
assertFalse(rs.next());
//assert no rows exists in indexName2
rs = stmt.executeQuery("select /*+ INDEX(" + indexName2 + ")*/ k, v1 from " + fullTableName2);
assertFalse(rs.next());
conn.rollback();
assertDataAndIndexRows(stmt, fullTableName1, fullTableName2, indexName1);
PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
if (localIndex) {
dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName1);
dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName2);
}
} finally {
conn.close();
}
}
Aggregations