Skip to content

Commit 1407bec

Browse files
committed
refactor channel health checking structure
Change-Id: I6857b40fa9a08d101b896470eaa7abdd9740c3e9
1 parent 243a5dd commit 1407bec

3 files changed

Lines changed: 68 additions & 126 deletions

File tree

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public class BigtableChannelPool extends ManagedChannel {
6161
private final BigtableChannelPoolSettings settings;
6262
private final ChannelFactory channelFactory;
6363
private final ScheduledExecutorService executor;
64-
private final ScheduledExecutorService channelHealthProbingExecutor =
65-
Executors.newSingleThreadScheduledExecutor();
6664

6765
private final Object entryWriteLock = new Object();
6866
@VisibleForTesting final AtomicReference<ImmutableList<Entry>> entries = new AtomicReference<>();
@@ -97,7 +95,7 @@ public static BigtableChannelPool create(
9795

9896
for (int i = 0; i < settings.getInitialChannelCount(); i++) {
9997
initialListBuilder.add(
100-
new Entry(channelFactory.createSingleChannel(), channelHealthProbingExecutor));
98+
new Entry(channelFactory.createSingleChannel()));
10199
}
102100

103101
entries.set(initialListBuilder.build());
@@ -155,9 +153,6 @@ public ManagedChannel shutdown() {
155153
// shutdownNow will cancel scheduled tasks
156154
executor.shutdownNow();
157155
}
158-
if (channelHealthProbingExecutor != null) {
159-
channelHealthProbingExecutor.shutdownNow();
160-
}
161156
return this;
162157
}
163158

@@ -198,9 +193,6 @@ public ManagedChannel shutdownNow() {
198193
if (executor != null) {
199194
executor.shutdownNow();
200195
}
201-
if (channelHealthProbingExecutor != null) {
202-
channelHealthProbingExecutor.shutdownNow();
203-
}
204196
return this;
205197
}
206198

@@ -328,7 +320,7 @@ private void expand(int desiredSize) {
328320
for (int i = 0; i < desiredSize - localEntries.size(); i++) {
329321
try {
330322
newEntries.add(
331-
new Entry(channelFactory.createSingleChannel(), channelHealthProbingExecutor));
323+
new Entry(channelFactory.createSingleChannel()));
332324
} catch (IOException e) {
333325
LOG.log(Level.WARNING, "Failed to add channel", e);
334326
}
@@ -367,7 +359,7 @@ void refresh() {
367359
for (int i = 0; i < newEntries.size(); i++) {
368360
try {
369361
newEntries.set(
370-
i, new Entry(channelFactory.createSingleChannel(), channelHealthProbingExecutor));
362+
i, new Entry(channelFactory.createSingleChannel()));
371363
} catch (IOException e) {
372364
LOG.log(Level.WARNING, "Failed to refresh channel, leaving old channel", e);
373365
}
@@ -445,26 +437,38 @@ static class Entry {
445437
private final AtomicInteger maxOutstanding = new AtomicInteger();
446438
private final AtomicInteger probesInFlight = new AtomicInteger(0);
447439

440+
/** Number of probes in flight plus number of probe results. (No-op stub) */
441+
AtomicInteger recentProbesSent() {
442+
return new AtomicInteger(0);
443+
}
444+
445+
/** Number of recently failed probes. (No-op stub) */
446+
AtomicInteger recentlyFailedProbes() {
447+
return new AtomicInteger(0);
448+
}
449+
450+
/**
451+
* Determines if the channel is healthy. (No-op stub)
452+
*
453+
* @return A default value of true.
454+
*/
455+
public boolean healthy() {
456+
return true;
457+
}
458+
448459
// Flag that the channel should be closed once all of the outstanding RPC complete.
449460
private final AtomicBoolean shutdownRequested = new AtomicBoolean();
450461
// Flag that the channel has been closed.
451462
private final AtomicBoolean shutdownInitiated = new AtomicBoolean();
452-
private final ChannelHealthChecker healthChecker;
453463

454-
private Entry(ManagedChannel channel, ScheduledExecutorService executor) {
464+
private Entry(ManagedChannel channel) {
455465
this.channel = channel;
456-
this.healthChecker = new ChannelHealthChecker(this, executor);
457466
}
458467

459468
ManagedChannel getManagedChannel() {
460469
return this.channel;
461470
}
462471

463-
// Add a getter for the healthChecker
464-
public ChannelHealthChecker getHealthChecker() {
465-
return healthChecker;
466-
}
467-
468472
int getAndResetMaxOutstanding() {
469473
return maxOutstanding.getAndSet(outstandingRpcs.get());
470474
}

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

Lines changed: 0 additions & 106 deletions
This file was deleted.

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
/** Stub for a class that will manage the health checking in the BigtableChannelPool */
2727
public class ChannelPoolHealthChecker {
2828

29+
// Configuration constants
30+
private static final int WINDOW_DURATION_MINUTES = 5;
31+
private static final int PROBE_RATE_SECONDS = 30;
32+
private static final int PROBE_DEADLINE_MILLISECONDS = 500;
33+
private static final int MIN_PROBES_FOR_EVALUATION = 4;
34+
private static final int FAILURE_PERCENT_THRESHOLD = 60;
35+
36+
/** Inner class to represent the result of a single probe. */
37+
class ProbeResult {
38+
final Instant startTime;
39+
final boolean success;
40+
41+
ProbeResult(Instant startTime, boolean success) {
42+
this.startTime = startTime;
43+
this.success = success;
44+
}
45+
46+
public boolean isSuccessful() {
47+
return success;
48+
}
49+
}
50+
2951
// Class fields
3052
private final Supplier<ImmutableList<Entry>> entrySupplier;
3153
private Instant lastEviction;
@@ -36,7 +58,26 @@ public ChannelPoolHealthChecker(Supplier<ImmutableList<Entry>> entrySupplier) {
3658
this.entrySupplier = entrySupplier;
3759
this.lastEviction = Instant.MIN;
3860
this.executor = Executors.newSingleThreadScheduledExecutor();
39-
// Scheduling for detectAndRemoveOutlierChannels goes here
61+
// Scheduling for runProbes and detectAndRemoveOutlierChannels goes here
62+
63+
}
64+
65+
/** Stop running health checking (No-op stub) */
66+
public void stop() {
67+
// Method stub, no operation.
68+
}
69+
70+
/** Runs probes on all the channels in the pool. (No-op stub) */
71+
private void runProbes() {
72+
// Method stub, no operation.
73+
for (Entry entry: this.entrySupplier.get()) {
74+
//pingAndWarm
75+
}
76+
}
77+
78+
/** Callback that will update Entry data on probe complete. (No-op stub) */
79+
private void onComplete() {
80+
4081
}
4182

4283
/**
@@ -52,5 +93,8 @@ private Entry findOutlierEntry() {
5293
/** Periodically detects and removes outlier channels from the pool. (No-op stub) */
5394
private void detectAndRemoveOutlierEntries() {
5495
// Method stub, no operation.
96+
for (Entry entry: this.entrySupplier.get()) {
97+
//if not healthy, enterIdle
98+
}
5599
}
56100
}

0 commit comments

Comments
 (0)