Search in sources :

Example 1 with IMetaStoreSchemaInfo

use of org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo in project hive by apache.

the class TestSchemaToolForMetastore method testSchemaInit.

/**
 * Test schema initialization
 */
@Test
public void testSchemaInit() throws Exception {
    IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, System.getProperty("test.tmp.dir", "target/tmp"), "derby");
    schemaTool.doInit(metastoreSchemaInfo.getHiveSchemaVersion());
    schemaTool.verifySchemaVersion();
}
Also used : IMetaStoreSchemaInfo(org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 2 with IMetaStoreSchemaInfo

use of org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo in project hive by apache.

the class TestTxnDbUtil method prepDb.

/**
 * Prepares the metastore database for unit tests.
 * Runs the latest init schema against the database configured in the CONNECT_URL_KEY param.
 * Ignores any duplication (table, index etc.) So it can be called multiple times for the same database.
 * @param conf Metastore configuration
 * @throws Exception Initialization failure
 */
public static synchronized void prepDb(Configuration conf) throws Exception {
    LOG.info("Creating transactional tables");
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = getConnection(conf);
        String s = conn.getMetaData().getDatabaseProductName();
        DatabaseProduct dbProduct = determineDatabaseProduct(s, conf);
        stmt = conn.createStatement();
        if (checkDbPrepared(stmt)) {
            return;
        }
        String schemaRootPath = getSchemaRootPath();
        IMetaStoreSchemaInfo metaStoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, schemaRootPath, dbProduct.getHiveSchemaPostfix());
        String initFile = metaStoreSchemaInfo.generateInitFileName(null);
        try (InputStream is = new FileInputStream(metaStoreSchemaInfo.getMetaStoreScriptDir() + File.separator + initFile)) {
            LOG.info("Reinitializing the metastore db with {} on the database {}", initFile, MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY));
            importSQL(stmt, is);
        }
    } catch (SQLException e) {
        try {
            if (conn != null) {
                conn.rollback();
            }
        } catch (SQLException re) {
            LOG.error("Error rolling back: " + re.getMessage());
        }
        // This might be a deadlock, if so, let's retry
        if (e instanceof SQLTransactionRollbackException && deadlockCnt++ < 5) {
            LOG.warn("Caught deadlock, retrying db creation");
            prepDb(conf);
        } else {
            throw e;
        }
    } finally {
        deadlockCnt = 0;
        closeResources(conn, stmt, null);
    }
}
Also used : SQLTransactionRollbackException(java.sql.SQLTransactionRollbackException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) IMetaStoreSchemaInfo(org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo) FileInputStream(java.io.FileInputStream) DatabaseProduct(org.apache.hadoop.hive.metastore.DatabaseProduct) DatabaseProduct.determineDatabaseProduct(org.apache.hadoop.hive.metastore.DatabaseProduct.determineDatabaseProduct)

Example 3 with IMetaStoreSchemaInfo

use of org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo in project hive by apache.

the class TestSchemaTool method testSchemaInit.

/**
 * Test schema initialization
 * @throws Exception
 */
public void testSchemaInit() throws Exception {
    IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(hiveConf, System.getProperty("test.tmp.dir", "target/tmp"), "derby");
    schemaTool.doInit(metastoreSchemaInfo.getHiveSchemaVersion());
    schemaTool.verifySchemaVersion();
}
Also used : IMetaStoreSchemaInfo(org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo)

Example 4 with IMetaStoreSchemaInfo

use of org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo in project hive by apache.

the class TestSchemaToolForMetastore method testSchemaInit.

/**
 * Test schema initialization
 */
@Test
public void testSchemaInit() throws Exception {
    IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, System.getProperty("test.tmp.dir", "target/tmp"), "derby");
    execute(new SchemaToolTaskInit(), "-initSchemaTo " + metastoreSchemaInfo.getHiveSchemaVersion());
    schemaTool.verifySchemaVersion();
}
Also used : IMetaStoreSchemaInfo(org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

IMetaStoreSchemaInfo (org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo)4 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SQLTransactionRollbackException (java.sql.SQLTransactionRollbackException)1 Statement (java.sql.Statement)1 DatabaseProduct (org.apache.hadoop.hive.metastore.DatabaseProduct)1 DatabaseProduct.determineDatabaseProduct (org.apache.hadoop.hive.metastore.DatabaseProduct.determineDatabaseProduct)1