Search in sources :

Example 1 with AllocWriteIdMessage

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

the class DbNotificationListener method onAllocWriteId.

/**
 * @param allocWriteIdEvent Alloc write id event
 * @throws MetaException
 */
@Override
public void onAllocWriteId(AllocWriteIdEvent allocWriteIdEvent, Connection dbConn, SQLGenerator sqlGenerator) throws MetaException {
    String tableName = allocWriteIdEvent.getTableName();
    String dbName = allocWriteIdEvent.getDbName();
    AllocWriteIdMessage msg = MessageBuilder.getInstance().buildAllocWriteIdMessage(allocWriteIdEvent.getTxnToWriteIdList(), dbName, tableName);
    NotificationEvent event = new NotificationEvent(0, now(), EventType.ALLOC_WRITE_ID.toString(), msgEncoder.getSerializer().serialize(msg));
    event.setTableName(tableName);
    event.setDbName(dbName);
    try {
        addNotificationLog(event, allocWriteIdEvent, dbConn, sqlGenerator);
    } catch (SQLException e) {
        throw new MetaException("Unable to execute direct SQL " + StringUtils.stringifyException(e));
    }
}
Also used : SQLException(java.sql.SQLException) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) AllocWriteIdMessage(org.apache.hadoop.hive.metastore.messaging.AllocWriteIdMessage) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with AllocWriteIdMessage

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

the class AllocWriteIdHandler method handle.

@Override
public List<Task<?>> handle(Context context) throws SemanticException {
    if (!AcidUtils.isAcidEnabled(context.hiveConf)) {
        context.log.error("Cannot load alloc write id event as acid is not enabled");
        throw new SemanticException("Cannot load alloc write id event as acid is not enabled");
    }
    AllocWriteIdMessage msg = deserializer.getAllocWriteIdMessage(context.dmd.getPayload());
    String dbName = (context.dbName != null && !context.dbName.isEmpty() ? context.dbName : msg.getDB());
    // We need table name for alloc write id and that is received from source.
    String tableName = msg.getTableName();
    // Repl policy should be created based on the table name in context.
    ReplTxnWork work = new ReplTxnWork(HiveUtils.getReplPolicy(context.dbName), dbName, tableName, ReplTxnWork.OperationType.REPL_ALLOC_WRITE_ID, msg.getTxnToWriteIdList(), context.eventOnlyReplicationSpec(), context.getDumpDirectory(), context.getMetricCollector());
    Task<?> allocWriteIdTask = TaskFactory.get(work, context.hiveConf);
    context.log.info("Added alloc write id task : {}", allocWriteIdTask.getId());
    updatedMetadata.set(context.dmd.getEventTo().toString(), dbName, tableName, null);
    return Collections.singletonList(allocWriteIdTask);
}
Also used : ReplTxnWork(org.apache.hadoop.hive.ql.plan.ReplTxnWork) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) AllocWriteIdMessage(org.apache.hadoop.hive.metastore.messaging.AllocWriteIdMessage)

Aggregations

AllocWriteIdMessage (org.apache.hadoop.hive.metastore.messaging.AllocWriteIdMessage)2 SQLException (java.sql.SQLException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 ReplTxnWork (org.apache.hadoop.hive.ql.plan.ReplTxnWork)1