This is an automated email from the ASF dual-hosted git repository. bharos92 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hive.git
commit 7af186a6c134e83a4ca3dc705035d635df574b7f Author: Bharath Krishna <bhar...@cloudera.com> AuthorDate: Wed Mar 27 11:12:50 2019 -0700 HIVE-21526 : JSONDropDatabaseMessage needs to have the full database object (Bharath Krishna reviewed by Vihang Karajgaonkar) --- .../hcatalog/listener/TestDbNotificationListener.java | 11 +++++++---- .../hive/metastore/messaging/DropDatabaseMessage.java | 4 ++++ .../hive/metastore/messaging/MessageBuilder.java | 2 +- .../messaging/json/JSONDropDatabaseMessage.java | 19 ++++++++++++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index a2f9f3f..7180564 100644 --- a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -406,8 +406,11 @@ public class TestDbNotificationListener { 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 class TestDbNotificationListener { // 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 class TestDbNotificationListener { // 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 a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java index a450d47..f8a567d 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/DropDatabaseMessage.java +++ b/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 a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java index 15c4769..aa83da4 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java @@ -175,7 +175,7 @@ public class MessageBuilder { } 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<String> fileIter) { diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java index d2a75bf..ae79161 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java +++ b/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 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class JSONDropDatabaseMessage extends DropDatabaseMessage { @JsonProperty - String server, servicePrincipal, db; + String server, servicePrincipal, db, dbJson; @JsonProperty Long timestamp; @@ -39,11 +42,16 @@ public class JSONDropDatabaseMessage extends DropDatabaseMessage { */ 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(); } @@ -61,6 +69,11 @@ public class JSONDropDatabaseMessage extends DropDatabaseMessage { public Long getTimestamp() { return timestamp; } @Override + public Database getDatabaseObject() throws Exception { + return (Database) MessageBuilder.getTObj(dbJson, Database.class); + } + + @Override public String toString() { try { return JSONMessageDeserializer.mapper.writeValueAsString(this);