Search in sources :

Example 1 with ConnectionQueryServicesImpl

use of org.apache.phoenix.query.ConnectionQueryServicesImpl in project phoenix by apache.

the class UpgradeIT method testAcquiringAndReleasingUpgradeMutex.

@Test
public void testAcquiringAndReleasingUpgradeMutex() throws Exception {
    ConnectionQueryServices services = null;
    byte[] mutexRowKey = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA, generateUniqueName());
    try (Connection conn = getConnection(false, null)) {
        services = conn.unwrap(PhoenixConnection.class).getQueryServices();
        putUnlockKVInSysMutex(mutexRowKey);
        assertTrue(((ConnectionQueryServicesImpl) services).acquireUpgradeMutex(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, mutexRowKey));
        try {
            ((ConnectionQueryServicesImpl) services).acquireUpgradeMutex(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, mutexRowKey);
            fail();
        } catch (UpgradeInProgressException expected) {
        }
        assertTrue(((ConnectionQueryServicesImpl) services).releaseUpgradeMutex(mutexRowKey));
        assertFalse(((ConnectionQueryServicesImpl) services).releaseUpgradeMutex(mutexRowKey));
    }
}
Also used : ConnectionQueryServicesImpl(org.apache.phoenix.query.ConnectionQueryServicesImpl) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) DelegateConnectionQueryServices(org.apache.phoenix.query.DelegateConnectionQueryServices) ConnectionQueryServices(org.apache.phoenix.query.ConnectionQueryServices) UpgradeInProgressException(org.apache.phoenix.exception.UpgradeInProgressException) Test(org.junit.Test)

Example 2 with ConnectionQueryServicesImpl

use of org.apache.phoenix.query.ConnectionQueryServicesImpl 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);
    }
}
Also used : ConnectionlessQueryServicesImpl(org.apache.phoenix.query.ConnectionlessQueryServicesImpl) ConnectionQueryServicesImpl(org.apache.phoenix.query.ConnectionQueryServicesImpl) SQLException(java.sql.SQLException) QueryServices(org.apache.phoenix.query.QueryServices) ConnectionQueryServices(org.apache.phoenix.query.ConnectionQueryServices) ConnectionQueryServices(org.apache.phoenix.query.ConnectionQueryServices)

Aggregations

ConnectionQueryServices (org.apache.phoenix.query.ConnectionQueryServices)2 ConnectionQueryServicesImpl (org.apache.phoenix.query.ConnectionQueryServicesImpl)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 UpgradeInProgressException (org.apache.phoenix.exception.UpgradeInProgressException)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 ConnectionlessQueryServicesImpl (org.apache.phoenix.query.ConnectionlessQueryServicesImpl)1 DelegateConnectionQueryServices (org.apache.phoenix.query.DelegateConnectionQueryServices)1 QueryServices (org.apache.phoenix.query.QueryServices)1 Test (org.junit.Test)1