MetaStoreListenerNotifier.notifyEvent(transactionalListeners, EventType.ALTER_TABLE, new AlterTableEvent(table, table, true, true, writeId, this)); MetaStoreListenerNotifier.notifyEvent(listeners, EventType.ALTER_TABLE, new AlterTableEvent(table, table, true, true, writeId, this));
@Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { if (!TxnUtils.isTransactionalTable(tableEvent.getNewTable())) { return; } Table oldTable = tableEvent.getOldTable(); Table newTable = tableEvent.getNewTable(); if(!oldTable.getCatName().equalsIgnoreCase(newTable.getCatName()) || !oldTable.getDbName().equalsIgnoreCase(newTable.getDbName()) || !oldTable.getTableName().equalsIgnoreCase(newTable.getTableName())) { txnHandler = getTxnHandler(); txnHandler.onRename( oldTable.getCatName(), oldTable.getDbName(), oldTable.getTableName(), null, newTable.getCatName(), newTable.getDbName(), newTable.getTableName(), null); } } @Override
/** * Send altered table notifications. Subscribers can receive these notifications for * dropped tables by listening on topic "HCAT" with message selector string * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_EVENT} = * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_ALTER_TABLE_EVENT} */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { if (tableEvent.getStatus()) { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); // onCreateTable alters the table to add the topic name. Since this class is generating // that alter, we don't want to notify on that alter. So take a quick look and see if // that's what this this alter is, and if so swallow it. if (after.getParameters() != null && after.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) != null && (before.getParameters() == null || before.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) == null)) { return; } // I think this is wrong, the alter table statement should come on the table topic not the // DB topic - Alan. String topicName = getTopicPrefix(tableEvent.getIHMSHandler().getConf()) + "." + after.getDbName().toLowerCase(); send(messageFactory.buildAlterTableMessage(before, after, tableEvent.getWriteId()), topicName); } }
/** * @param tableEvent alter table event * @throws MetaException */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); AlterTableMessage msg = MessageBuilder.getInstance() .buildAlterTableMessage(before, after, tableEvent.getIsTruncateOp(), tableEvent.getWriteId()); NotificationEvent event = new NotificationEvent(0, now(), EventType.ALTER_TABLE.toString(), msgEncoder.getSerializer().serialize(msg) ); event.setCatName(after.isSetCatName() ? after.getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(after.getDbName()); event.setTableName(after.getTableName()); process(event, tableEvent); }
/** * Send altered table notifications. Subscribers can receive these notifications for * dropped tables by listening on topic "HCAT" with message selector string * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_EVENT} = * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_ALTER_TABLE_EVENT} */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { if (tableEvent.getStatus()) { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); // onCreateTable alters the table to add the topic name. Since this class is generating // that alter, we don't want to notify on that alter. So take a quick look and see if // that's what this this alter is, and if so swallow it. if (after.getParameters() != null && after.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) != null && (before.getParameters() == null || before.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) == null)) { return; } // I think this is wrong, the alter table statement should come on the table topic not the // DB topic - Alan. String topicName = getTopicPrefix(tableEvent.getHandler().getHiveConf()) + "." + after.getDbName().toLowerCase(); send(messageFactory.buildAlterTableMessage(before, after), topicName); } }
Assert.assertTrue(alterTableE.getStatus()); validateAlterTable(tbl, renamedTable, alterTableE.getOldTable(), alterTableE.getNewTable()); validateAlterTable(tbl, renamedTable, preAlterTableE.getOldTable(), preAlterTableE.getNewTable()); Assert.assertTrue(alterTableE.getStatus()); validateAlterTableColumns(tbl, altTable, alterTableE.getOldTable(), alterTableE.getNewTable()); validateAlterTableColumns(tbl, altTable, preAlterTableE.getOldTable(), preAlterTableE.getNewTable());
new AlterTableEvent(oldt, newTable, success, this); alterTableEvent.setEnvironmentContext(envContext); listener.onAlterTable(alterTableEvent);
/** * @param tableEvent alter table event * @throws MetaException */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); NotificationEvent event = new NotificationEvent(0, now(), EventType.ALTER_TABLE.toString(), msgFactory .buildAlterTableMessage(before, after, tableEvent.getIsTruncateOp()).toString()); event.setCatName(after.isSetCatName() ? after.getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(after.getDbName()); event.setTableName(after.getTableName()); process(event, tableEvent); }
assertEquals(notifyList.size(), listSize); AlterTableEvent alterTableEvent = (AlterTableEvent) notifyList.get(listSize-1); assert alterTableEvent.getStatus(); assertEquals(envContext, alterTableEvent.getEnvironmentContext());
/** * Send altered table notifications. Subscribers can receive these notifications for * dropped tables by listening on topic "HCAT" with message selector string * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_EVENT} = * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_ALTER_TABLE_EVENT} */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { if (tableEvent.getStatus()) { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); // onCreateTable alters the table to add the topic name. Since this class is generating // that alter, we don't want to notify on that alter. So take a quick look and see if // that's what this this alter is, and if so swallow it. if (after.getParameters() != null && after.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) != null && (before.getParameters() == null || before.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) == null)) { return; } // I think this is wrong, the alter table statement should come on the table topic not the // DB topic - Alan. String topicName = getTopicPrefix(tableEvent.getHandler().getHiveConf()) + "." + after.getDbName().toLowerCase(); send(messageFactory.buildAlterTableMessage(before, after), topicName); } }
/** * Adjust the privileges when table is renamed */ @Override public void onAlterTable (AlterTableEvent tableEvent) throws MetaException { // don't sync privileges if the operation has failed if (!tableEvent.getStatus()) { LOGGER.debug("Skip syncing privileges with Sentry server for onAlterTable event," + " since the operation failed. \n"); return; } renameSentryTablePrivilege(tableEvent.getOldTable().getDbName(), tableEvent.getOldTable().getTableName(), tableEvent.getOldTable().getSd().getLocation(), tableEvent.getNewTable().getDbName(), tableEvent.getNewTable().getTableName(), tableEvent.getNewTable().getSd().getLocation()); }
new AlterTableEvent(oldt, newTable, success, this); alterTableEvent.setEnvironmentContext(envContext); listener.onAlterTable(alterTableEvent);
/** * Listener which fires when a table is altered. * * <p>For auditing purposes the read/write differential is the old and new * table respectively.</p> * * @param event The add partition event */ @Override public void onAlterTable(AlterTableEvent event) throws MetaException { try { Set<ReadEntity> readEntities = new HashSet<>(); readEntities.add(new ReadEntity(new Table(event.getOldTable()))); Set<WriteEntity> writeEntities = new HashSet<>(); writeEntities.add( new WriteEntity( new Table(event.getNewTable()), WriteType.INSERT ) ); run(readEntities, writeEntities, HiveOperation.THRIFT_ALTER_TABLE); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Send altered table notifications. Subscribers can receive these notifications for * dropped tables by listening on topic "HCAT" with message selector string * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_EVENT} = * {@value org.apache.hive.hcatalog.common.HCatConstants#HCAT_ALTER_TABLE_EVENT} */ @Override public void onAlterTable(AlterTableEvent tableEvent) throws MetaException { if (tableEvent.getStatus()) { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); // onCreateTable alters the table to add the topic name. Since this class is generating // that alter, we don't want to notify on that alter. So take a quick look and see if // that's what this this alter is, and if so swallow it. if (after.getParameters() != null && after.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) != null && (before.getParameters() == null || before.getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME) == null)) { return; } // I think this is wrong, the alter table statement should come on the table topic not the // DB topic - Alan. String topicName = getTopicPrefix(tableEvent.getIHMSHandler().getConf()) + "." + after.getDbName().toLowerCase(); send(messageFactory.buildAlterTableMessage(before, after), topicName); } }
txnAlterTableEventResponses = MetaStoreListenerNotifier.notifyEvent(transactionalListeners, EventMessage.EventType.ALTER_TABLE, new AlterTableEvent(oldt, newt, false, true, newt.getWriteId(), handler), environmentContext); new AlterTableEvent(oldt, newt, false, success, newt.getWriteId(), handler), environmentContext, txnAlterTableEventResponses, msdb);
new AlterTableEvent(oldt, newTable, success, this); alterTableEvent.setEnvironmentContext(envContext); listener.onAlterTable(alterTableEvent);
/** * Listener which fires when a table is altered. * * <p>For auditing purposes the read/write differential is the old and new * table respectively.</p> * * @param event The add partition event */ @Override public void onAlterTable(AlterTableEvent event) throws MetaException { try { Set<ReadEntity> readEntities = new HashSet<>(); readEntities.add(new ReadEntity(new Table(event.getOldTable()))); Set<WriteEntity> writeEntities = new HashSet<>(); writeEntities.add( new WriteEntity( new Table(event.getNewTable()), WriteType.INSERT ) ); run(readEntities, writeEntities, HiveOperation.THRIFT_ALTER_TABLE); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Insert a thrift audit log entry that represents renaming a table. * * @param oldTable the source table * @param newTable the table renamed to * @param hiveConf Hive configuration * @throws Exception if there's an error inserting into the audit log */ public static void insertThriftRenameTableLogEntry( org.apache.hadoop.hive.metastore.api.Table oldTable, org.apache.hadoop.hive.metastore.api.Table newTable, HiveConf hiveConf) throws Exception { final MetastoreAuditLogListener metastoreAuditLogListener = new MetastoreAuditLogListener(hiveConf); AlterTableEvent event = new AlterTableEvent( oldTable, newTable, true, null ); metastoreAuditLogListener.onAlterTable(event); }
/** * @param tableEvent alter table event * @throws MetaException */ public void onAlterTable (AlterTableEvent tableEvent) throws MetaException { Table before = tableEvent.getOldTable(); Table after = tableEvent.getNewTable(); NotificationEvent event = new NotificationEvent(0, now(), HCatConstants.HCAT_ALTER_TABLE_EVENT, msgFactory.buildAlterTableMessage(before, after).toString()); event.setDbName(after.getDbName()); event.setTableName(after.getTableName()); enqueue(event); }
/** * Insert a thrift audit log entry that represents renaming a table. * * @param oldTable the source table * @param newTable the table renamed to * @param hiveConf Hive configuration * @throws Exception if there's an error inserting into the audit log */ public static void insertThriftRenameTableLogEntry( org.apache.hadoop.hive.metastore.api.Table oldTable, org.apache.hadoop.hive.metastore.api.Table newTable, HiveConf hiveConf) throws Exception { final MetastoreAuditLogListener metastoreAuditLogListener = new MetastoreAuditLogListener(hiveConf); AlterTableEvent event = new AlterTableEvent( oldTable, newTable, true, null ); metastoreAuditLogListener.onAlterTable(event); }