Resolution: Won't Fix
Affects Version/s: 1.8.1
Fix Version/s: None
Parquet-avro and probably also other Parquet libraries are not well behaved. It registers a shutdown hook that bypasses application shutdown sequence, corrupts data written to currently opened Parquet file(s) and disables or reconfigures slf4j/logback logger so no further log message is visible.
Our application is a microservice that handles stop request in form of signal SIGTERM, resp. JVM shutdown hook. If it arrives the application will close all opened files (writers), release all other resources and gracefully shutdown. We are swiching from sequence files to Parquet at the moment and using Maven dependency org.apache.parquet:parquet-avro:1.8.1 which is current latest version. We are using Runtime.getRuntime().addShutdownHook() to handle SIGTERM.
See archive in attachment.
- Optionally update version of hadoop-client in pom.xml to match your Hadoop.
- Use mvn package to compile.
- Copy Hadoop configuration XMLs to config directory.
- Update configuration at the top of ParquetBrokenShutdown class.
- Execute ParquetBrokenShutdown class.
- Send SIGTERM to shutdown the application (kill PID).
Parquet library tries to care about application shutdown but this introduces more issues than solves. If application is writing to a file and the library asynchronously decides to close underlying writer, data loss will occur. The handle is just closed and all remaining records can't be written.
Stored file is also currupted in such case. It contains only four bytes "PAR1" header so actually all data are lost.
Together with that whole application logging using slf4j/logback is reconfigured or completely disabled so no more application's log messages appear in the output. This may be related to
PARQUET-369 and will be hopefully fixed in PARQUET-401. No such issue was observed when sequence files were used in the past.
Java executes threads of shutdown hooks independently and in parallel, but it is possible for the application to force its own shutdown to be executed before the Parquet's one. Parquet library uses Hadoop's ShutdownHookManager to register the hook which has a possibility to define a priority.
This workaround would be impossible if there are two or more such nasty libraries.
No workaround has been found for the second issue with disabled logging until now.
- Never touch logging configuration in libraries.
- Use slf4j-api interfaces and just output log messages.
- Application is responsible for configuration of logging.
- Do not register any shutdown hook in libraries that releases resources that are still possibly in use.
- Instead provide an API to the application to close/free the allocated resources (already present).
- The application is responsible to call close on all Closeables during shutdown in correct order and correct time.
- No library has enough information for that.
- Be well behaved library, do not try to be smarter than the application, it isn't possible.