Search in sources :

Example 1 with EventMessage

use of org.apache.hadoop.hive.metastore.messaging.EventMessage in project hive by apache.

the class DbNotificationListener method onAddPartition.

/**
 * @param partitionEvent partition event
 * @throws MetaException
 */
@Override
public void onAddPartition(AddPartitionEvent partitionEvent) throws MetaException {
    Table t = partitionEvent.getTable();
    PartitionFilesIterator fileIter = MetaStoreUtils.isExternalTable(t) ? null : new PartitionFilesIterator(partitionEvent.getPartitionIterator(), t);
    EventMessage msg = MessageBuilder.getInstance().buildAddPartitionMessage(t, partitionEvent.getPartitionIterator(), fileIter);
    MessageSerializer serializer = msgEncoder.getSerializer();
    NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_PARTITION.toString(), serializer.serialize(msg));
    event.setCatName(t.isSetCatName() ? t.getCatName() : DEFAULT_CATALOG_NAME);
    event.setDbName(t.getDbName());
    event.setTableName(t.getTableName());
    process(event, partitionEvent);
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) EventMessage(org.apache.hadoop.hive.metastore.messaging.EventMessage) MessageSerializer(org.apache.hadoop.hive.metastore.messaging.MessageSerializer) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 2 with EventMessage

use of org.apache.hadoop.hive.metastore.messaging.EventMessage in project hive by apache.

the class AddPartitionHandler method handle.

@Override
public void handle(Context withinContext) throws Exception {
    LOG.info("Processing#{} ADD_PARTITION message : {}", fromEventId(), eventMessageAsJSON);
    // dump partition related events for metadata-only dump.
    if (withinContext.hiveConf.getBoolVar(HiveConf.ConfVars.REPL_DUMP_METADATA_ONLY)) {
        return;
    }
    AddPartitionMessage apm = (AddPartitionMessage) eventMessage;
    org.apache.hadoop.hive.metastore.api.Table tobj = apm.getTableObj();
    if (tobj == null) {
        LOG.debug("Event#{} was a ADD_PTN_EVENT with no table listed", fromEventId());
        return;
    }
    final Table qlMdTable = new Table(tobj);
    if (!Utils.shouldReplicate(withinContext.replicationSpec, qlMdTable, true, withinContext.getTablesForBootstrap(), withinContext.oldReplScope, withinContext.hiveConf)) {
        return;
    }
    Iterable<org.apache.hadoop.hive.metastore.api.Partition> ptns = apm.getPartitionObjs();
    if ((ptns == null) || (!ptns.iterator().hasNext())) {
        LOG.debug("Event#{} was an ADD_PTN_EVENT with no partitions", fromEventId());
        return;
    }
    Iterable<Partition> qlPtns = StreamSupport.stream(ptns.spliterator(), true).map(input -> {
        if (input == null) {
            return null;
        }
        try {
            return new Partition(qlMdTable, input);
        } catch (HiveException e) {
            throw new IllegalArgumentException(e);
        }
    }).collect(Collectors.toList());
    Path metaDataPath = new Path(withinContext.eventRoot, EximUtil.METADATA_NAME);
    EximUtil.createExportDump(metaDataPath.getFileSystem(withinContext.hiveConf), metaDataPath, qlMdTable, qlPtns, withinContext.replicationSpec, withinContext.hiveConf);
    boolean copyAtLoad = withinContext.hiveConf.getBoolVar(HiveConf.ConfVars.REPL_RUN_DATA_COPY_TASKS_ON_TARGET);
    Iterator<PartitionFiles> partitionFilesIter = apm.getPartitionFilesIter().iterator();
    // list would be empty. So, it is enough to check hasNext outside the loop.
    if (partitionFilesIter.hasNext()) {
        for (Partition qlPtn : qlPtns) {
            Iterable<String> files = partitionFilesIter.next().getFiles();
            if (files != null) {
                if (copyAtLoad) {
                    // encoded filename/checksum of files, write into _files
                    Path ptnDataPath = new Path(withinContext.eventRoot, EximUtil.DATA_PATH_NAME + File.separator + qlPtn.getName());
                    writeEncodedDumpFiles(withinContext, files, ptnDataPath);
                } else {
                    for (String file : files) {
                        writeFileEntry(qlMdTable, qlPtn, file, withinContext);
                    }
                }
            }
        }
    }
    withinContext.createDmd(this).write();
}
Also used : Iterator(java.util.Iterator) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Table(org.apache.hadoop.hive.ql.metadata.Table) DumpType(org.apache.hadoop.hive.ql.parse.repl.DumpType) Collectors(java.util.stream.Collectors) File(java.io.File) PartitionFiles(org.apache.hadoop.hive.metastore.messaging.PartitionFiles) Partition(org.apache.hadoop.hive.ql.metadata.Partition) EventMessage(org.apache.hadoop.hive.metastore.messaging.EventMessage) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) EximUtil(org.apache.hadoop.hive.ql.parse.EximUtil) Path(org.apache.hadoop.fs.Path) Utils(org.apache.hadoop.hive.ql.parse.repl.dump.Utils) StreamSupport(java.util.stream.StreamSupport) AddPartitionMessage(org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) Path(org.apache.hadoop.fs.Path) Partition(org.apache.hadoop.hive.ql.metadata.Partition) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) PartitionFiles(org.apache.hadoop.hive.metastore.messaging.PartitionFiles) AddPartitionMessage(org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage)

Aggregations

NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)2 EventMessage (org.apache.hadoop.hive.metastore.messaging.EventMessage)2 File (java.io.File)1 Iterator (java.util.Iterator)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 Path (org.apache.hadoop.fs.Path)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 AddPartitionMessage (org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage)1 MessageSerializer (org.apache.hadoop.hive.metastore.messaging.MessageSerializer)1 PartitionFiles (org.apache.hadoop.hive.metastore.messaging.PartitionFiles)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 Partition (org.apache.hadoop.hive.ql.metadata.Partition)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1 EximUtil (org.apache.hadoop.hive.ql.parse.EximUtil)1 DumpType (org.apache.hadoop.hive.ql.parse.repl.DumpType)1 Utils (org.apache.hadoop.hive.ql.parse.repl.dump.Utils)1