TanYuxin-tyx commented on code in PR #22330: URL: https://github.com/apache/flink/pull/22330#discussion_r1187058204
########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/shuffle/TieredInternalShuffleMaster.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.runtime.io.network.partition.hybrid.tiered.shuffle; + +import org.apache.flink.api.common.JobID; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.runtime.io.network.partition.ResultPartitionID; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStorageConfiguration; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.ResourceRegistry; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.TieredStorageMasterClient; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.tier.TierFactory; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.tier.TierMasterAgent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStorageIdMappingUtils.convertId; + +/** + * A wrapper internal shuffle master class for tiered storage. All the tiered storage operations + * with the shuffle master should be wrapped in this class. + */ +public class TieredInternalShuffleMaster { + + private final TieredStorageMasterClient tieredStorageMasterClient; + + private final Map<JobID, List<ResultPartitionID>> jobPartitionIds; + + public TieredInternalShuffleMaster(Configuration conf) { + TieredStorageConfiguration tieredStorageConfiguration = + createTieredStorageConfiguration(conf); + ResourceRegistry resourceRegistry = new ResourceRegistry(); + List<TierMasterAgent> tierFactories = + tieredStorageConfiguration.getTierFactories().stream() + .map(TierFactory::createMasterAgent) + .peek(tierMasterAgent -> tierMasterAgent.setup(resourceRegistry)) + .collect(Collectors.toList()); + this.tieredStorageMasterClient = new TieredStorageMasterClient(tierFactories); + this.jobPartitionIds = new HashMap<>(); + } + + public void addPartition(JobID jobID, ResultPartitionID resultPartitionID) { + jobPartitionIds.computeIfAbsent(jobID, ignore -> new ArrayList<>()).add(resultPartitionID); + tieredStorageMasterClient.addPartition(convertId(resultPartitionID)); + } + + public void releasePartition(ResultPartitionID resultPartitionID) { + tieredStorageMasterClient.releasePartition(convertId(resultPartitionID)); + } + + public void unregisterJob(JobID jobID) { + List<ResultPartitionID> resultPartitionIDs = jobPartitionIds.remove(jobID); + if (resultPartitionIDs != null) { + resultPartitionIDs.forEach( + resultPartitionID -> + tieredStorageMasterClient.releasePartition( + convertId(resultPartitionID))); + } + } Review Comment: OK. Because we can not know the exact jobId when releasing a result partition, I added a `partitionJobIds` to record the jobId of the `resultPartitioinId` to be released. 1. When adding a partition, add the partition id and job id to `jobPartitionIds` and `partitionJobIds` separately. 2. When releasing a partition, remove the partition id in the `jobPartitionIds` and `partitionJobIds` separately. 3. When registering a job, remove all the partition ids of the job in the `jobPartitionIds` and `partitionJobIds`. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org