Search in sources :

Example 31 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class MigrateSystemTablesToSystemNamespaceIT method verifySyscatData.

private void verifySyscatData(Properties clientProps, String connName, Statement stmt) throws SQLException {
    ResultSet rs = stmt.executeQuery("SELECT * FROM SYSTEM.CATALOG");
    ReadOnlyProps props = new ReadOnlyProps((Map) clientProps);
    boolean systemTablesMapped = SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, props);
    boolean systemSchemaExists = false;
    Set<String> namespaceMappedSystemTablesSet = new HashSet<>(PHOENIX_NAMESPACE_MAPPED_SYSTEM_TABLES);
    Set<String> systemTablesSet = new HashSet<>(PHOENIX_SYSTEM_TABLES);
    while (rs.next()) {
        if (rs.getString("IS_NAMESPACE_MAPPED") == null) {
            systemSchemaExists = rs.getString("TABLE_SCHEM").equals(PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME) ? true : systemSchemaExists;
        } else if (rs.getString("COLUMN_NAME") == null) {
            String schemaName = rs.getString("TABLE_SCHEM");
            String tableName = rs.getString("TABLE_NAME");
            if (schemaName.equals(PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME)) {
                if (systemTablesMapped) {
                    namespaceMappedSystemTablesSet.remove(String.valueOf(TableName.valueOf(schemaName + QueryConstants.NAMESPACE_SEPARATOR + tableName)));
                    assertTrue(rs.getString("IS_NAMESPACE_MAPPED").equals(Boolean.TRUE.toString()));
                } else {
                    systemTablesSet.remove(String.valueOf(TableName.valueOf(schemaName + QueryConstants.NAME_SEPARATOR + tableName)));
                    assertTrue(rs.getString("IS_NAMESPACE_MAPPED").equals(Boolean.FALSE.toString()));
                }
            }
        }
    }
    if (!systemSchemaExists) {
        fail(PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME + " entry doesn't exist in SYSTEM.CATALOG table.");
    }
    // The set will contain SYSMUTEX table since that table is not exposed in SYSCAT
    if (systemTablesMapped) {
        assertTrue(namespaceMappedSystemTablesSet.size() == 1);
    } else {
        assertTrue(systemTablesSet.size() == 1);
    }
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Example 32 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class IndexExtendedIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(2);
    serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(2);
    clientProps.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
    clientProps.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.TRUE.toString());
    setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) BeforeClass(org.junit.BeforeClass)

Example 33 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class DropSchemaIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    // Drop the HBase table metadata for this test
    props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
    // Must update config before starting server
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) BeforeClass(org.junit.BeforeClass)

Example 34 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class MetaDataEndpointImpl method start.

/**
 * Stores a reference to the coprocessor environment provided by the
 * {@link org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost} from the region where this
 * coprocessor is loaded. Since this is a coprocessor endpoint, it always expects to be loaded
 * on a table region, so always expects this to be an instance of
 * {@link RegionCoprocessorEnvironment}.
 * @param env the environment provided by the coprocessor host
 * @throws IOException if the provided environment is not an instance of
 *             {@code RegionCoprocessorEnvironment}
 */
@Override
public void start(CoprocessorEnvironment env) throws IOException {
    if (env instanceof RegionCoprocessorEnvironment) {
        this.env = (RegionCoprocessorEnvironment) env;
    } else {
        throw new CoprocessorException("Must be loaded on a table region!");
    }
    phoenixAccessCoprocessorHost = new PhoenixMetaDataCoprocessorHost(this.env);
    Configuration config = env.getConfiguration();
    this.accessCheckEnabled = config.getBoolean(QueryServices.PHOENIX_ACLS_ENABLED, QueryServicesOptions.DEFAULT_PHOENIX_ACLS_ENABLED);
    this.blockWriteRebuildIndex = config.getBoolean(QueryServices.INDEX_FAILURE_BLOCK_WRITE, QueryServicesOptions.DEFAULT_INDEX_FAILURE_BLOCK_WRITE);
    this.maxIndexesPerTable = config.getInt(QueryServices.MAX_INDEXES_PER_TABLE, QueryServicesOptions.DEFAULT_MAX_INDEXES_PER_TABLE);
    this.isTablesMappingEnabled = SchemaUtil.isNamespaceMappingEnabled(PTableType.TABLE, new ReadOnlyProps(config.iterator()));
    logger.info("Starting Tracing-Metrics Systems");
    // Start the phoenix trace collection
    Tracing.addTraceMetricsSource();
    Metrics.ensureConfigured();
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Configuration(org.apache.hadoop.conf.Configuration) CoprocessorException(org.apache.hadoop.hbase.coprocessor.CoprocessorException)

Example 35 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class ConnectionQueryServicesImplTest method testExceptionHandlingOnSystemNamespaceCreation.

@SuppressWarnings("unchecked")
@Test
public void testExceptionHandlingOnSystemNamespaceCreation() throws Exception {
    ConnectionQueryServicesImpl cqs = mock(ConnectionQueryServicesImpl.class);
    // Invoke the real methods for these two calls
    when(cqs.createSchema(any(List.class), anyString())).thenCallRealMethod();
    doCallRealMethod().when(cqs).ensureSystemTablesMigratedToSystemNamespace(any(ReadOnlyProps.class));
    // Do nothing for this method, just check that it was invoked later
    doNothing().when(cqs).createSysMutexTableIfNotExists(any(HBaseAdmin.class), any(ReadOnlyProps.class));
    // Spoof out this call so that ensureSystemTablesUpgrade() will return-fast.
    when(cqs.getSystemTableNamesInDefaultNamespace(any(HBaseAdmin.class))).thenReturn(Collections.<TableName>emptyList());
    // Throw a special exception to check on later
    doThrow(PHOENIX_IO_EXCEPTION).when(cqs).ensureNamespaceCreated(anyString());
    // Make sure that ensureSystemTablesMigratedToSystemNamespace will try to migrate the system tables.
    Map<String, String> props = new HashMap<>();
    props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
    cqs.ensureSystemTablesMigratedToSystemNamespace(new ReadOnlyProps(props));
    // Should be called after upgradeSystemTables()
    // Proves that execution proceeded
    verify(cqs).getSystemTableNamesInDefaultNamespace(any(HBaseAdmin.class));
    try {
        // Verifies that the exception is propagated back to the caller
        cqs.createSchema(Collections.<Mutation>emptyList(), "");
    } catch (PhoenixIOException e) {
        assertEquals(PHOENIX_IO_EXCEPTION, e);
    }
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) PhoenixIOException(org.apache.phoenix.exception.PhoenixIOException) HashMap(java.util.HashMap) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ReadOnlyProps (org.apache.phoenix.util.ReadOnlyProps)72 BeforeClass (org.junit.BeforeClass)43 Test (org.junit.Test)14 IOException (java.io.IOException)6 Properties (java.util.Properties)6 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)6 ResultSet (java.sql.ResultSet)5 Configuration (org.apache.hadoop.conf.Configuration)5 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)4 Connection (java.sql.Connection)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)3 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)3 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)3 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)3 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)3