Search in sources :

Example 1 with WriteEventInfo

use of org.apache.hadoop.hive.metastore.api.WriteEventInfo in project hive by apache.

the class CommitTxnHandler method handle.

@Override
public void handle(Context withinContext) throws Exception {
    if (!ReplUtils.includeAcidTableInDump(withinContext.hiveConf)) {
        return;
    }
    LOG.info("Processing#{} COMMIT_TXN message : {}", fromEventId(), eventMessageAsJSON);
    String payload = eventMessageAsJSON;
    if (!withinContext.hiveConf.getBoolVar(HiveConf.ConfVars.REPL_DUMP_METADATA_ONLY)) {
        boolean replicatingAcidEvents = true;
        if (withinContext.hiveConf.getBoolVar(HiveConf.ConfVars.REPL_BOOTSTRAP_ACID_TABLES)) {
            // We do not dump ACID table related events when taking a bootstrap dump of ACID tables as
            // part of an incremental dump. So we shouldn't be dumping any changes to ACID table as
            // part of the commit. At the same time we need to dump the commit transaction event so
            // that replication can end a transaction opened when replaying open transaction event.
            LOG.debug("writeEventsInfoList will be removed from commit message because we are " + "bootstrapping acid tables.");
            replicatingAcidEvents = false;
        } else if (!ReplUtils.includeAcidTableInDump(withinContext.hiveConf)) {
            // Similar to the above condition, only for testing purposes, if the config doesn't allow
            // ACID tables to be replicated, we don't dump any changes to the ACID tables as part of
            // commit.
            LOG.debug("writeEventsInfoList will be removed from commit message because we are " + "not dumping acid tables.");
            replicatingAcidEvents = false;
        }
        List<WriteEventInfo> writeEventInfoList = null;
        if (replicatingAcidEvents) {
            writeEventInfoList = getAllWriteEventInfo(withinContext);
        }
        int numEntry = (writeEventInfoList != null ? writeEventInfoList.size() : 0);
        if (numEntry != 0) {
            eventMessage.addWriteEventInfo(writeEventInfoList);
            payload = jsonMessageEncoder.getSerializer().serialize(eventMessage);
            LOG.debug("payload for commit txn event : " + eventMessageAsJSON);
        }
        org.apache.hadoop.hive.ql.metadata.Table qlMdTablePrev = null;
        org.apache.hadoop.hive.ql.metadata.Table qlMdTable = null;
        List<Partition> qlPtns = new ArrayList<>();
        List<List<String>> filesTobeAdded = new ArrayList<>();
        // used during import, so we need not dump the latest table metadata.
        for (int idx = 0; idx < numEntry; idx++) {
            qlMdTable = new org.apache.hadoop.hive.ql.metadata.Table(eventMessage.getTableObj(idx));
            if (qlMdTablePrev == null) {
                qlMdTablePrev = qlMdTable;
            }
            // one dump directory per table
            if (!qlMdTablePrev.getCompleteName().equals(qlMdTable.getCompleteName())) {
                createDumpFileForTable(withinContext, qlMdTablePrev, qlPtns, filesTobeAdded);
                qlPtns = new ArrayList<>();
                filesTobeAdded = new ArrayList<>();
                qlMdTablePrev = qlMdTable;
            }
            if (qlMdTable.isPartitioned() && (null != eventMessage.getPartitionObj(idx))) {
                qlPtns.add(new org.apache.hadoop.hive.ql.metadata.Partition(qlMdTable, eventMessage.getPartitionObj(idx)));
            }
            filesTobeAdded.add(Lists.newArrayList(ReplChangeManager.getListFromSeparatedString(eventMessage.getFiles(idx))));
        }
        // Dump last table in the list
        if (qlMdTablePrev != null) {
            createDumpFileForTable(withinContext, qlMdTablePrev, qlPtns, filesTobeAdded);
        }
    }
    DumpMetaData dmd = withinContext.createDmd(this);
    dmd.setPayload(payload);
    dmd.write();
}
Also used : Partition(org.apache.hadoop.hive.ql.metadata.Partition) DumpMetaData(org.apache.hadoop.hive.ql.parse.repl.load.DumpMetaData) ArrayList(java.util.ArrayList) Table(org.apache.hadoop.hive.ql.metadata.Table) Partition(org.apache.hadoop.hive.ql.metadata.Partition) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with WriteEventInfo

use of org.apache.hadoop.hive.metastore.api.WriteEventInfo in project hive by apache.

the class CommitTxnHandler method getAllWriteEventInfo.

