use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method dropTable.
@Test
public void dropTable() throws Exception {
String defaultDbName = "default";
String tblName = "droptbl";
String tblName2 = "droptbl2";
String tblOwner = "me";
String serdeLocation = testTempDir;
FieldSchema col1 = new FieldSchema("col1", "int", "no comment");
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(col1);
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
StorageDescriptor sd = new StorageDescriptor(cols, serdeLocation, "input", "output", false, 0, serde, null, null, emptyParameters);
Table table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
// Event 2
msClient.dropTable(defaultDbName, tblName);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(2, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_TABLE.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
DropTableMessage dropTblMsg = md.getDropTableMessage(event.getMessage());
assertEquals(defaultDbName, dropTblMsg.getDB());
assertEquals(tblName, dropTblMsg.getTable());
assertEquals(TableType.MANAGED_TABLE.toString(), dropTblMsg.getTableType());
Table tableObj = dropTblMsg.getTableObj();
assertEquals(table.getDbName(), tableObj.getDbName());
assertEquals(table.getTableName(), tableObj.getTableName());
assertEquals(table.getOwner(), tableObj.getOwner());
assertEquals(table.getParameters(), tableObj.getParameters());
assertEquals(TableType.MANAGED_TABLE.toString(), tableObj.getTableType());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.DROP_TABLE, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
table = new Table(tblName2, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
msClient.createTable(table);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.dropTable(defaultDbName, tblName2);
fail("Error: drop table should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
testEventCounts(defaultDbName, firstEventId, null, null, 3);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method verifyInsertEventReceived.
private void verifyInsertEventReceived(String defaultDbName, String tblName, List<List<String>> partKeyVals, FireEventRequest rqst, long expectedStartEventId, int expectedNumOfEvents) throws Exception {
FireEventResponse response = msClient.fireListenerEvent(rqst);
assertTrue("Event id must be set in the fireEvent response", response.isSetEventIds());
Assert.assertNotNull(response.getEventIds());
Assert.assertTrue(response.getEventIds().size() == expectedNumOfEvents);
for (int i = 0; i < expectedNumOfEvents; i++) {
Assert.assertEquals(expectedStartEventId + i, response.getEventIds().get(i).longValue());
}
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(expectedStartEventId - 1, 0, null);
assertEquals(expectedNumOfEvents, rsp.getEventsSize());
for (int i = 0; i < expectedNumOfEvents; i++) {
NotificationEvent event = rsp.getEvents().get(i);
assertEquals(expectedStartEventId + i, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.INSERT.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
verifyInsert(event, defaultDbName, tblName);
InsertMessage insertMessage = md.getInsertMessage(event.getMessage());
List<String> ptnValues = insertMessage.getPtnObj().getValues();
assertFalse(insertMessage.isReplace());
assertEquals(partKeyVals.get(i), ptnValues);
}
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method rollbackTxn.
@Test
public void rollbackTxn() throws Exception {
long txnId1 = msClient.openTxn("me", TxnType.READ_ONLY);
long txnId2 = msClient.openTxn("me", TxnType.DEFAULT);
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
msClient.rollbackTxn(txnId1);
rsp = msClient.getNextNotification(firstEventId + 1, 0, null);
assertEquals(0, rsp.getEventsSize());
msClient.rollbackTxn(txnId2);
rsp = msClient.getNextNotification(firstEventId + 1, 0, null);
assertEquals(1, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.ABORT_TXN.toString(), event.getEventType());
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class ObjectStore method getNextNotification.
@Override
public NotificationEventResponse getNextNotification(NotificationEventRequest rqst) {
boolean commited = false;
Query query = null;
NotificationEventResponse result = new NotificationEventResponse();
result.setEvents(new ArrayList<>());
try {
openTransaction();
long lastEvent = rqst.getLastEvent();
List<Object> parameterVals = new ArrayList<>();
parameterVals.add(lastEvent);
StringBuilder filterBuilder = new StringBuilder("eventId > para" + parameterVals.size());
StringBuilder parameterBuilder = new StringBuilder("java.lang.Long para" + parameterVals.size());
if (rqst.isSetEventTypeSkipList()) {
for (String eventType : rqst.getEventTypeSkipList()) {
parameterVals.add(eventType);
parameterBuilder.append(", java.lang.String para" + parameterVals.size());
filterBuilder.append(" && eventType != para" + parameterVals.size());
}
}
query = pm.newQuery(MNotificationLog.class, filterBuilder.toString());
query.declareParameters(parameterBuilder.toString());
query.setOrdering("eventId ascending");
int maxEventResponse = MetastoreConf.getIntVar(conf, ConfVars.METASTORE_MAX_EVENT_RESPONSE);
int maxEvents = (rqst.getMaxEvents() < maxEventResponse && rqst.getMaxEvents() > 0) ? rqst.getMaxEvents() : maxEventResponse;
query.setRange(0, maxEvents);
Collection<MNotificationLog> events = (Collection) query.executeWithArray(parameterVals.toArray(new Object[0]));
commited = commitTransaction();
if (events == null) {
return result;
}
Iterator<MNotificationLog> i = events.iterator();
while (i.hasNext()) {
result.addToEvents(translateDbToThrift(i.next()));
}
return result;
} finally {
rollbackAndCleanup(commited, query);
}
}
Aggregations