terrytlu opened a new issue, #17312:
URL: https://github.com/apache/iceberg/issues/17312
### Apache Iceberg version
1.4.3
### Query engine
Spark
### Please describe the bug 🐞
**Description**
When using `HiveCatalog` backed by Hive Metastore, `listTables` /
`listViews` can time out for namespaces containing a large number of tables.
In our production environment, a single database holds ~46,000 tables.
Calling `HiveCatalog.listTables(namespace)` consistently timed out, and
increasing `hive.metastore.client.socket.timeout` to 900s did **not** help.
```
java.lang.RuntimeException: Failed to list all tables under namespace
datatemp_export
at org.apache.iceberg.hive.HiveCatalog.listTables(HiveCatalog.java:171)
at org.apache.iceberg.cachingCatalog.listTables(CachingCatalog.java:136)
at
org.apache.amoro.formats.iceberg.IcebergCatalog.lambda$1ListTables$5(IcebergCatalog.java:94)
at org.apache.amoro.table.TableMetaStore.call(TableMetaStore.java:357)
at
org.apache.amoro.table.TableMetaStore.lambda$doAs$0(TableMetaStore.java:300)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1876)
at org.apache.amoro.table.TableMetaStore.doAs(TableMetaStore.java:300)
at
org.apache.amoro.formats.iceberg.IcebergCatalog.listTables(IcebergCatalog.java:92)
at
org.apache.amoro.common.UnifiedCatalog.listTables(CommonUnifiedCatalog.java:138)
at
org.apache.amoro.server.catalog.ExternalCatalog.lambda$1ListTables$10(ExternalCatalog.java:114)
at org.apache.amoro.table.TableMetaStore.call(TableMetaStore.java:357)
at
org.apache.amoro.table.TableMetaStore.lambda$doAs$0(TableMetaStore.java:300)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1876)
at org.apache.amoro.table.TableMetaStore.doAs(TableMetaStore.java:300)
at
org.apache.amoro.server.catalog.ExternalCatalog.doAs(ExternalCatalog.java:153)
at
org.apache.amoro.server.catalog.ExternalCatalog.listTables(ExternalCatalog.java:111)
at
org.apache.amoro.server.table.MasterSlaveTableService.lambda$null$4(MasterSlaveTableService.java:392)
at
java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
Caused by: org.apache.thrift.transport.TTransportException:
java.net.SocketTimeoutException: Read timed out
at
org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:178)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:109)
at
org.apache.thrift.transport.TSaslTransport.readLength(TSaslTransport.java:336)
at
org.apache.thrift.transport.TSaslTransport.readFrame(TSaslTransport.java:419)
at
org.apache.thrift.transport.TSaslTransport.read(TSaslTransport.java:395)
at
org.apache.thrift.transport.TSaslClientTransport.read(TSaslClientTransport.java:39)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:109)
at
org.apache.hadoop.hive.metastore.security.TFilterTransport.readAll(TFilterTransport.java:63)
at
org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:463)
at
org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:361)
at
org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:244)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:77)
at
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.recv_get_table_objects_by_name_req(ThriftHiveMetastore.java:2927)
at
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.getTableObjectsByNameReq(ThriftHiveMetastore.java:2923)
at
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.getTables(HiveMetaStoreClient.java:2965)
at
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.getTableObjectsByName(HiveMetaStoreClient.java:2946)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
```
**Root cause**
`HiveCatalog.listTables` resolves the Iceberg table list by fetching **all**
`Table` objects from HMS (`getTableObjectsByName`) and filtering on the client
side by `table_type = ICEBERG`. For a namespace with 46,000 tables, this pulls
the full metadata of every table (schema, columns, SD, parameters, etc.) over
the Thrift socket in one response — far more data than the client needs (only
the Iceberg table *names*).
**Proposed fix**
Use HMS server-side filtering via `IMetaStoreClient.listTableNamesByFilter`
(`get_table_names_by_filter`), e.g.:
```
hive_filter_field_params__table_type like "ICEBERG"
```
This filters on the HMS side and returns only the matching table names,
drastically reducing the payload. Keep the existing client-side path available
behind a fallback flag (default off) for environments where server-side
filtering is unsupported.
### Willingness to contribute
- [x] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]