iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

Some tests are leaking temp folders

Open lirui-apache opened this issue 4 years ago • 5 comments

We encountered this issue with 0.11, but thought it might still apply to latest code. Basically the issue is because test classes try to clean up temp folders by calling java.io.File.delete, which won't really delete the folder if it's not empty.

Problematic classes include: SparkTestBaseWithCatalog::dropWarehouse TestHiveMetastore::stop TestCatalogTableLoader::dropWarehouse

lirui-apache avatar Dec 15 '21 13:12 lirui-apache

I tried deleting these folders with commons-io FileUtils, but then tests start to fail with metastore internal errors. I think it's because we didn't clean up some static fields in metastore between different tests.

Such as the thread local TxnStore in HMSHandler: https://github.com/apache/hive/blob/rel/release-2.3.8/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java#L249

and the connection pool in TxnHandler: https://github.com/apache/hive/blob/rel/release-2.3.8/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java#L149

lirui-apache avatar Dec 16 '21 13:12 lirui-apache

@lirui-apache: If I recall correctly we usually start the HMS instance BeforeClass and close it in AfterClass. So deleting warehouse directories between tests would be counterproductive 😄 TestHiveMetastore.reset() tries to drop the extra databases, tables and folders. Is it called between tests?

pvary avatar Dec 16 '21 14:12 pvary

Hi @pvary , I'm not trying to delete warehouse folders between test methods. I just want to make sure the clean up logic in AfterClass really does its job to delete these folders. Or do you mean even AfterClass shouldn't do this? Then I wonder where this can be done, because otherwise it slowly eats up the disk space in our CI runners.

I checked TestHiveMetastore.reset(), seems it's only called in the After method of some tests in iceberg-mr.

lirui-apache avatar Dec 17 '21 04:12 lirui-apache

@lirui-apache: You are absolutely right that we should delete the warehouse folders in the AfterClass. I am surprised that the directory is not removed as we create it with java.nio.file.Files.createTempDirectory("hive", asFileAttribute(fromString("rwxrwxrwx"))).toFile(). From the doc:

As with the createTempFile methods, this method is only part of a temporary-file facility. A shutdown-hook, or the File.deleteOnExit mechanism may be used to delete the directory automatically.

Maybe we just have to call after creation?

      this.hiveLocalDir.deleteOnExit();

As for the TestHiveMetastore .reset(), I think it would be useful to call it in the After methods to separate the test cases.

pvary avatar Dec 17 '21 08:12 pvary

Thanks @pvary for confirming. Yeah a shutdown hook will do the trick, although we might still want to figure out why follow-up tests are relying on the previous temp folders not being deleted. I guess it indicates some more static fields we need to clear out.

lirui-apache avatar Dec 20 '21 12:12 lirui-apache