use of org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage in project hive by apache.
the class DropDatabaseHandler method handle.
@Override
public List<Task<? extends Serializable>> handle(Context context) throws SemanticException {
DropDatabaseMessage msg = deserializer.getDropDatabaseMessage(context.dmd.getPayload());
String actualDbName = context.isDbNameEmpty() ? msg.getDB() : context.dbName;
DropDatabaseDesc desc = new DropDatabaseDesc(actualDbName, true, context.eventOnlyReplicationSpec());
Task<? extends Serializable> dropDBTask = TaskFactory.get(new DDLWork(new HashSet<>(), new HashSet<>(), desc));
context.log.info("Added drop database task : {}:{}", dropDBTask.getId(), desc.getDatabaseName());
updatedMetadata.set(context.dmd.getEventTo().toString(), actualDbName, null, null);
return Collections.singletonList(dropDBTask);
}
use of org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage in project hive by apache.
the class TestDbNotificationListener method dropDatabase.
@Test
public void dropDatabase() throws Exception {
String dbName = "dropdb";
String dbName2 = "dropdb2";
String dbLocationUri = "file:/tmp";
String dbDescription = "no description";
Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
msClient.dropDatabase(dbName);
// Read notification from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
// Two events: one for create db and other for drop db
assertEquals(2, rsp.getEventsSize());
// Read event from notification
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_DATABASE.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
assertNull(event.getTableName());
// Parse the message field
DropDatabaseMessage dropDbMsg = md.getDropDatabaseMessage(event.getMessage());
assertEquals(dbName, dropDbMsg.getDB());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.DROP_DATABASE, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_DATABASE, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.dropDatabase(dbName2);
fail("Error: drop database should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
}
Aggregations