Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.phoenix.jdbc;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HA_PARALLEL_TASK_TIMEOUT_COUNTER;
import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableList;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.PairOfSameType;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.monitoring.Metric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class ParallelPhoenixUtil {
// Timeout used for every operation on a ParallelPhoenixConnection. Defaults to
// phoenix.query.timeoutMs. 0 means wait indefinitely
public static final String PHOENIX_HA_PARALLEL_OPERATION_TIMEOUT_ATTRIB = "phoenix.ha.parallel.operation.timeout.ms";
public static ParallelPhoenixUtil INSTANCE = new ParallelPhoenixUtil();
private static final Logger LOGGER =
LoggerFactory.getLogger(ParallelPhoenixUtil.class);
private static final long DEFAULT_INTERNAL_OPERATION_TIMEOUT_MS = 1000;
private ParallelPhoenixUtil(){
}
/**
*
* @param futures position in list indicates the cluster
* @param context
* @return
* @throws SQLException
*/
public Object getAnyOfNonExceptionally(List> futures, ParallelPhoenixContext context) throws SQLException {
long timeoutMs = context.getOperationTimeout();
long endTime =
(timeoutMs == 0) ? Long.MAX_VALUE
: EnvironmentEdgeManager.currentTime() + timeoutMs;
long internalTimeoutMs =
(timeoutMs == 0) ? DEFAULT_INTERNAL_OPERATION_TIMEOUT_MS
: Math.min(DEFAULT_INTERNAL_OPERATION_TIMEOUT_MS, timeoutMs);
Object result = null;
boolean changed = true;
boolean timedout = false;
List> originalFutures = futures;
CompletableFuture