Skip to content

Commit

Permalink
Add cause of failures in Thrift and Glue metastore
Browse files Browse the repository at this point in the history
This will be beneficial in case of detecting retry issues
  • Loading branch information
pajaks authored and ebyhr committed Nov 13, 2023
1 parent 944aa96 commit 8155c56
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ public class SchemaAlreadyExistsException

public SchemaAlreadyExistsException(String schemaName)
{
this(schemaName, format("Schema already exists: '%s'", schemaName));
this(schemaName, null);
}

public SchemaAlreadyExistsException(String schemaName, String message)
public SchemaAlreadyExistsException(String schemaName, Throwable cause)
{
super(ALREADY_EXISTS, message);
this(schemaName, format("Schema already exists: '%s'", schemaName), cause);
}

public SchemaAlreadyExistsException(String schemaName, String message, Throwable cause)
{
super(ALREADY_EXISTS, message, cause);
this.schemaName = schemaName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class TableAlreadyExistsException

public TableAlreadyExistsException(SchemaTableName tableName)
{
this(tableName, format("Table already exists: '%s'", tableName));
this(tableName, null);
}

public TableAlreadyExistsException(SchemaTableName tableName, String message)
public TableAlreadyExistsException(SchemaTableName tableName, Throwable cause)
{
this(tableName, message, null);
this(tableName, format("Table already exists: '%s'", tableName), cause);
}

public TableAlreadyExistsException(SchemaTableName tableName, String message, Throwable cause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private void updateTableStatisticsInternal(String databaseName, String tableName
columnStatisticsProvider.updateTableColumnStatistics(table, updatedStatistics.getColumnStatistics());
}
catch (EntityNotFoundException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -487,7 +487,7 @@ public void createDatabase(Database database)
glueClient.createDatabase(new CreateDatabaseRequest().withDatabaseInput(databaseInput)));
}
catch (AlreadyExistsException e) {
throw new SchemaAlreadyExistsException(database.getDatabaseName());
throw new SchemaAlreadyExistsException(database.getDatabaseName(), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -519,7 +519,7 @@ public void dropDatabase(String databaseName, boolean deleteData)
glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(databaseName)));
}
catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(databaseName);
throw new SchemaNotFoundException(databaseName, e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -563,10 +563,10 @@ public void createTable(Table table, PrincipalPrivileges principalPrivileges)
.withTableInput(input)));
}
catch (AlreadyExistsException e) {
throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()), e);
}
catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(table.getDatabaseName());
throw new SchemaNotFoundException(table.getDatabaseName(), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -626,7 +626,7 @@ public void replaceTable(String databaseName, String tableName, Table newTable,
.withTableInput(newTableInput)));
}
catch (EntityNotFoundException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -711,7 +711,7 @@ public void setTableOwner(String databaseName, String tableName, HivePrincipal p
.withTableInput(newTableInput)));
}
catch (EntityNotFoundException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -1126,7 +1126,7 @@ public void alterPartition(String databaseName, String tableName, PartitionWithS
partition.getStatistics().getColumnStatistics());
}
catch (EntityNotFoundException e) {
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues());
throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues(), e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -1264,10 +1264,10 @@ public void createFunction(String databaseName, String functionName, LanguageFun
.withFunctionInput(functionInput)));
}
catch (AlreadyExistsException e) {
throw new TrinoException(ALREADY_EXISTS, "Function already exists");
throw new TrinoException(ALREADY_EXISTS, "Function already exists", e);
}
catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(databaseName);
throw new SchemaNotFoundException(databaseName, e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public void dropFunction(String databaseName, String functionName, String signat
.withFunctionName(metastoreFunctionName(functionName, signatureToken))));
}
catch (EntityNotFoundException e) {
throw new TrinoException(FUNCTION_NOT_FOUND, "Function not found");
throw new TrinoException(FUNCTION_NOT_FOUND, "Function not found", e);
}
catch (AmazonServiceException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private Map<String, HiveColumnStatistics> getTableColumnStatistics(String databa
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -480,7 +480,7 @@ private Map<String, List<ColumnStatisticsObj>> getMetastorePartitionColumnStatis
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -561,7 +561,7 @@ private void setTableColumnStatistics(String databaseName, String tableName, Lis
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand All @@ -585,7 +585,7 @@ private void deleteTableColumnStatistics(String databaseName, String tableName,
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -655,7 +655,7 @@ private void setPartitionColumnStatistics(String databaseName, String tableName,
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand All @@ -679,7 +679,7 @@ private void deletePartitionColumnStatistics(String databaseName, String tableNa
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -953,7 +953,7 @@ public void createDatabase(Database database)
}));
}
catch (AlreadyExistsException e) {
throw new SchemaAlreadyExistsException(database.getName());
throw new SchemaAlreadyExistsException(database.getName(), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand All @@ -978,7 +978,7 @@ public void dropDatabase(String databaseName, boolean deleteData)
}));
}
catch (NoSuchObjectException e) {
throw new SchemaNotFoundException(databaseName);
throw new SchemaNotFoundException(databaseName, e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down Expand Up @@ -1006,7 +1006,7 @@ public void alterDatabase(String databaseName, Database database)
}));
}
catch (NoSuchObjectException e) {
throw new SchemaNotFoundException(databaseName);
throw new SchemaNotFoundException(databaseName, e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand All @@ -1032,10 +1032,10 @@ public void createTable(Table table)
}));
}
catch (AlreadyExistsException e) {
throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName()));
throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName()), e);
}
catch (NoSuchObjectException e) {
throw new SchemaNotFoundException(table.getDbName());
throw new SchemaNotFoundException(table.getDbName(), e);
}
catch (InvalidObjectException e) {
boolean databaseMissing;
Expand All @@ -1047,7 +1047,7 @@ public void createTable(Table table)
databaseMissing = false; // we don't know, assume it exists for the purpose of error reporting
}
if (databaseMissing) {
throw new SchemaNotFoundException(table.getDbName());
throw new SchemaNotFoundException(table.getDbName(), e);
}
throw new TrinoException(HIVE_METASTORE_ERROR, e);
}
Expand Down Expand Up @@ -1079,7 +1079,7 @@ public void dropTable(String databaseName, String tableName, boolean deleteData)
}));
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e);
}
catch (TException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void dropNamespace(ConnectorSession session, String namespace)
glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(namespace)));
}
catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(namespace);
throw new SchemaNotFoundException(namespace, e);
}
catch (AmazonServiceException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, e);
Expand All @@ -291,7 +291,7 @@ public Map<String, Object> loadNamespaceMetadata(ConnectorSession session, Strin
return metadata.buildOrThrow();
}
catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(namespace);
throw new SchemaNotFoundException(namespace, e);
}
catch (AmazonServiceException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, e);
Expand All @@ -316,7 +316,7 @@ public void createNamespace(ConnectorSession session, String namespace, Map<Stri
.withDatabaseInput(createDatabaseInput(namespace, properties))));
}
catch (AlreadyExistsException e) {
throw new SchemaAlreadyExistsException(namespace);
throw new SchemaAlreadyExistsException(namespace, e);
}
catch (AmazonServiceException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, e);
Expand Down

0 comments on commit 8155c56

Please sign in to comment.