io.trino.execution.resourcegroups.LegacyResourceGroupConfigurationManager Maven / Gradle / Ivy
/*
* Licensed 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 io.trino.execution.resourcegroups;
import com.google.inject.Inject;
import io.trino.execution.QueryManagerConfig;
import io.trino.execution.resourcegroups.LegacyResourceGroupConfigurationManager.VoidContext;
import io.trino.spi.resourcegroups.ResourceGroup;
import io.trino.spi.resourcegroups.ResourceGroupConfigurationManager;
import io.trino.spi.resourcegroups.ResourceGroupId;
import io.trino.spi.resourcegroups.SelectionContext;
import io.trino.spi.resourcegroups.SelectionCriteria;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
public class LegacyResourceGroupConfigurationManager
implements ResourceGroupConfigurationManager
{
enum VoidContext
{
NONE
}
private static final ResourceGroupId GLOBAL = new ResourceGroupId("global");
private final int hardConcurrencyLimit;
private final int maxQueued;
@Inject
public LegacyResourceGroupConfigurationManager(QueryManagerConfig config)
{
hardConcurrencyLimit = config.getMaxConcurrentQueries();
maxQueued = config.getMaxQueuedQueries();
}
@Override
public void configure(ResourceGroup group, SelectionContext criteria)
{
checkArgument(group.getId().equals(GLOBAL), "Unexpected resource group: %s", group.getId());
group.setMaxQueuedQueries(maxQueued);
group.setHardConcurrencyLimit(hardConcurrencyLimit);
}
@Override
public Optional> match(SelectionCriteria criteria)
{
return Optional.of(new SelectionContext<>(GLOBAL, VoidContext.NONE));
}
@Override
public SelectionContext parentGroupContext(SelectionContext context)
{
return new SelectionContext<>(
context.getResourceGroupId().getParent().orElseThrow(() -> new IllegalArgumentException("Group has no parent group: " + context.getResourceGroupId())),
VoidContext.NONE);
}
@Override
public void shutdown() {}
}