-
Notifications
You must be signed in to change notification settings - Fork 14k
[FLINK-40019][core][runtime] Support per-job delegation tokens #28639
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
base: master
Are you sure you want to change the base?
Changes from all commits
b154129
6f3db83
9c1c49d
485c10a
3c1dbd7
451af6c
35495a6
9ce1950
c2ac7c3
4df526e
b02b224
ddf1001
8d5d41a
ce9efa9
8c56630
c2e1b98
39bf366
8b25efa
56bf595
f01b959
0f60c5c
07593f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.flink.core.security.token; | ||
|
|
||
| import org.apache.flink.annotation.Experimental; | ||
|
|
||
| /** | ||
| * Handed to a {@link DelegationTokenProvider} at {@link | ||
| * DelegationTokenProvider#init(org.apache.flink.configuration.Configuration, | ||
| * DelegationTokenManagerCallback) init} time, giving the provider a way to ask the delegation token | ||
| * manager to re-obtain tokens. The provider may retain the callback and invoke it later, outside | ||
| * the {@code init}/{@code registerJob} call stack. | ||
| */ | ||
| @Experimental | ||
| public interface DelegationTokenManagerCallback { | ||
|
|
||
| /** | ||
| * Requests an asynchronous token re-obtain and redistribution to all receivers, bringing the | ||
| * next obtain cycle forward instead of waiting for the periodic renewal. | ||
| * | ||
| * <p>May be called from any thread at any time after {@code init}. The manager coalesces | ||
| * requests and may apply a cooldown, so a call does not necessarily map to one obtain cycle. | ||
| * Returns immediately and does not wait for completion. | ||
| */ | ||
| void reobtainDelegationTokens(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import org.apache.flink.api.common.JobID; | ||
| import org.apache.flink.api.common.JobStatus; | ||
| import org.apache.flink.api.java.tuple.Tuple2; | ||
| import org.apache.flink.configuration.Configuration; | ||
| import org.apache.flink.configuration.ThreadDumpMode; | ||
| import org.apache.flink.runtime.blob.TransientBlobKey; | ||
| import org.apache.flink.runtime.blocklist.BlockedNode; | ||
|
|
@@ -116,8 +117,8 @@ | |
| * <p>It offers the following methods as part of its rpc interface to interact with him remotely: | ||
| * | ||
| * <ul> | ||
| * <li>{@link #registerJobMaster(JobMasterId, ResourceID, String, JobID, Duration)} registers a | ||
| * {@link JobMaster} at the resource manager | ||
| * <li>{@link #registerJobMaster(JobMasterId, ResourceID, String, JobID, Configuration, Duration)} | ||
| * registers a {@link JobMaster} at the resource manager | ||
| * </ul> | ||
| */ | ||
| public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable> | ||
|
|
@@ -367,12 +368,14 @@ public CompletableFuture<RegistrationResponse> registerJobMaster( | |
| final ResourceID jobManagerResourceId, | ||
| final String jobManagerAddress, | ||
| final JobID jobId, | ||
| final Configuration jobConfiguration, | ||
| final Duration timeout) { | ||
|
|
||
| checkNotNull(jobMasterId); | ||
| checkNotNull(jobManagerResourceId); | ||
| checkNotNull(jobManagerAddress); | ||
| checkNotNull(jobId); | ||
| checkNotNull(jobConfiguration); | ||
|
|
||
| try (MdcCloseable ignored = MdcUtils.withContext(MdcUtils.asContextData(jobId))) { | ||
| if (!jobLeaderIdService.containsJob(jobId)) { | ||
|
|
@@ -428,6 +431,20 @@ public CompletableFuture<RegistrationResponse> registerJobMaster( | |
| jobMasterIdFuture, | ||
| (JobMasterGateway jobMasterGateway, JobMasterId leadingJobMasterId) -> { | ||
| if (Objects.equals(leadingJobMasterId, jobMasterId)) { | ||
| // Reject a failed provider registration before installing the | ||
| // JobMaster registration. Report plugin linkage errors as | ||
| // registration failures too. | ||
| try { | ||
| delegationTokenManager.registerJob(jobId, jobConfiguration); | ||
| } catch (Exception | LinkageError e) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want to prepare for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The LinkageError catch is there so a failed registration doesn't leave job state in the providers that already registered the job. I see three options:
Please correct me if I'm missing something and appreciate if you can share your opinion on these tradeoffs. |
||
| return new RegistrationResponse.Failure( | ||
| new FlinkException( | ||
| "Failed to register job " | ||
| + jobId | ||
| + " with the delegation token " | ||
| + "manager", | ||
| e)); | ||
| } | ||
| return registerJobMasterInternal( | ||
| jobMasterGateway, | ||
| jobId, | ||
|
|
@@ -1224,6 +1241,15 @@ protected void removeJob(JobID jobId, Exception cause) { | |
| if (jobManagerRegistrations.containsKey(jobId)) { | ||
| closeJobManagerConnection(jobId, ResourceRequirementHandling.CLEAR, cause); | ||
| } | ||
|
|
||
| try { | ||
| delegationTokenManager.unregisterJob(jobId); | ||
| } catch (Exception e) { | ||
| log.warn( | ||
| "Could not properly remove the job {} from the delegation token manager.", | ||
| jobId, | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| protected void jobLeaderLostLeadership(JobID jobId, JobMasterId oldJobMasterId) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify my earlier comment on the test: I'm not claiming a prod bug here, this looks self-healing by design (retry skips
addJobviacontainsJob, cleanup happens viaremoveJob/leader-id timeout otherwise). What's missing is bookkeeping test coverage: a test that fails delegation-token registration once, then retries, and asserts the retry completes end-to-end without leavingjobLeaderIdServicein a duplicated or stale state. This path touches token delivery so I would like it locked in by a test rather than relying on inspection.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. The test in 8b25efa085e checks that the JobMaster retries automatically and, when registration succeeds, the leader retriever has been started once and never stopped. Removing and recreating the monitored entry would fail those assertions.
It also checks that the JobMaster establishes its connection and that the ResourceManager accepts a resource declaration for the same job and JobMaster ID.