Skip to content

Commit 1cd5e4a

Browse files
committed
add stubs and make changes to BigtableChannelPool to allow for integration
Change-Id: I19dc8fa9d6b64f2f97b0784ec7ca8456b6b7442f
1 parent 9ad66b1 commit 1cd5e4a

3 files changed

Lines changed: 162 additions & 0 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class BigtableChannelPool extends ManagedChannel {
6565

6666
private final Object entryWriteLock = new Object();
6767
@VisibleForTesting final AtomicReference<ImmutableList<Entry>> entries = new AtomicReference<>();
68+
private final ChannelPoolHealthChecker channelPoolHealthChecker = new ChannelPoolHealthChecker(() -> entries.get());
6869
private final AtomicInteger indexTicker = new AtomicInteger();
6970
private final String authority;
7071

@@ -441,6 +442,10 @@ private Entry(ManagedChannel channel) {
441442
this.channel = channel;
442443
}
443444

445+
ManagedChannel getManagedChannel() {
446+
return this.channel;
447+
}
448+
444449
int getAndResetMaxOutstanding() {
445450
return maxOutstanding.getAndSet(outstandingRpcs.get());
446451
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.google.cloud.bigtable.gaxx.grpc;
2+
3+
import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool.Entry;
4+
import com.google.common.collect.EvictingQueue;
5+
import java.time.Instant;
6+
import java.util.concurrent.ScheduledExecutorService;
7+
import java.util.concurrent.ScheduledFuture;
8+
import java.util.concurrent.atomic.AtomicInteger;
9+
import java.util.concurrent.locks.ReadWriteLock;
10+
import java.util.concurrent.locks.ReentrantReadWriteLock;
11+
12+
/**
13+
* A class with harmless method stubs for health checking a channel.
14+
* The core implementation logic has been removed.
15+
*/
16+
public class ChannelHealthChecker {
17+
18+
// Configuration constants
19+
private static final int WINDOW_DURATION_MINUTES = 5;
20+
private static final int PROBE_RATE_SECONDS = 30;
21+
private static final int PROBE_DEADLINE_MILLISECONDS = 500;
22+
private static final int MIN_PROBES_FOR_EVALUATION = 4;
23+
private static final int FAILURE_PERCENT_THRESHOLD = 60;
24+
25+
// Class fields
26+
final Entry entry;
27+
private final ScheduledExecutorService probeExecutor;
28+
private volatile ScheduledFuture<?> scheduledProbeFuture;
29+
private final ReadWriteLock probeResultsLock = new ReentrantReadWriteLock();
30+
private final EvictingQueue<ProbeResult> probeResults;
31+
private final AtomicInteger probesInFlight = new AtomicInteger(0);
32+
33+
/**
34+
* Inner class to represent the result of a single probe.
35+
*/
36+
class ProbeResult {
37+
final Instant startTime;
38+
final boolean success;
39+
40+
ProbeResult(Instant startTime, boolean success) {
41+
this.startTime = startTime;
42+
this.success = success;
43+
}
44+
45+
public boolean isSuccessful() {
46+
return success;
47+
}
48+
}
49+
50+
/**
51+
* Constructor for the health checker.
52+
*/
53+
public ChannelHealthChecker(Entry entry, ScheduledExecutorService executor) {
54+
int queueCapacity = (WINDOW_DURATION_MINUTES * 60) / PROBE_RATE_SECONDS;
55+
this.probeResults = EvictingQueue.create(queueCapacity);
56+
this.entry = entry;
57+
this.probeExecutor = executor;
58+
// Scheduling runProbe will go here
59+
}
60+
61+
/**
62+
* Stops the health checking process. (No-op stub)
63+
*/
64+
public void stop() {
65+
// Method stub, no operation.
66+
}
67+
68+
/**
69+
* Runs a single health probe. (No-op stub)
70+
*/
71+
private void runProbe() {
72+
// Method stub, no operation.
73+
}
74+
75+
/**
76+
* Callback for when a probe finishes. (No-op stub)
77+
*/
78+
void probeFinished(Instant startTime, boolean success) {
79+
// Method stub, no operation.
80+
}
81+
82+
/**
83+
* Returns the number of recent probes sent. (No-op stub)
84+
* @return A default value of 0.
85+
*/
86+
private int recentProbesSent() {
87+
return 0;
88+
}
89+
90+
/**
91+
* Returns the number of recently failed probes. (No-op stub)
92+
* @return A default value of 0.
93+
*/
94+
public int recentlyFailedProbes() {
95+
return 0;
96+
}
97+
98+
/**
99+
* Determines if the channel is healthy. (No-op stub)
100+
* @return A default value of true.
101+
*/
102+
public boolean healthy() {
103+
return true;
104+
}
105+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.google.cloud.bigtable.gaxx.grpc;
2+
3+
import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPool.Entry;
4+
import com.google.common.collect.ImmutableList;
5+
import java.time.Duration;
6+
import java.time.Instant;
7+
import java.util.Collections;
8+
import java.util.Map;
9+
import java.util.WeakHashMap;
10+
import java.util.concurrent.Executors;
11+
import java.util.concurrent.ScheduledExecutorService;
12+
import java.util.function.Supplier;
13+
import javax.annotation.Nullable;
14+
15+
/**
16+
* Stub for a class that will manage the health checking in the BigtableChannelPool
17+
*/
18+
public class ChannelPoolHealthChecker {
19+
20+
// Class fields
21+
private final Supplier<ImmutableList<Entry>> entrySupplier;
22+
private Map<Entry, ChannelHealthChecker> healthCheckers;
23+
private Instant lastEviction;
24+
private ScheduledExecutorService executor;
25+
26+
/**
27+
* Constructor for the pool health checker.
28+
*/
29+
public ChannelPoolHealthChecker(Supplier<ImmutableList<Entry>> entrySupplier) {
30+
this.healthCheckers = Collections.synchronizedMap(new WeakHashMap<>());
31+
this.entrySupplier = entrySupplier;
32+
this.lastEviction = Instant.MIN;
33+
this.executor = Executors.newSingleThreadScheduledExecutor();
34+
// Scheduling for detectAndRemoveOutlierChannels goes here
35+
}
36+
37+
/**
38+
* Finds a channel that is an outlier in terms of health. (No-op stub)
39+
* @return A default value of null.
40+
*/
41+
@Nullable
42+
private Entry findOutlierEntry() {
43+
return null;
44+
}
45+
46+
/**
47+
* Periodically detects and removes outlier channels from the pool. (No-op stub)
48+
*/
49+
private void detectAndRemoveOutlierEntries() {
50+
// Method stub, no operation.
51+
}
52+
}

0 commit comments

Comments
 (0)