use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class MutableIndexFailureIT method dumpStateOfIndexes.
private static final void dumpStateOfIndexes(Connection conn, String tableName, boolean beforeRebuildTaskRun) throws SQLException {
PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
PTable table = phxConn.getTable(new PTableKey(phxConn.getTenantId(), tableName));
List<PTable> indexes = table.getIndexes();
String s = beforeRebuildTaskRun ? "before rebuild run" : "after rebuild run";
System.out.println("************Index state in connection " + s + "******************");
for (PTable idx : indexes) {
System.out.println("Index Name: " + idx.getName().getString() + " State: " + idx.getIndexState() + " Disable timestamp: " + idx.getIndexDisableTimestamp());
}
System.out.println("************Index state from server " + s + "******************");
table = PhoenixRuntime.getTableNoCache(phxConn, fullTableName);
for (PTable idx : table.getIndexes()) {
System.out.println("Index Name: " + idx.getName().getString() + " State: " + idx.getIndexState() + " Disable timestamp: " + idx.getIndexDisableTimestamp());
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class PartialIndexRebuilderIT method testRegionsOnlineCheck.
@Test
public void testRegionsOnlineCheck() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
PTableKey key = new PTableKey(null, fullTableName);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY)");
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a')");
conn.commit();
Configuration conf = conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration();
PTable table = metaCache.getTableRef(key).getTable();
assertTrue(MetaDataUtil.tableRegionsOnline(conf, table));
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
admin.disableTable(fullTableName);
assertFalse(MetaDataUtil.tableRegionsOnline(conf, table));
admin.enableTable(fullTableName);
}
assertTrue(MetaDataUtil.tableRegionsOnline(conf, table));
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class PartialIndexRebuilderIT method testMultiValuesWhenDisableAndInactive.
@Test
public void testMultiValuesWhenDisableAndInactive() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
PTableKey key = new PTableKey(null, fullTableName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2) INCLUDE (v3)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0','x')");
conn.commit();
clock.time += 100;
try (HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) {
// By using an INDEX_DISABLE_TIMESTAMP of 0, we prevent the partial index rebuilder from triggering
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
long disableTime = clock.currentTime();
// Set some values while index disabled
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11','yy')");
conn.commit();
clock.time += 100;
assertTrue(hasDisabledIndex(metaCache, key));
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','222','zzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','dddd','3333','zzzz')");
conn.commit();
clock.time += 100;
// Will cause partial index rebuilder to be triggered
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
}
runIndexRebuilder(fullTableName);
assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.INACTIVE, null));
// Set some values while index is in INACTIVE state
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','eeeee','44444','zzzzz')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','fffff','55555','zzzzzz')");
conn.commit();
clock.time += WAIT_AFTER_DISABLED;
// Enough time has passed, so rebuild will start now
runIndexRebuilder(fullTableName);
assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L));
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class PartialIndexRebuilderIT method testTimeBatchesInCoprocessorRequired.
@Test
public void testTimeBatchesInCoprocessorRequired() throws Throwable {
String schemaName = generateUniqueName();
String tableName = generateUniqueName();
String indexName = generateUniqueName();
final String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
final String fullIndexName = SchemaUtil.getTableName(schemaName, indexName);
PTableKey key = new PTableKey(null, fullTableName);
final MyClock clock = new MyClock(1000);
EnvironmentEdgeManager.injectEdge(clock);
try (Connection conn = DriverManager.getConnection(getUrl())) {
PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache();
conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
clock.time += 100;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0')");
conn.commit();
clock.time += 100;
HTableInterface metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE);
clock.time += 100;
long disableTime = clock.currentTime();
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11')");
conn.commit();
clock.time += 100;
assertTrue(hasDisabledIndex(metaCache, key));
assertEquals(2, TestUtil.getRowCount(conn, fullTableName));
assertEquals(1, TestUtil.getRowCount(conn, fullIndexName));
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','0')");
conn.commit();
clock.time += 100;
conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')");
conn.commit();
clock.time += 100;
IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE);
clock.time += 100;
waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE);
clock.time += WAIT_AFTER_DISABLED;
runIndexRebuilder(fullTableName);
assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L));
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
} finally {
EnvironmentEdgeManager.injectEdge(null);
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class DropColumnIT method helpTestDroppingIndexedColDropsViewIndex.
public void helpTestDroppingIndexedColDropsViewIndex(boolean isMultiTenant) throws Exception {
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
props.setProperty(TENANT_ID_ATTRIB, TENANT_ID);
try (Connection conn = getConnection();
Connection viewConn = isMultiTenant ? getConnection(props) : conn) {
String tableWithView = generateUniqueName();
String viewOfTable = generateUniqueName();
String viewIndex1 = generateUniqueName();
String viewIndex2 = generateUniqueName();
conn.setAutoCommit(false);
viewConn.setAutoCommit(false);
String ddlFormat = "CREATE TABLE " + tableWithView + " (%s k VARCHAR NOT NULL, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR, v4 VARCHAR CONSTRAINT PK PRIMARY KEY(%s k))%s";
String ddl = String.format(ddlFormat, isMultiTenant ? "TENANT_ID VARCHAR NOT NULL, " : "", isMultiTenant ? "TENANT_ID, " : "", isMultiTenant ? "MULTI_TENANT=true" : "");
conn.createStatement().execute(ddl);
viewConn.createStatement().execute("CREATE VIEW " + viewOfTable + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableWithView);
// create an index with the column that will be dropped
viewConn.createStatement().execute("CREATE INDEX " + viewIndex1 + " ON " + viewOfTable + "(v2) INCLUDE (v4)");
// create an index without the column that will be dropped
viewConn.createStatement().execute("CREATE INDEX " + viewIndex2 + " ON " + viewOfTable + "(v1) INCLUDE (v4)");
// verify index was created
try {
viewConn.createStatement().execute("SELECT * FROM " + viewIndex1);
} catch (TableNotFoundException e) {
fail("Index on view was not created");
}
// upsert a single row
PreparedStatement stmt = viewConn.prepareStatement("UPSERT INTO " + viewOfTable + " VALUES(?,?,?,?,?,?,?)");
stmt.setString(1, "a");
stmt.setString(2, "b");
stmt.setString(3, "c");
stmt.setString(4, "d");
stmt.setString(5, "e");
stmt.setInt(6, 1);
stmt.setString(7, "g");
stmt.execute();
viewConn.commit();
// verify the index was created
PhoenixConnection pconn = viewConn.unwrap(PhoenixConnection.class);
PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
PTable view = pconn.getTable(new PTableKey(tenantId, viewOfTable));
PTable viewIndex = pconn.getTable(new PTableKey(tenantId, viewIndex1));
byte[] viewIndexPhysicalTable = viewIndex.getPhysicalName().getBytes();
assertNotNull("Can't find view index", viewIndex);
assertEquals("Unexpected number of indexes ", 2, view.getIndexes().size());
assertEquals("Unexpected index ", viewIndex1, view.getIndexes().get(0).getName().getString());
assertEquals("Unexpected index ", viewIndex2, view.getIndexes().get(1).getName().getString());
// drop two columns
conn.createStatement().execute("ALTER TABLE " + tableWithView + " DROP COLUMN v2, v3 ");
// verify columns were dropped
try {
conn.createStatement().execute("SELECT v2 FROM " + tableWithView);
fail("Column should have been dropped");
} catch (ColumnNotFoundException e) {
}
try {
conn.createStatement().execute("SELECT v3 FROM " + tableWithView);
fail("Column should have been dropped");
} catch (ColumnNotFoundException e) {
}
// verify index metadata was dropped
try {
viewConn.createStatement().execute("SELECT * FROM " + viewIndex1);
fail("Index metadata should have been dropped");
} catch (TableNotFoundException e) {
}
pconn = viewConn.unwrap(PhoenixConnection.class);
view = pconn.getTable(new PTableKey(tenantId, viewOfTable));
try {
viewIndex = pconn.getTable(new PTableKey(tenantId, viewIndex1));
fail("View index should have been dropped");
} catch (TableNotFoundException e) {
}
assertEquals("Unexpected number of indexes ", 1, view.getIndexes().size());
assertEquals("Unexpected index ", viewIndex2, view.getIndexes().get(0).getName().getString());
// verify that the physical index view table is *not* dropped
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(viewIndexPhysicalTable);
// scan the physical table and verify there is a single row for the second local index
Scan scan = new Scan();
HTable table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(viewIndexPhysicalTable);
ResultScanner results = table.getScanner(scan);
Result result = results.next();
assertNotNull(result);
PTable viewIndexPTable = pconn.getTable(new PTableKey(pconn.getTenantId(), viewIndex2));
PColumn column = viewIndexPTable.getColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V4"));
byte[] cq = column.getColumnQualifierBytes();
// there should be a single row belonging to VIEWINDEX2
assertNotNull(viewIndex2 + " row is missing", result.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, cq));
assertNull(results.next());
}
}
Aggregations