Search in sources :

Example 1 with HiveSchemaFactory

use of org.apache.drill.exec.store.hive.schema.HiveSchemaFactory in project drill by apache.

the class HiveStoragePlugin method registerSchemas.

// Forced to synchronize this method to allow error recovery
// in the multi-threaded case. Can remove synchronized only
// by restructuring connections and cache to allow better
// recovery from failed secure connections.
@Override
public synchronized void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    try {
        schemaFactory.registerSchemas(schemaConfig, parent);
        return;
    // Hack. We may need to retry the connection. But, we can't because
    // the retry logic is implemented in the very connection we need to
    // discard and rebuild. To work around, we discard the entire schema
    // factory, and all its invalid connections. Very crude, but the
    // easiest short-term solution until we refactor the code to do the
    // job properly. See DRILL-5510.
    } catch (Throwable e) {
        // Unwrap exception
        Throwable ex = e;
        for (; ; ) {
            // Case for failing on an invalid cached connection
            if (ex instanceof MetaException || // tokens.
            ex instanceof TTransportException) {
                break;
            }
            if (ex.getCause() == null || ex.getCause() == ex) {
                logger.error("Hive metastore register schemas failed", e);
                throw new DrillRuntimeException("Unknown Hive error", e);
            }
            ex = ex.getCause();
        }
    }
    try {
        schemaFactory.close();
    } catch (Throwable t) {
        // Ignore, we're in a bad state.
        logger.warn("Schema factory forced close failed, error ignored", t);
    }
    try {
        schemaFactory = new HiveSchemaFactory(this, name, hiveConf);
    } catch (ExecutionSetupException e) {
        throw new DrillRuntimeException(e);
    }
    // Try the schemas again. If this fails, just give up.
    schemaFactory.registerSchemas(schemaConfig, parent);
    logger.debug("Successfully recovered from a Hive metastore connection failure.");
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) TTransportException(org.apache.thrift.transport.TTransportException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) HiveSchemaFactory(org.apache.drill.exec.store.hive.schema.HiveSchemaFactory) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 HiveSchemaFactory (org.apache.drill.exec.store.hive.schema.HiveSchemaFactory)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 TTransportException (org.apache.thrift.transport.TTransportException)1