Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ceresdb-protocol/src/main/java/io/ceresdb/CeresDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ private static RpcClient initRpcClient(final CeresDBOptions opts) {
private static RouterClient initRouteClient(final CeresDBOptions opts, final RpcClient rpcClient) {
final RouterOptions routerOpts = opts.getRouterOptions();
routerOpts.setRpcClient(rpcClient);
final RouterClient routerClient = new RouterClient();
final RouterClient routerClient = routerOpts.getRouteMode().equals(RouteMode.CLUSTER) ? new RouterClient() :
new StandaloneRouterClient();
if (!routerClient.init(routerOpts)) {
throw new IllegalStateException("Fail to start router client");
}
Expand Down
35 changes: 35 additions & 0 deletions ceresdb-protocol/src/main/java/io/ceresdb/RouteMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 io.ceresdb;

/**
* route mode
* @author lee
* @version : RouteMode.java, v 0.1 2023.01.17 14:23 lee Exp $
*/
public enum RouteMode {

/**
* In this mode, the client does not cache routing information and each request is proxied through the server to the correct server
*/
STANDALONE,

/**
* In this mode, the client cache routing information. Client find the correct server firstly, and then request to the correct server directly.
*/
CLUSTER
}
8 changes: 4 additions & 4 deletions ceresdb-protocol/src/main/java/io/ceresdb/RouterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public class RouterClient implements Lifecycle<RouterOptions>, Display, Iterable
private ScheduledExecutorService cleaner;
private ScheduledExecutorService refresher;

private RouterOptions opts;
private RpcClient rpcClient;
private RouterByMetrics router;
private InnerMetrics metrics;
protected RouterOptions opts;
protected RpcClient rpcClient;
protected RouterByMetrics router;
protected InnerMetrics metrics;

private final ConcurrentMap<String, Route> routeCache = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 io.ceresdb;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
* A route rpc client which cached nothing about table information, and return
* clusterAddress directly
* @author lee
*/
public class StandaloneRouterClient extends RouterClient {

public CompletableFuture<Map<String, Route>> routeFor(final Collection<String> metrics) {
if (metrics == null || metrics.isEmpty()) {
return Utils.completedCf(Collections.emptyMap());
}

final Map<String, Route> routeMap = new HashMap<>();

metrics.forEach(metric -> {
Route route = new Route();
route.setEndpoint(this.opts.getClusterAddress());
route.setMetric(metric);
routeMap.put(metric, route);
});
return Utils.completedCf(routeMap);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.Executor;

import io.ceresdb.LimitedPolicy;
import io.ceresdb.RouteMode;
import io.ceresdb.common.Copiable;
import io.ceresdb.common.Endpoint;
import io.ceresdb.common.Tenant;
Expand Down Expand Up @@ -237,6 +238,11 @@ public static final class Builder {
// all route tables are refreshed every 30 seconds.
private long routeTableRefreshPeriodSeconds = 30;

/** Route mode for request
@see RouteMode
**/
private RouteMode routeMode = RouteMode.CLUSTER;

public Builder(Endpoint clusterAddress) {
this.clusterAddress = clusterAddress;
}
Expand Down Expand Up @@ -432,6 +438,18 @@ public Builder routeTableRefreshPeriodSeconds(final long routeTableRefreshPeriod
return this;
}

/**
* Route mode for request
* @see RouteMode
*
* @param routeMode route mode for request
* @return this builder
*/
public Builder routeMode(final RouteMode routeMode) {
this.routeMode = routeMode;
return this;
}

/**
* A good start, happy coding.
*
Expand All @@ -449,6 +467,8 @@ public CeresDBOptions build() {
opts.routerOptions.setMaxCachedSize(this.routeTableMaxCachedSize);
opts.routerOptions.setGcPeriodSeconds(this.routeTableGcPeriodSeconds);
opts.routerOptions.setRefreshPeriodSeconds(this.routeTableRefreshPeriodSeconds);
opts.routerOptions.setRouteMode(this.routeMode);

opts.writeOptions = new WriteOptions();
opts.writeOptions.setMaxWriteSize(this.maxWriteSize);
opts.writeOptions.setMaxRetries(this.writeMaxRetries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.ceresdb.options;

import io.ceresdb.RouteMode;
import io.ceresdb.common.Copiable;
import io.ceresdb.common.Endpoint;
import io.ceresdb.rpc.RpcClient;
Expand All @@ -38,6 +39,8 @@ public class RouterOptions implements Copiable<RouterOptions> {
// all route tables are refreshed every 30 seconds.
private long refreshPeriodSeconds = 30;

private RouteMode routeMode = RouteMode.CLUSTER;

public RpcClient getRpcClient() {
return rpcClient;
}
Expand Down Expand Up @@ -78,6 +81,14 @@ public void setRefreshPeriodSeconds(long refreshPeriodSeconds) {
this.refreshPeriodSeconds = refreshPeriodSeconds;
}

public RouteMode getRouteMode() {
return routeMode;
}

public void setRouteMode(RouteMode routeMode) {
this.routeMode = routeMode;
}

@Override
public RouterOptions copy() {
final RouterOptions opts = new RouterOptions();
Expand All @@ -86,6 +97,7 @@ public RouterOptions copy() {
opts.maxCachedSize = this.maxCachedSize;
opts.gcPeriodSeconds = this.gcPeriodSeconds;
opts.refreshPeriodSeconds = this.refreshPeriodSeconds;
opts.routeMode = this.routeMode;
return opts;
}

Expand All @@ -97,6 +109,8 @@ public String toString() {
", maxCachedSize=" + maxCachedSize + //
", gcPeriodSeconds=" + gcPeriodSeconds + //
", refreshPeriodSeconds=" + refreshPeriodSeconds + //
", routeMode=" + routeMode + //
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import io.ceresdb.CeresDBClient;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down