Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-36406] Close MetadataApplier when the job stops #3623

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/** {@code MetadataApplier} is used to apply metadata changes to external systems. */
@PublicEvolving
public interface MetadataApplier extends Serializable {
public interface MetadataApplier extends Serializable, AutoCloseable {

/** Apply the given {@link SchemaChangeEvent} to external systems. */
void applySchemaChange(SchemaChangeEvent schemaChangeEvent) throws SchemaEvolveException;
Expand All @@ -50,4 +50,8 @@ default boolean acceptsSchemaEvolutionType(SchemaChangeEventType schemaChangeEve
default Set<SchemaChangeEventType> getSupportedSchemaEvolutionTypes() {
return Arrays.stream(SchemaChangeEventTypeFamily.ALL).collect(Collectors.toSet());
}

/** Closes the metadata applier and its underlying resources. */
@Override
default void close() throws Exception {}
Comment on lines +55 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a JavaDocs for this method would be nice.

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public void applySchemaChange(SchemaChangeEvent schemaChangeEvent)
});
}

public void close() throws Exception {
if (catalog != null) {
catalog.close();
}
}

private void applyCreateTable(CreateTableEvent event) throws SchemaEvolveException {
try {
if (!catalog.databaseExists(event.tableId().getSchemaName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -343,11 +342,22 @@ public void getSchemaChangeResult(CompletableFuture<CoordinationResponse> respon
}
}

/**
* As at Flink 1.20, the runtime (<code>
* DefaultOperatorCoordinatorHandler#disposeAllOperatorCoordinators</code>) will ignore the
* exception thrown by this method. Thus, it should report errors by logging them.
*/
@Override
public void close() throws IOException {
public void close() {
if (schemaChangeThreadPool != null) {
schemaChangeThreadPool.shutdown();
}

try {
metadataApplier.close();
} catch (Exception e) {
LOG.error("Failed to close metadata applier.", e);
}
}

private List<SchemaChangeEvent> calculateDerivedSchemaChangeEvents(SchemaChangeEvent event) {
Expand Down
Loading