Skip to content

Commit

Permalink
Simplified condition (#273)
Browse files Browse the repository at this point in the history
Signed-off-by: Rahil <rahilrshk@gmail.com>
  • Loading branch information
rahilsh authored Sep 22, 2021
1 parent 0352c65 commit 37506fe
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 123 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/tikv/cdc/CDCEvent.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.tikv.cdc;

import java.util.Objects;
import org.tikv.kvproto.Cdcpb.Event.Row;

class CDCEvent {
enum CDCEventType {
ROW,
RESOLVED_TS,
ERROR;
};
ERROR
}

public final long regionId;

Expand Down Expand Up @@ -57,7 +56,7 @@ public String toString() {
builder.append("resolvedTs=").append(resolvedTs);
break;
case ROW:
builder.append("row=").append(Objects.toString(row));
builder.append("row=").append(row);
break;
}
return builder.append("}").toString();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tikv/cdc/RegionCDCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RegionCDCClient implements AutoCloseable, StreamObserver<ChangeDataEvent>

private final AtomicBoolean running = new AtomicBoolean(false);

private boolean started = false;
private final boolean started = false;

public RegionCDCClient(
final TiRegion region,
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/org/tikv/common/MetricsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public class MetricsServer {
private static MetricsServer METRICS_SERVER_INSTANCE = null;
private static int metricsServerRefCount = 0;

private int port;
private HTTPServer server;
private CollectorRegistry collectorRegistry;
private final int port;
private final HTTPServer server;

public static MetricsServer getInstance(TiConfiguration conf) {
if (!conf.isMetricsEnable()) {
Expand All @@ -58,16 +57,16 @@ public static MetricsServer getInstance(TiConfiguration conf) {

private MetricsServer(int port) {
try {
this.collectorRegistry = new CollectorRegistry();
this.collectorRegistry.register(RawKVClient.RAW_REQUEST_LATENCY);
this.collectorRegistry.register(RawKVClient.RAW_REQUEST_FAILURE);
this.collectorRegistry.register(RawKVClient.RAW_REQUEST_SUCCESS);
this.collectorRegistry.register(RegionStoreClient.GRPC_RAW_REQUEST_LATENCY);
this.collectorRegistry.register(RetryPolicy.GRPC_SINGLE_REQUEST_LATENCY);
this.collectorRegistry.register(RegionManager.GET_REGION_BY_KEY_REQUEST_LATENCY);
this.collectorRegistry.register(PDClient.PD_GET_REGION_BY_KEY_REQUEST_LATENCY);
CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(RawKVClient.RAW_REQUEST_LATENCY);
collectorRegistry.register(RawKVClient.RAW_REQUEST_FAILURE);
collectorRegistry.register(RawKVClient.RAW_REQUEST_SUCCESS);
collectorRegistry.register(RegionStoreClient.GRPC_RAW_REQUEST_LATENCY);
collectorRegistry.register(RetryPolicy.GRPC_SINGLE_REQUEST_LATENCY);
collectorRegistry.register(RegionManager.GET_REGION_BY_KEY_REQUEST_LATENCY);
collectorRegistry.register(PDClient.PD_GET_REGION_BY_KEY_REQUEST_LATENCY);
this.port = port;
this.server = new HTTPServer(new InetSocketAddress(port), this.collectorRegistry, true);
this.server = new HTTPServer(new InetSocketAddress(port), collectorRegistry, true);
logger.info("http server is up " + this.server.getPort());
} catch (Exception e) {
logger.error("http server not up");
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/tikv/common/PDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void waitScatterRegionFinish(Metapb.Region region, BackOffer backOffer) {
"wait scatter region %d at key %s is %s",
region.getId(),
KeyUtils.formatBytes(resp.getDesc().toByteArray()),
resp.getStatus().toString()));
resp.getStatus()));
}
}
}
Expand Down Expand Up @@ -422,11 +422,9 @@ public synchronized void updateLeaderOrforwardFollower() {
logger.info(String.format("can not switch to new leader, try follower forward"));
List<Pdpb.Member> members = resp.getMembersList();

boolean hasReachNextMember = false;
// If we have not used follower forward, try the first follower.
if (pdClientWrapper != null && pdClientWrapper.getStoreAddress().equals(leaderUrlStr)) {
hasReachNextMember = true;
}
boolean hasReachNextMember =
pdClientWrapper != null && pdClientWrapper.getStoreAddress().equals(leaderUrlStr);

for (int i = 0; i < members.size() * 2; i++) {
Pdpb.Member member = members.get(i % members.size());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/tikv/common/TiConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private static ReplicaRead getReplicaRead(String key) {
private boolean showRowId = getBoolean(TIKV_SHOW_ROWID);
private String dbPrefix = get(TIKV_DB_PREFIX);
private KVMode kvMode = getKvMode(TIKV_KV_MODE);
private boolean enableGrpcForward = getBoolean(TIKV_ENABLE_GRPC_FORWARD);
private final boolean enableGrpcForward = getBoolean(TIKV_ENABLE_GRPC_FORWARD);

private int kvClientConcurrency = getInt(TIKV_KV_CLIENT_CONCURRENCY);
private ReplicaRead replicaRead = getReplicaRead(TIKV_REPLICA_READ);
Expand All @@ -275,8 +275,8 @@ private static ReplicaRead getReplicaRead(String key) {

private boolean metricsEnable = getBoolean(TIKV_METRICS_ENABLE);
private int metricsPort = getInt(TIKV_METRICS_PORT);
private int grpcHealthCheckTimeout = getInt(TIKV_GRPC_HEALTH_CHECK_TIMEOUT);
private int healthCheckPeriodDuration = getInt(TIKV_HEALTH_CHECK_PERIOD_DURATION);
private final int grpcHealthCheckTimeout = getInt(TIKV_GRPC_HEALTH_CHECK_TIMEOUT);
private final int healthCheckPeriodDuration = getInt(TIKV_HEALTH_CHECK_PERIOD_DURATION);

private final String networkMappingName = get(TIKV_NETWORK_MAPPING_NAME);
private HostMapping hostMapping = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tikv/common/TiSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class TiSession implements AutoCloseable {
private volatile ImporterStoreClient.ImporterStoreClientBuilder importerClientBuilder;
private volatile boolean isClosed = false;
private volatile SwitchTiKVModeClient switchTiKVModeClient;
private MetricsServer metricsServer;
private final MetricsServer metricsServer;
private static final int MAX_SPLIT_REGION_STACK_DEPTH = 6;

public TiSession(TiConfiguration conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected Set<Integer> visit(ComparisonBinaryExpression node, LogicalBinaryExpre
NormalizedPredicate predicate = node.normalize();
if (predicate == null) {
throw new UnsupportedOperationException(
String.format("ComparisonBinaryExpression %s cannot be normalized", node.toString()));
String.format("ComparisonBinaryExpression %s cannot be normalized", node));
}
String colRefName = predicate.getColumnRef().getName();
List<Expression> partExprs = partExprsPerColumnRef.get(colRefName);
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/tikv/common/parser/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Expression visitDecimalLiteral(MySqlParser.DecimalLiteralContext ctx) {
return parseIntOrLongOrDec(val);
}

throw new UnsupportedSyntaxException(ctx.toString() + ": it is not supported.");
throw new UnsupportedSyntaxException(ctx + ": it is not supported.");
}

@Override
Expand All @@ -135,7 +135,7 @@ public Expression visitStringLiteral(MySqlParser.StringLiteralContext ctx) {
}
return Constant.create(sb.toString().replace("\"", ""));
}
throw new UnsupportedSyntaxException(ctx.toString() + " is not supported yet");
throw new UnsupportedSyntaxException(ctx + " is not supported yet");
}

@Override
Expand All @@ -161,7 +161,7 @@ public Expression visitConstant(MySqlParser.ConstantContext ctx) {
Doubles.tryParse(ctx.REAL_LITERAL().getSymbol().getText()), RealType.REAL);
}

throw new UnsupportedSyntaxException(ctx.toString() + "not supported constant");
throw new UnsupportedSyntaxException(ctx + "not supported constant");
}

@Override
Expand All @@ -187,8 +187,7 @@ public Expression visitBinaryComparisonPredicate(
return ComparisonBinaryExpression.greaterEqual(left, right);
}

throw new UnsupportedSyntaxException(
ctx.toString() + ": it is not possible reach to this line of code");
throw new UnsupportedSyntaxException(ctx + ": it is not possible reach to this line of code");
}

public Expression visitLogicalExpression(MySqlParser.LogicalExpressionContext ctx) {
Expand All @@ -203,8 +202,7 @@ public Expression visitLogicalExpression(MySqlParser.LogicalExpressionContext ct
return LogicalBinaryExpression.xor(visitChildren(left), visitChildren(right));
}

throw new UnsupportedSyntaxException(
ctx.toString() + ": it is not possible reach to this line of code");
throw new UnsupportedSyntaxException(ctx + ": it is not possible reach to this line of code");
}

@Override
Expand All @@ -222,6 +220,6 @@ public Expression visitMathExpressionAtom(MySqlParser.MathExpressionAtomContext
case "div":
return ArithmeticBinaryExpression.divide(left, right);
}
throw new UnsupportedSyntaxException(ctx.toString() + ": it is not supported right now");
throw new UnsupportedSyntaxException(ctx + ": it is not supported right now");
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/tikv/common/policy/RetryPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public abstract class RetryPolicy<RespT> {
.register();

// handles PD and TiKV's error.
private ErrorHandler<RespT> handler;
private final ErrorHandler<RespT> handler;

private ImmutableSet<Status.Code> unrecoverableStatus =
private final ImmutableSet<Status.Code> unrecoverableStatus =
ImmutableSet.of(
Status.Code.ALREADY_EXISTS, Status.Code.PERMISSION_DENIED,
Status.Code.INVALID_ARGUMENT, Status.Code.NOT_FOUND,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/tikv/common/region/RegionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Pair<TiRegion, TiStore> getRegionStorePairByKey(
ByteString key, TiStoreType storeType, BackOffer backOffer) {
TiRegion region = getRegionByKey(key, backOffer);
if (!region.isValid()) {
throw new TiClientInternalException("Region invalid: " + region.toString());
throw new TiClientInternalException("Region invalid: " + region);
}

TiStore store = null;
Expand Down Expand Up @@ -181,7 +181,7 @@ public Pair<TiRegion, TiStore> getRegionStorePairByKey(

if (store == null) {
throw new TiClientInternalException(
"Cannot find valid store on " + storeType + " for region " + region.toString());
"Cannot find valid store on " + storeType + " for region " + region);
}

return Pair.create(region, store);
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/org/tikv/common/region/StoreHealthyChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
public class StoreHealthyChecker implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(StoreHealthyChecker.class);
private static final long MAX_CHECK_STORE_TOMBSTONE_TICK = 60;
private BlockingQueue<TiStore> taskQueue;
private final BlockingQueue<TiStore> taskQueue;
private final ChannelFactory channelFactory;
private final ReadOnlyPDClient pdClient;
private final RegionCache cache;
private long checkTombstoneTick;
private long timeout;
private final long timeout;

public StoreHealthyChecker(
ChannelFactory channelFactory, ReadOnlyPDClient pdClient, RegionCache cache, long timeout) {
Expand All @@ -37,11 +37,8 @@ public StoreHealthyChecker(
}

public boolean scheduleStoreHealthCheck(TiStore store) {
if (!this.taskQueue.add(store)) {
// add queue false, mark it reachable so that it can be put again.
return false;
}
return true;
// add queue false, mark it reachable so that it can be put again.
return this.taskQueue.add(store);
}

private List<TiStore> getValidStores() {
Expand All @@ -68,11 +65,7 @@ private boolean checkStoreHealth(TiStore store) {
HealthGrpc.newBlockingStub(channel).withDeadlineAfter(timeout, TimeUnit.MILLISECONDS);
HealthCheckRequest req = HealthCheckRequest.newBuilder().build();
HealthCheckResponse resp = stub.check(req);
if (resp.getStatus() == HealthCheckResponse.ServingStatus.SERVING) {
return true;
} else {
return false;
}
return resp.getStatus() == HealthCheckResponse.ServingStatus.SERVING;
} catch (Exception e) {
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/tikv/common/region/TiStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.tikv.kvproto.Metapb;

public class TiStore implements Serializable {
private static long MAX_FAIL_FORWARD_TIMES = 4;
private static final long MAX_FAIL_FORWARD_TIMES = 4;
private final Metapb.Store store;
private final Metapb.Store proxyStore;
private AtomicBoolean reachable;
private AtomicBoolean valid;
private AtomicLong failForwardCount;
private AtomicBoolean canForward;
private final AtomicBoolean reachable;
private final AtomicBoolean valid;
private final AtomicLong failForwardCount;
private final AtomicBoolean canForward;

public TiStore(Metapb.Store store) {
this.store = store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.tikv.kvproto.Errorpb;

public class StreamingResponse implements Iterable {
private Iterator<Coprocessor.Response> resultIterator;
private List<Coprocessor.Response> responseList;
private final Iterator<Coprocessor.Response> resultIterator;
private final List<Coprocessor.Response> responseList;

@SuppressWarnings("unchecked")
public StreamingResponse(Iterator resultIterator) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/tikv/raw/RawKVClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,9 @@ public class TikvIterator implements Iterator<KvPair> {

private Iterator<KvPair> iterator;

private ByteString startKey;
private ByteString endKey;
private boolean keyOnly;
private final ByteString startKey;
private final ByteString endKey;
private final boolean keyOnly;

private KvPair last;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tikv/txn/LockResolverClientV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private TxnStatus getTxnStatusFromLock(BackOffer bo, Lock lock, long callerStart
logger.warn(
String.format(
"lock txn not found, lock has expired, CallerStartTs=%d lock str=%s",
callerStartTS, lock.toString()));
callerStartTS, lock));
if (lock.getLockType() == Kvrpcpb.Op.PessimisticLock) {
return new TxnStatus();
}
Expand Down
Loading

0 comments on commit 37506fe

Please sign in to comment.