[FLINK-36406] Close MetadataApplier when the job stops #3623
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request implements closing
MetadataApplier
when the job stops. This allowsMetadataApplier
implementations to release the resources that they may use to apply schema changes (e.g. a JDBC connection).Choice of the interface
SchemaRegistryRequestHandler
(which will closeMetadataApplier
) implementsCloseable
, so it would make sense to declareMetadataApplier
asCloseable
as well.PaimonMetadataApplier
internally instantiates a PaimonCatalog
, which it ideally should close, and which isAutocloseable
.To me, it makes more sense to declare
MetadataApplier
asAutoCloseable
. The reason is thatCloseable
is an IO-specific interface, which is declared injava.io
and throwsIOException
inclose()
.AutoCloseable
is more generic and seems to be more suitable forMetadataApplier
, whose implementations doesn't necessarily perform IO.Testing
I didn't find existing tests focusing on
SchemaRegistryRequestHandler
orSchemaRegistry
, so I dind't implement a unit test. Testing of the changes inSchemaRegistryRequestHandler
can be done by implementing some logging inValuesMetadataApplier#close
and running any test that uses it (e.g.FlinkPipelineComposerITCase
)Additional scope
Just as a demonstration of where this new functionality can be applied, I implemented
close()
inPaimonMetadataApplier
. I didn't test it and am not sure that this is the right thing to do. I can revert this part, if necessary.Further considerations
The problem of closing resources seems also relevant for the
MetadataAccessor
interface. Specifically,MySqlMetadataAccessor
disconnects from the database after each call but some other implementations may require maintaining a persistent connection.