Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSQ worker: Support in-memory shuffles. #16790

Merged
merged 13 commits into from
Jul 31, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
import org.apache.druid.msq.statistics.PartialKeyStatisticsInformation;

import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;

/**
* Client for the multi-stage query controller. Used by a Worker task.
* Client for the multi-stage query controller. Used by a {@link Worker}. Each instance is specific to a single query,
* meaning it communicates with a single controller.
*/
public interface ControllerClient extends AutoCloseable
public interface ControllerClient extends Closeable
{
/**
* Client side method to update the controller with partial key statistics information for a particular stage and worker.
* Controller's implementation collates all the information for a stage to fetch key statistics from workers.
* Client side method to update the controller with partial key statistics information for a particular stage
* and worker. The controller collates all the information for a stage to fetch key statistics from workers.
*
* Only used when {@link StageDefinition#mustGatherResultKeyStatistics()}.
*/
void postPartialKeyStatistics(
StageId stageId,
Expand Down Expand Up @@ -77,20 +81,21 @@ void postResultsComplete(

/**
* Client side method to inform the controller that the error has occured in the given worker.
*
* @param queryId query ID, if this error is associated with a specific query
* @param errorWrapper error details
*/
void postWorkerError(
String workerId,
@Nullable String queryId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the places where this is called, we pass it the worker's task id. Should we keep the parameter name as is? Also, I was taking a look at the controller chat handler and we don't really use the worker's task id afaict. Maybe we can remove the param altogether, though that would introduce backward compatibility issues.
Also, can it be nullable given that we pass this as a URL param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I don't actually need to change this from workerId to queryId right now. This was related to some other stuff I was tinkering with, about supporting multiple queries running on the same worker id, but it isn't important for this PR. I'll revert it.

Fwiw, the server side (ControllerResource) does not read this parameter, so it currently doesn't matter what it is. That's probably why I didn't notice the inconsistency when testing this PR.

MSQErrorReport errorWrapper
) throws IOException;

/**
* Client side method to inform the controller about the warnings generated by the given worker.
*/
void postWorkerWarning(
List<MSQErrorReport> MSQErrorReports
) throws IOException;
void postWorkerWarning(List<MSQErrorReport> MSQErrorReports) throws IOException;

List<String> getTaskList() throws IOException;
List<String> getWorkerIds() throws IOException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lets add javadoc here, even though it wasn't present in the original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added javadoc.


/**
* Close this client. Idempotent.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.msq.exec;

import org.apache.druid.frame.processor.OutputChannel;
import org.apache.druid.frame.processor.OutputChannelFactory;
import org.apache.druid.frame.processor.PartitionedOutputChannel;

import java.io.IOException;

/**
* Decorator for {@link OutputChannelFactory} that notifies a {@link Listener} whenever a channel is opened.
*/
public class ListeningOutputChannelFactory implements OutputChannelFactory
{
private final OutputChannelFactory delegate;
private final Listener listener;

public ListeningOutputChannelFactory(final OutputChannelFactory delegate, final Listener listener)
{
this.delegate = delegate;
this.listener = listener;
}

@Override
public OutputChannel openChannel(final int partitionNumber) throws IOException
{
return notifyListener(delegate.openChannel(partitionNumber));
}


@Override
public OutputChannel openNilChannel(final int partitionNumber)
{
return notifyListener(delegate.openNilChannel(partitionNumber));
}

@Override
public PartitionedOutputChannel openPartitionedChannel(
final String name,
final boolean deleteAfterRead
)
{
throw new UnsupportedOperationException("Listening to partitioned channels is not supported");
}

private OutputChannel notifyListener(OutputChannel channel)
{
listener.channelOpened(channel);
return channel;
}

public interface Listener
{
void channelOpened(OutputChannel channel);
}
}
Loading
Loading