TanYuxin-tyx commented on code in PR #22330: URL: https://github.com/apache/flink/pull/22330#discussion_r1187058705
########## 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))); + } + } + + private TieredStorageConfiguration createTieredStorageConfiguration(Configuration conf) { + // TODO, from the configuration, get the configured options(i.e., remote storage path, the + // reserved storage size, etc.), then set them to the builder. Review Comment: Replaced this with a `TieredStorageConfiguration#fromConfiguration`. -- 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