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

fix: use default endpint while route is empty #43

Merged
merged 1 commit into from
Feb 28, 2023
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
2 changes: 0 additions & 2 deletions ceresdb-example/src/test/java/io/ceresdb/CeresDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
*/
package io.ceresdb;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down
14 changes: 7 additions & 7 deletions ceresdb-protocol/src/main/java/io/ceresdb/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.ceresdb.common.util.Clock;

/**
* Route info for metric.
* Route info for table.
*
*/
public class Route {
Expand All @@ -18,21 +18,21 @@ public class Route {
private Object ext;
private final AtomicLong lastHit = new AtomicLong(Clock.defaultClock().getTick());

public static Route invalid(final String metric) {
throw new IllegalStateException("Unexpected, invalid route for metric: " + metric);
public static Route invalid(final String table) {
throw new IllegalStateException("Unexpected, invalid route for table: " + table);
}

public static Route of(final Endpoint endpoint) {
return of(null, endpoint, null);
}

public static Route of(final String metric, final Endpoint endpoint) {
return of(metric, endpoint, null);
public static Route of(final String table, final Endpoint endpoint) {
return of(table, endpoint, null);
}

public static Route of(final String metric, final Endpoint endpoint, final Object ext) {
public static Route of(final String table, final Endpoint endpoint, final Object ext) {
final Route r = new Route();
r.table = metric;
r.table = table;
r.endpoint = endpoint;
r.ext = ext;
return r;
Expand Down
4 changes: 3 additions & 1 deletion ceresdb-protocol/src/main/java/io/ceresdb/RouterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public CompletableFuture<Map<String, Route>> routeFor(final RequestContext reqCt
ret = remote;
} else {
local.putAll(remote);
for (String miss : misses) {
local.putIfAbsent(miss, Route.of(miss, opts.getClusterAddress()));
}
ret = local;
}
return ret;
Expand All @@ -197,7 +200,6 @@ public CompletableFuture<Map<String, Route>> routeFor(final RequestContext reqCt

public CompletableFuture<Map<String, Route>> routeRefreshFor(final RequestContext reqCtx,
final Collection<String> tables) {
final long startCall = Clock.defaultClock().getTick();
return this.router.routeFor(reqCtx, tables).whenComplete((remote, err) -> {
if (err == null) {
this.routeCache.putAll(remote);
Expand Down
2 changes: 1 addition & 1 deletion ceresdb-protocol/src/main/java/io/ceresdb/WriteClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public StreamWriteBuf<Point, WriteOk> streamWrite(final RequestContext reqCtx, f

final CompletableFuture<WriteOk> respFuture = new CompletableFuture<>();

return this.routerClient.routeFor(reqCtx, Collections.singleton(table))
return this.routerClient.routeFor(finalReqCtx, Collections.singleton(table))
.thenApply(routes -> routes.values().stream().findFirst().orElseGet(() -> Route.invalid(table)))
.thenApply(route -> streamWriteTo(route, finalReqCtx, ctx, Utils.toUnaryObserver(respFuture)))
.thenApply(reqObserver -> new StreamWriteBuf<Point, WriteOk>() {
Expand Down