Search in sources :

Example 1 with DropDatabaseMessage

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);
}
Also used : DropDatabaseDesc(org.apache.hadoop.hive.ql.plan.DropDatabaseDesc) DropDatabaseMessage(org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) HashSet(java.util.HashSet)

Example 2 with DropDatabaseMessage

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());
}
Also used : NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) DropDatabaseMessage(org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage) Database(org.apache.hadoop.hive.metastore.api.Database) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Test(org.junit.Test)

Aggregations

DropDatabaseMessage (org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage)2 HashSet (java.util.HashSet)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 NotificationEventResponse (org.apache.hadoop.hive.metastore.api.NotificationEventResponse)1 DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)1 DropDatabaseDesc (org.apache.hadoop.hive.ql.plan.DropDatabaseDesc)1 Test (org.junit.Test)1