private List<WriteEventInfo> getAllWriteEventInfo(Context withinContext) throws Exception {
    String contextDbName = StringUtils.normalizeIdentifier(withinContext.replScope.getDbName());
    GetAllWriteEventInfoRequest request = new GetAllWriteEventInfoRequest(eventMessage.getTxnId());
    request.setDbName(contextDbName);
    List<WriteEventInfo> writeEventInfoList = withinContext.db.getMSC().getAllWriteEventInfo(request);
    return ((writeEventInfoList == null) ? null : new ArrayList<>(Collections2.filter(writeEventInfoList, writeEventInfo -> {
        assert (writeEventInfo != null);
        // it should be skipped.
        return (ReplUtils.tableIncludedInReplScope(withinContext.replScope, writeEventInfo.getTable()) && ReplUtils.tableIncludedInReplScope(withinContext.oldReplScope, writeEventInfo.getTable()) && !withinContext.getTablesForBootstrap().contains(writeEventInfo.getTable().toLowerCase()));
    })));
}
Also used : LoginException(javax.security.auth.login.LoginException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) DumpMetaData(org.apache.hadoop.hive.ql.parse.repl.load.DumpMetaData) Collections2(com.google.common.collect.Collections2) GetAllWriteEventInfoRequest(org.apache.hadoop.hive.metastore.api.GetAllWriteEventInfoRequest) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) DumpType(org.apache.hadoop.hive.ql.parse.repl.DumpType) StringUtils(org.apache.hadoop.hive.metastore.utils.StringUtils) ArrayList(java.util.ArrayList) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) Lists(com.google.common.collect.Lists) EximUtil(org.apache.hadoop.hive.ql.parse.EximUtil) Path(org.apache.hadoop.fs.Path) ReplChangeManager(org.apache.hadoop.hive.metastore.ReplChangeManager) HiveUtils(org.apache.hadoop.hive.ql.metadata.HiveUtils) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Table(org.apache.hadoop.hive.ql.metadata.Table) IOException(java.io.IOException) HiveFatalException(org.apache.hadoop.hive.ql.metadata.HiveFatalException) File(java.io.File) Partition(org.apache.hadoop.hive.ql.metadata.Partition) List(java.util.List) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) ReplUtils(org.apache.hadoop.hive.ql.exec.repl.util.ReplUtils) CommitTxnMessage(org.apache.hadoop.hive.metastore.messaging.CommitTxnMessage) GetAllWriteEventInfoRequest(org.apache.hadoop.hive.metastore.api.GetAllWriteEventInfoRequest) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) ArrayList(java.util.ArrayList)

Example 3 with WriteEventInfo

use of org.apache.hadoop.hive.metastore.api.WriteEventInfo in project hive by apache.

the class JSONCommitTxnMessage method addWriteEventInfo.

@Override
public void addWriteEventInfo(List<WriteEventInfo> writeEventInfoList) {
    if (this.databases == null) {
        this.databases = Lists.newArrayList();
    }
    if (this.tables == null) {
        this.tables = Lists.newArrayList();
    }
    if (this.writeIds == null) {
        this.writeIds = Lists.newArrayList();
    }
    if (this.tableObjs == null) {
        this.tableObjs = Lists.newArrayList();
    }
    if (this.partitions == null) {
        this.partitions = Lists.newArrayList();
    }
    if (this.partitionObjs == null) {
        this.partitionObjs = Lists.newArrayList();
    }
    if (this.files == null) {
        this.files = Lists.newArrayList();
    }
    for (WriteEventInfo writeEventInfo : writeEventInfoList) {
        this.databases.add(writeEventInfo.getDatabase());
        this.tables.add(writeEventInfo.getTable());
        this.writeIds.add(writeEventInfo.getWriteId());
        this.partitions.add(writeEventInfo.getPartition());
        this.tableObjs.add(writeEventInfo.getTableObj());
        this.partitionObjs.add(writeEventInfo.getPartitionObj());
        this.files.add(writeEventInfo.getFiles());
    }
}
Also used : WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo)

Example 4 with WriteEventInfo

use of org.apache.hadoop.hive.metastore.api.WriteEventInfo in project hive by apache.

the class TestGetAllWriteEventInfo method testGetByWrongTable.

@Test
public void testGetByWrongTable() throws Exception {
    GetAllWriteEventInfoRequest req = new GetAllWriteEventInfoRequest();
    req.setTxnId(TXN_ID);
    req.setDbName(DB_NAME);
    req.setTableName("wrong_table");
    List<WriteEventInfo> writeEventInfoList = client.getAllWriteEventInfo(req);
    Assert.assertTrue(writeEventInfoList.isEmpty());
}
Also used : GetAllWriteEventInfoRequest(org.apache.hadoop.hive.metastore.api.GetAllWriteEventInfoRequest) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 5 with WriteEventInfo

use of org.apache.hadoop.hive.metastore.api.WriteEventInfo in project hive by apache.

the class TestGetAllWriteEventInfo method testGetByTxnId.

@Test
public void testGetByTxnId() throws Exception {
    GetAllWriteEventInfoRequest req = new GetAllWriteEventInfoRequest();
    req.setTxnId(TXN_ID);
    List<WriteEventInfo> writeEventInfoList = client.getAllWriteEventInfo(req);
    Assert.assertEquals(1, writeEventInfoList.size());
    WriteEventInfo writeEventInfo = writeEventInfoList.get(0);
    Assert.assertEquals(TXN_ID, writeEventInfo.getWriteId());
    Assert.assertEquals(DB_NAME, writeEventInfo.getDatabase());
    Assert.assertEquals(TABLE_NAME, writeEventInfo.getTable());
}
Also used : GetAllWriteEventInfoRequest(org.apache.hadoop.hive.metastore.api.GetAllWriteEventInfoRequest) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

WriteEventInfo (org.apache.hadoop.hive.metastore.api.WriteEventInfo)11 GetAllWriteEventInfoRequest (org.apache.hadoop.hive.metastore.api.GetAllWriteEventInfoRequest)6 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Path (org.apache.hadoop.fs.Path)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 CommitTxnMessage (org.apache.hadoop.hive.metastore.messaging.CommitTxnMessage)2 Partition (org.apache.hadoop.hive.ql.metadata.Partition)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 DumpMetaData (org.apache.hadoop.hive.ql.parse.repl.load.DumpMetaData)2 Collections2 (com.google.common.collect.Collections2)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1