use of org.apache.phoenix.query.ConnectionQueryServices in project phoenix by apache.
the class PhoenixDriver method getConnectionQueryServices.
@Override
protected ConnectionQueryServices getConnectionQueryServices(String url, final Properties info) throws SQLException {
try {
lockInterruptibly(LockMode.READ);
checkClosed();
ConnectionInfo connInfo = ConnectionInfo.create(url);
SQLException sqlE = null;
boolean success = false;
final QueryServices services = getQueryServices();
ConnectionQueryServices connectionQueryServices = null;
// Also performs the Kerberos login if the URL/properties request this
final ConnectionInfo normalizedConnInfo = connInfo.normalize(services.getProps(), info);
try {
connectionQueryServices = connectionQueryServicesCache.get(normalizedConnInfo, new Callable<ConnectionQueryServices>() {
@Override
public ConnectionQueryServices call() throws Exception {
ConnectionQueryServices connectionQueryServices;
if (normalizedConnInfo.isConnectionless()) {
connectionQueryServices = new ConnectionlessQueryServicesImpl(services, normalizedConnInfo, info);
} else {
connectionQueryServices = new ConnectionQueryServicesImpl(services, normalizedConnInfo, info);
}
return connectionQueryServices;
}
});
connectionQueryServices.init(url, info);
success = true;
} catch (ExecutionException ee) {
if (ee.getCause() instanceof SQLException) {
sqlE = (SQLException) ee.getCause();
} else {
throw new SQLException(ee);
}
} catch (SQLException e) {
sqlE = e;
} finally {
if (!success) {
// Remove from map, as initialization failed
connectionQueryServicesCache.invalidate(normalizedConnInfo);
if (sqlE != null) {
throw sqlE;
}
}
}
return connectionQueryServices;
} finally {
unlock(LockMode.READ);
}
}
use of org.apache.phoenix.query.ConnectionQueryServices in project phoenix by apache.
the class PhoenixEmbeddedDriver method createConnection.
protected final Connection createConnection(String url, Properties info) throws SQLException {
Properties augmentedInfo = PropertiesUtil.deepCopy(info);
augmentedInfo.putAll(getDefaultProps().asMap());
ConnectionQueryServices connectionServices = getConnectionQueryServices(url, augmentedInfo);
PhoenixConnection connection = connectionServices.connect(url, augmentedInfo);
return connection;
}
use of org.apache.phoenix.query.ConnectionQueryServices in project phoenix by apache.
the class MutableIndexIT method testIndexHalfStoreFileReader.
@Test
public void testIndexHalfStoreFileReader() throws Exception {
Connection conn1 = getConnection();
ConnectionQueryServices connectionQueryServices = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES);
HBaseAdmin admin = connectionQueryServices.getAdmin();
String tableName = "TBL_" + generateUniqueName();
String indexName = "IDX_" + generateUniqueName();
createBaseTable(conn1, tableName, "('e')");
conn1.createStatement().execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON " + tableName + "(v1)" + (localIndex ? "" : " SPLIT ON ('e')"));
conn1.createStatement().execute("UPSERT INTO " + tableName + " values('b',1,2,4,'z')");
conn1.createStatement().execute("UPSERT INTO " + tableName + " values('f',1,2,3,'z')");
conn1.createStatement().execute("UPSERT INTO " + tableName + " values('j',2,4,2,'a')");
conn1.createStatement().execute("UPSERT INTO " + tableName + " values('q',3,1,1,'c')");
conn1.commit();
String query = "SELECT count(*) FROM " + tableName + " where v1<='z'";
ResultSet rs = conn1.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
TableName indexTable = TableName.valueOf(localIndex ? tableName : indexName);
admin.flush(indexTable);
boolean merged = false;
HTableInterface table = connectionQueryServices.getTable(indexTable.getName());
// merge regions until 1 left
long numRegions = 0;
while (true) {
rs = conn1.createStatement().executeQuery(query);
assertTrue(rs.next());
//TODO this returns 5 sometimes instead of 4, duplicate results?
assertEquals(4, rs.getInt(1));
try {
List<HRegionInfo> indexRegions = admin.getTableRegions(indexTable);
numRegions = indexRegions.size();
if (numRegions == 1) {
break;
}
if (!merged) {
List<HRegionInfo> regions = admin.getTableRegions(indexTable);
Log.info("Merging: " + regions.size());
admin.mergeRegions(regions.get(0).getEncodedNameAsBytes(), regions.get(1).getEncodedNameAsBytes(), false);
merged = true;
Threads.sleep(10000);
}
} catch (Exception ex) {
Log.info(ex);
}
long waitStartTime = System.currentTimeMillis();
// wait until merge happened
while (System.currentTimeMillis() - waitStartTime < 10000) {
List<HRegionInfo> regions = admin.getTableRegions(indexTable);
Log.info("Waiting:" + regions.size());
if (regions.size() < numRegions) {
break;
}
Threads.sleep(1000);
}
SnapshotTestingUtils.waitForTableToBeOnline(BaseTest.getUtility(), indexTable);
assertTrue("Index table should be online ", admin.isTableAvailable(indexTable));
}
}
use of org.apache.phoenix.query.ConnectionQueryServices in project phoenix by apache.
the class UpgradeIT method testConcurrentUpgradeThrowsUprgadeInProgressException.
@Test
public void testConcurrentUpgradeThrowsUprgadeInProgressException() throws Exception {
final AtomicBoolean mutexStatus1 = new AtomicBoolean(false);
final AtomicBoolean mutexStatus2 = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(2);
final AtomicInteger numExceptions = new AtomicInteger(0);
ConnectionQueryServices services = null;
final byte[] mutexKey = Bytes.toBytes(generateUniqueName());
try (Connection conn = getConnection(false, null)) {
services = conn.unwrap(PhoenixConnection.class).getQueryServices();
putUnlockKVInSysMutex(mutexKey);
FutureTask<Void> task1 = new FutureTask<>(new AcquireMutexRunnable(mutexStatus1, services, latch, numExceptions, mutexKey));
FutureTask<Void> task2 = new FutureTask<>(new AcquireMutexRunnable(mutexStatus2, services, latch, numExceptions, mutexKey));
Thread t1 = new Thread(task1);
t1.setDaemon(true);
Thread t2 = new Thread(task2);
t2.setDaemon(true);
t1.start();
t2.start();
latch.await();
// make sure tasks didn't fail by calling get()
task1.get();
task2.get();
assertTrue("One of the threads should have acquired the mutex", mutexStatus1.get() || mutexStatus2.get());
assertNotEquals("One and only one thread should have acquired the mutex ", mutexStatus1.get(), mutexStatus2.get());
assertEquals("One and only one thread should have caught UpgradeRequiredException ", 1, numExceptions.get());
}
}
use of org.apache.phoenix.query.ConnectionQueryServices in project phoenix by apache.
the class ProductMetricsIT method destroyTable.
private static void destroyTable() throws Exception {
// Physically delete HBase table so that splits occur as expected for each test
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
ConnectionQueryServices services = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class).getQueryServices();
HBaseAdmin admin = services.getAdmin();
try {
try {
admin.disableTable(PRODUCT_METRICS_NAME);
admin.deleteTable(PRODUCT_METRICS_NAME);
} catch (TableNotFoundException e) {
}
} finally {
admin.close();
}
}
Aggregations