zentol commented on a change in pull request #17387:
URL: https://github.com/apache/flink/pull/17387#discussion_r748126942
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/metrics/groups/TaskManagerMetricGroup.java
##########
@@ -81,61 +79,33 @@ public String taskManagerId() {
// job groups
// ------------------------------------------------------------------------
- public TaskMetricGroup addTaskForJob(
- final JobID jobId,
- final String jobName,
- final JobVertexID jobVertexId,
- final ExecutionAttemptID executionAttemptId,
- final String taskName,
- final int subtaskIndex,
- final int attemptNumber) {
+ public TaskManagerJobMetricGroup getOrCreateTaskManagerJobMetricGroup(
+ JobID jobId, String jobName) {
Preconditions.checkNotNull(jobId);
-
String resolvedJobName = jobName == null || jobName.isEmpty() ?
jobId.toString() : jobName;
-
- // we cannot strictly lock both our map modification and the job group
modification
- // because it might lead to a deadlock
- while (true) {
- // get or create a jobs metric group
- TaskManagerJobMetricGroup currentJobGroup;
- synchronized (this) {
- currentJobGroup = jobs.get(jobId);
-
- if (currentJobGroup == null || currentJobGroup.isClosed()) {
- currentJobGroup =
- new TaskManagerJobMetricGroup(registry, this,
jobId, resolvedJobName);
- jobs.put(jobId, currentJobGroup);
- }
- }
-
- // try to add another task. this may fail if we found a
pre-existing job metrics
- // group and it is closed concurrently
- TaskMetricGroup taskGroup =
- currentJobGroup.addTask(
- jobVertexId, executionAttemptId, taskName,
subtaskIndex, attemptNumber);
-
- if (taskGroup != null) {
- // successfully added the next task
- return taskGroup;
+ TaskManagerJobMetricGroup jobGroup;
+ synchronized (this) { // synchronization isn't strictly necessary as
of FLINK-24864
+ jobGroup = jobs.get(jobId);
+ if (jobGroup == null) {
+ jobGroup = new TaskManagerJobMetricGroup(registry, this,
jobId, resolvedJobName);
+ jobs.put(jobId, jobGroup);
}
-
- // else fall through the loop
}
+ return jobGroup;
}
- public void removeJobMetricsGroup(JobID jobId, TaskManagerJobMetricGroup
group) {
- if (jobId == null || group == null || !group.isClosed()) {
- return;
- }
-
- synchronized (this) {
- // optimistically remove the currently contained group, and check
later if it was
- // correct
- TaskManagerJobMetricGroup containedGroup = jobs.remove(jobId);
+ public TaskManagerJobMetricGroup getJobMetricsGroup(JobID jobId) {
Review comment:
But...couldn't you just pass `jobGroup`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]