commit 9835ff18c24cf5a838bd3e5558cb3b91d053dcb7 Author: Bharath Krishna Date: Wed Mar 27 11:12:50 2019 -0700 HIVE-21526 : JSONDropDatabaseMessage needs to have the full database object. diff --git itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index a2f9f3f0a6ac474b8e84e4bad4c839974a7d234f..7180564812cd37b8783038a167ee645d65303cac 100644 --- itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -406,8 +406,11 @@ public void dropDatabase() throws Exception { String dbName2 = "dropdb2"; String dbLocationUri = testTempDir; String dbDescription = "no description"; - Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); - msClient.createDatabase(db); + msClient.createDatabase(new Database(dbName, dbDescription, dbLocationUri, emptyParameters)); + + // Get the DB for comparison below since it may include additional parameters + Database db = msClient.getDatabase(dbName); + // Drop the database msClient.dropDatabase(dbName); // Read notification from metastore @@ -428,6 +431,7 @@ public void dropDatabase() throws Exception { // Parse the message field DropDatabaseMessage dropDbMsg = md.getDropDatabaseMessage(event.getMessage()); assertEquals(dbName, dropDbMsg.getDB()); + assertEquals(db, dropDbMsg.getDatabaseObject()); // Verify the eventID was passed to the non-transactional listener MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.DROP_DATABASE, firstEventId + 2); @@ -435,8 +439,7 @@ public void dropDatabase() throws Exception { // 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); + msClient.createDatabase(new Database(dbName2, dbDescription, dbLocationUri, emptyParameters)); DummyRawStoreFailEvent.setEventSucceed(false); try { msClient.dropDatabase(dbName2); diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java index a450d476998430d0671356e0eab5945dd7423bfb..f8a567da8f7e39539b46d24c3ec049c752ef76d9 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java @@ -19,9 +19,13 @@ package org.apache.hadoop.hive.metastore.messaging; +import org.apache.hadoop.hive.metastore.api.Database; + public abstract class DropDatabaseMessage extends EventMessage { protected DropDatabaseMessage() { super(EventType.DROP_DATABASE); } + + public abstract Database getDatabaseObject() throws Exception; } diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java index 15c4769e337148635ee2893feffd1e0bbdfd1e13..aa83da4ed52ae60592a006ba3872096a6882a870 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java @@ -175,7 +175,7 @@ public AlterDatabaseMessage buildAlterDatabaseMessage(Database beforeDb, Databas } public DropDatabaseMessage buildDropDatabaseMessage(Database db) { - return new JSONDropDatabaseMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, db.getName(), now()); + return new JSONDropDatabaseMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, db, now()); } public CreateTableMessage buildCreateTableMessage(Table table, Iterator fileIter) { diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java index d2a75bf6a89ccaa212a14107b5cdbb4afd5457af..ae791610ae563f321a8d03254dec1e51a3cc3282 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java @@ -19,9 +19,12 @@ package org.apache.hadoop.hive.metastore.messaging.json; +import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hive.metastore.messaging.MessageBuilder; +import org.apache.thrift.TException; /** * JSON implementation of DropDatabaseMessage. @@ -29,7 +32,7 @@ public class JSONDropDatabaseMessage extends DropDatabaseMessage { @JsonProperty - String server, servicePrincipal, db; + String server, servicePrincipal, db, dbJson; @JsonProperty Long timestamp; @@ -39,11 +42,16 @@ */ public JSONDropDatabaseMessage() {} - public JSONDropDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp) { + public JSONDropDatabaseMessage(String server, String servicePrincipal, Database db, Long timestamp) { this.server = server; this.servicePrincipal = servicePrincipal; - this.db = db; + this.db = db.getName(); this.timestamp = timestamp; + try { + this.dbJson = MessageBuilder.createDatabaseObjJson(db); + } catch (TException ex) { + throw new IllegalArgumentException("Could not serialize database object", ex); + } checkValid(); } @@ -60,6 +68,11 @@ public JSONDropDatabaseMessage(String server, String servicePrincipal, String db @Override public Long getTimestamp() { return timestamp; } + @Override + public Database getDatabaseObject() throws Exception { + return (Database) MessageBuilder.getTObj(dbJson, Database.class); + } + @Override public String toString() { try {