xintongsong commented on code in PR #22330: URL: https://github.com/apache/flink/pull/22330#discussion_r1181363214
########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/TieredResource.java: ########## @@ -0,0 +1,26 @@ +/* + * 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.storage; + +/** The resource (e.g., local files, remote storage files, etc.) for the Tiered Storage. */ +public interface TieredResource { Review Comment: I'd suggest the name `TieredStorageResource`. ########## 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: Each partition can be released for multiple times, one from `releasePartition` and one from `unregisterJob`, let alone the possibility that `releasePartition` and `unregisterJob` may or may not be called multiple times for the same partition/job id. This means all the classes handling the release of partitions (`TieredStorageMasterClient`, `TierMasterAgent`, etc.) would need to be aware of such possibility. Alternatively, we can guarantee each partition is only released for once, by eagerly removing the partition from `releasePartition ` in `releasePartition` and calling `TieredStorageMasterClient#releasePartition` only if the partition can be found in `releasePartition`. ########## 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)) Review Comment: We are calling `setup` immediately after creating the master agents. Do we plan to add more steps in between in the subsequent PRs? If not, it might be better to pass the setting-up arguments directly to the creating method, so that we won't need to frequently check whether the agent is setup inside the agents. ########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/common/TieredStorageConfiguration.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.common; + +/** Configurations for the Tiered Storage. */ +public class TieredStorageConfiguration { Review Comment: Minor: In Flink, we usually organize the definition of a class in the following order: fields, methods, internal types. ########## flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/TieredStorageTestUtils.java: ########## @@ -0,0 +1,29 @@ +/* + * 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; + +/** The test utils for the tiered storage tests. */ +public class TieredStorageTestUtils { Review Comment: This class does not provide any util functions. And why would we need these constants in a dedicated class? ########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultPartitionID.java: ########## @@ -23,6 +23,9 @@ import org.apache.flink.runtime.executiongraph.IntermediateResultPartition; import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID; +import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf; +import org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled; Review Comment: I also don't think `ResultPartitionID` should depends on Netty classes. However, it seems `IntermediateResultPartitionID`, `ExecutionAttemptID` and likely more have already depended on Netty classes. Let's keep it as is and create a follow-up ticket for cleaning the improper dependency. ########## 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: From this description, I think this method should not belong to `TieredInternalShuffleMaster`. Take remote storage path as an example, we need it not only for the master but also for the producer & consumer, and we definitely want to derive the same path from the configuration for all the components. Same for reserved storage size and likely other configurations. -- 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]
