rohangarg commented on code in PR #13368: URL: https://github.com/apache/druid/pull/13368#discussion_r1081122205
########## processing/src/main/java/org/apache/druid/frame/channel/ComposingWritableFrameChannel.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.druid.frame.channel; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.ListenableFuture; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.query.ResourceLimitExceededException; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +/** + * A composed writable channel to write frames. The channel can encapsulate multiple writable channels in it and + * automatically switches to next channels once the current write channel cannot allow more writes. + */ +public class ComposingWritableFrameChannel implements WritableFrameChannel +{ + private final List<Supplier<WritableFrameChannel>> channels; + private final Map<Integer, HashSet<Integer>> partitionToChannelMap; + private int currentIndex; + + public ComposingWritableFrameChannel( + List<Supplier<WritableFrameChannel>> channels, + Map<Integer, HashSet<Integer>> partitionToChannelMap + ) + { + this.channels = Preconditions.checkNotNull(channels, "channels is null"); + this.partitionToChannelMap = + Preconditions.checkNotNull(partitionToChannelMap, "partitionToChannelMap is null"); + this.currentIndex = 0; + } + + @Override + public void write(FrameWithPartition frameWithPartition) throws IOException + { + if (currentIndex >= channels.size()) { + throw new ISE("No more channels available to write. Total available channels : " + channels.size()); + } + + try { + channels.get(currentIndex).get().write(frameWithPartition); Review Comment: The ordering is fixed currently in the composing factory - it is always disk followed by durable storage. I had tried using a custom object/error instead of an exception but that seemed overkill currently since there's only one such case right now. I have added a comment explaining the need and also that we can create custom objects in future if the logic becomes complex -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
