Skip to content

Commit

Permalink
[enhance](hive)hive event code optimization apache#42637 (apache#42876)
Browse files Browse the repository at this point in the history
cherry pick from apache#42637

Co-authored-by: zhangdong <[email protected]>
  • Loading branch information
morningman and zddr authored Oct 30, 2024
1 parent 17d84dc commit 2a6d6c1
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private AddPartitionEvent(NotificationEvent event,
super(event, catalogName);
Preconditions.checkArgument(getEventType().equals(MetastoreEventType.ADD_PARTITION));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
AddPartitionMessage addPartitionMessage =
MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand Down Expand Up @@ -98,18 +98,18 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNames:[{}]", catalogName, dbName, tblName,
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNames:[{}]", catalogName, dbName, tblName,
partitionNames.toString());
// bail out early if there are not partitions to process
if (partitionNames.isEmpty()) {
infoLog("Partition list is empty. Ignoring this event.");
logInfo("Partition list is empty. Ignoring this event.");
return;
}
Env.getCurrentEnv().getCatalogMgr()
.addExternalPartitions(catalogName, dbName, hmsTbl.getTableName(), partitionNames, eventTime, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private AlterDatabaseEvent(NotificationEvent event,
dbNameAfter = dbAfter.getName();
} catch (Exception e) {
throw new MetastoreNotificationException(
debugString("Unable to parse the alter database message"), e);
getMsgWithEventInfo("Unable to parse the alter database message"), e);
}
// this is a rename event if either dbName of before and after object changed
isRename = !dbBefore.getName().equalsIgnoreCase(dbAfter.getName());
Expand All @@ -82,7 +82,7 @@ private void processRename() throws DdlException {
throw new DdlException("Only support ExternalCatalog Databases");
}
if (catalog.getDbNullable(dbAfter.getName()) != null) {
infoLog("AlterExternalDatabase canceled, because dbAfter has exist, "
logInfo("AlterExternalDatabase canceled, because dbAfter has exist, "
+ "catalogName:[{}],dbName:[{}]",
catalogName, dbAfter.getName());
return;
Expand Down Expand Up @@ -113,10 +113,10 @@ protected void process() throws MetastoreNotificationException {
return;
}
// only can change properties,we do nothing
infoLog("catalogName:[{}],dbName:[{}]", catalogName, dbName);
logInfo("catalogName:[{}],dbName:[{}]", catalogName, dbName);
} catch (Exception e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private AlterPartitionEvent(NotificationEvent event,
super(event, catalogName);
Preconditions.checkArgument(getEventType().equals(MetastoreEventType.ALTER_PARTITION));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
AlterPartitionMessage alterPartitionMessage =
MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand Down Expand Up @@ -109,7 +109,7 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNameBefore:[{}],partitionNameAfter:[{}]",
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNameBefore:[{}],partitionNameAfter:[{}]",
catalogName, dbName, tblName, partitionNameBefore, partitionNameAfter);
if (isRename) {
Env.getCurrentEnv().getCatalogMgr()
Expand All @@ -125,7 +125,7 @@ protected void process() throws MetastoreNotificationException {
}
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private AlterTableEvent(NotificationEvent event, String catalogName) {
super(event, catalogName);
Preconditions.checkArgument(MetastoreEventType.ALTER_TABLE.equals(getEventType()));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
JSONAlterTableMessage alterTableMessage =
(JSONAlterTableMessage) MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand All @@ -70,7 +70,7 @@ private AlterTableEvent(NotificationEvent event, String catalogName) {
tblNameAfter = tableAfter.getTableName();
} catch (Exception e) {
throw new MetastoreNotificationException(
debugString("Unable to parse the alter table message"), e);
getMsgWithEventInfo("Unable to parse the alter table message"), e);
}
// this is a rename event if either dbName or tblName of before and after object changed
isRename = !tableBefore.getDbName().equalsIgnoreCase(tableAfter.getDbName())
Expand Down Expand Up @@ -111,7 +111,7 @@ private void processRename() throws DdlException {
boolean hasExist = Env.getCurrentEnv().getCatalogMgr()
.externalTableExistInLocal(tableAfter.getDbName(), tableAfter.getTableName(), catalogName);
if (hasExist) {
infoLog("AlterExternalTable canceled,because tableAfter has exist, "
logInfo("AlterExternalTable canceled,because tableAfter has exist, "
+ "catalogName:[{}],dbName:[{}],tableName:[{}]",
catalogName, dbName, tableAfter.getTableName());
return;
Expand Down Expand Up @@ -143,7 +143,7 @@ public String getTblNameAfter() {
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableBefore:[{}],tableAfter:[{}]", catalogName, dbName,
logInfo("catalogName:[{}],dbName:[{}],tableBefore:[{}],tableAfter:[{}]", catalogName, dbName,
tableBefore.getTableName(), tableAfter.getTableName());
if (isRename) {
processRename();
Expand All @@ -161,7 +161,7 @@ protected void process() throws MetastoreNotificationException {
eventTime);
} catch (Exception e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}]", catalogName, dbName);
logInfo("catalogName:[{}],dbName:[{}]", catalogName, dbName);
Env.getCurrentEnv().getCatalogMgr().registerExternalDatabaseFromEvent(dbName, catalogName, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private CreateTableEvent(NotificationEvent event, String catalogName) throws Met
super(event, catalogName);
Preconditions.checkArgument(MetastoreEventType.CREATE_TABLE.equals(getEventType()));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
CreateTableMessage createTableMessage =
MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand All @@ -57,7 +57,7 @@ private CreateTableEvent(NotificationEvent event, String catalogName) throws Met
hmsTbl.setTableName(hmsTbl.getTableName().toLowerCase(Locale.ROOT));
} catch (Exception e) {
throw new MetastoreNotificationException(
debugString("Unable to deserialize the event message"), e);
getMsgWithEventInfo("Unable to deserialize the event message"), e);
}
}

Expand All @@ -78,12 +78,12 @@ protected boolean willChangeTableName() {
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tblName);
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tblName);
Env.getCurrentEnv().getCatalogMgr()
.registerExternalTableFromEvent(dbName, hmsTbl.getTableName(), catalogName, eventTime, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}]", catalogName, dbName);
logInfo("catalogName:[{}],dbName:[{}]", catalogName, dbName);
Env.getCurrentEnv().getCatalogMgr()
.unregisterExternalDatabase(dbName, catalogName, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private DropPartitionEvent(NotificationEvent event,
super(event, catalogName);
Preconditions.checkArgument(getEventType().equals(MetastoreEventType.DROP_PARTITION));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
DropPartitionMessage dropPartitionMessage =
MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand Down Expand Up @@ -97,19 +97,19 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNames:[{}]", catalogName, dbName, tblName,
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}],partitionNames:[{}]", catalogName, dbName, tblName,
partitionNames.toString());
// bail out early if there are not partitions to process
if (partitionNames.isEmpty()) {
infoLog("Partition list is empty. Ignoring this event.");
logInfo("Partition list is empty. Ignoring this event.");
return;
}
Env.getCurrentEnv().getCatalogMgr()
.dropExternalPartitions(catalogName, dbName, hmsTbl.getTableName(),
partitionNames, eventTime, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private DropTableEvent(NotificationEvent event,
super(event, catalogName);
Preconditions.checkArgument(MetastoreEventType.DROP_TABLE.equals(getEventType()));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
try {
JSONDropTableMessage dropTableMessage =
(JSONDropTableMessage) MetastoreEventsProcessor.getMessageDeserializer(event.getMessageFormat())
Expand Down Expand Up @@ -77,11 +77,11 @@ protected boolean willChangeTableName() {
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tableName);
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tableName);
Env.getCurrentEnv().getCatalogMgr().unregisterExternalTable(dbName, tableName, catalogName, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ protected static List<MetastoreEvent> getEvents(NotificationEvent event,

@Override
public void process() {
infoLog("Ignoring unknown event type " + metastoreNotificationEvent.getEventType());
logInfo("Ignoring unknown event type " + metastoreNotificationEvent.getEventType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private InsertEvent(NotificationEvent event, String catalogName) {
super(event, catalogName);
Preconditions.checkArgument(getEventType().equals(MetastoreEventType.INSERT));
Preconditions
.checkNotNull(event.getMessage(), debugString("Event message is null"));
.checkNotNull(event.getMessage(), getMsgWithEventInfo("Event message is null"));
}

protected static List<MetastoreEvent> getEvents(NotificationEvent event, String catalogName) {
Expand All @@ -62,7 +62,7 @@ protected boolean willChangeTableName() {
@Override
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tblName);
logInfo("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tblName);
/**
* Only when we use hive client to execute a `INSERT INTO TBL SELECT * ...` or `INSERT INTO TBL ...` sql
* to a non-partitioned table then the hms will generate an insert event, and there is not
Expand All @@ -75,7 +75,7 @@ protected void process() throws MetastoreNotificationException {
eventTime);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);
getMsgWithEventInfo("Failed to process event"), e);
}
}

Expand Down
Loading

0 comments on commit 2a6d6c1

Please sign in to comment.