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-25173][table][hive] Introduce CatalogLock and implement HiveCatalogLock #18114

Merged
merged 4 commits into from Dec 23, 2021

Conversation

JingsongLi
Copy link
Contributor

What is the purpose of the change

Introduce CatalogLock for connectors, source & sink can use this lock to do some global sync.

/**
 * An interface that allows source and sink to use global lock to some transaction-related things.
 */
@Internal
public interface CatalogLock extends Closeable {
 
    /** Run with catalog lock. The caller should tell catalog the database and table name. */
    <T> T runWithLock(String database, String table, Callable<T> callable) throws Exception;
 
    /** Factory to create {@link CatalogLock}. */
    interface Factory extends Serializable {
        CatalogLock create();
    }
} 

And we need a interface to set lock to source&sink by catalog:

/**
 * Source and sink implement this interface if they require {@link CatalogLock}.
 */
@Internal
public interface RequireCatalogLock {
 
    void setLockFactory(CatalogLock.Factory lockFactory);
} 

Brief change log

  • Introduce CatalogLock and RequireCatalogLock
  • Implement HiveCatalogLock

Verifying this change

HiveRunnerITCase.testCatalogLock

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (yes / no)
  • The serializers: (yes / no / don't know)
  • The runtime per-record code paths (performance sensitive): (yes / no / don't know)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
  • The S3 file system connector: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@flinkbot
Copy link
Collaborator

flinkbot commented Dec 15, 2021

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit d00c16d (Wed Dec 15 09:14:35 UTC 2021)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.


The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@JingsongLi
Copy link
Contributor Author

@flinkbot run azure

@RocMarshal
Copy link
Contributor

@JingsongLi Thanks for the efforts. Shall we add a description section into the relevant documentation page based on HiveConfOptions.java?

key("flink.hive.lock-check-max-sleep")
.durationType()
.defaultValue(Duration.ofSeconds(8))
.withDescription("the maximum sleep time when retrying to check the lock.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change the maximum to The maximum to make it consistent with the following options?

Copy link
Contributor

@luoyuxia luoyuxia left a comment

Choose a reason for hiding this comment

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

Otherwise, lgtm.

@JingsongLi
Copy link
Contributor Author

@JingsongLi Thanks for the efforts. Shall we add a description section into the relevant documentation page based on HiveConfOptions.java?

I am currently not ready to add, these options need a user scenario to expose, directly exposed in the documentation users can not use.

@JingsongLi
Copy link
Contributor Author

@flinkbot run azure

@JingsongLi JingsongLi merged commit 11f74d8 into apache:master Dec 23, 2021
FlechazoW pushed a commit to FlechazoW/flink that referenced this pull request Dec 23, 2021
public interface CatalogLock extends Closeable {

/** Run with catalog lock. The caller should tell catalog the database and table name. */
<T> T runWithLock(String database, String table, Callable<T> callable) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a question about this. Shall we also add String catalogName as a parameter too? Maybe only databaseName and TableName can not avoid clash? eg: catalog_a.db.tb and catalog_b.db.tb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, This lock is provided by catalog, and catalog itself already knows its name.

context.getClassLoader(),
context.isTemporary());
if (sink instanceof RequireCatalogLock) {
((RequireCatalogLock) sink).setLockFactory(HiveCatalogLock.createFactory(hiveConf));
Copy link
Contributor

Choose a reason for hiding this comment

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

For now we have to check and call RequireCatalogLock#setLockFactory manually in every DynamicTableFactory if necessary. Shall we lift this to Planner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now this is an internal interface. If we need lock to be more general, we can put lock factory into {@link DynamicTableFactory.Context}.

@shouweikun
Copy link
Contributor

Hi @JingsongLi , still I have some questions. Would you mind explaining it a little bit more? thx~

niklassemmler pushed a commit to niklassemmler/flink that referenced this pull request Feb 3, 2022
@JingsongLi JingsongLi deleted the hiveLock branch March 8, 2022 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants