From 1e011231808f98e0d5be065b9f6a9b8636f71ec7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Dec 2018 09:58:51 -0500 Subject: [PATCH 1/4] Fixed Issue - shutting-down WatchDog daemon threads spawned by Spanner client --- .../cloud/spanner/spi/v1/GapicSpannerRpc.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index 607f3fd3e41a..63a7fc738745 100644 --- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -103,10 +103,7 @@ import io.grpc.Context; import java.util.List; import java.util.Map; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import java.util.concurrent.*; import javax.annotation.Nullable; import org.threeten.bp.Duration; @@ -139,6 +136,7 @@ public class GapicSpannerRpc implements SpannerRpc { private final Duration checkInterval = systemProperty(PROPERTY_PERIOD_SECONDS, DEFAULT_PERIOD_SECONDS); + private final ScheduledExecutorService spannerWatchdog; public static GapicSpannerRpc create(SpannerOptions options) { return new GapicSpannerRpc(options); } @@ -191,14 +189,13 @@ public GapicSpannerRpc(SpannerOptions options) { CredentialsProvider credentialsProvider = GrpcTransportOptions.setUpCredentialsProvider(options); + spannerWatchdog = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() + .setDaemon(true) + .setNameFormat("RK-Cloud-Spanner-WatchdogProvider-%d") + .build()); WatchdogProvider watchdogProvider = InstantiatingWatchdogProvider.create() - .withExecutor( - Executors.newSingleThreadScheduledExecutor( - new ThreadFactoryBuilder() - .setDaemon(true) - .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") - .build())) + .withExecutor(spannerWatchdog) .withCheckInterval(checkInterval) .withClock(NanoClock.getDefaultClock()); @@ -572,6 +569,7 @@ public void shutdown() { this.spannerStub.close(); this.instanceAdminStub.close(); this.databaseAdminStub.close(); + this.spannerWatchdog.shutdown(); } /** From 9bdd44c59a4482972cf63a1e8ee556f6536aa0db Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Dec 2018 10:27:24 -0500 Subject: [PATCH 2/4] Fixed Issue - shutdown watchDog daemon threads spawned by Spanner client --- .../com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index 63a7fc738745..506dac84d50e 100644 --- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -103,7 +103,11 @@ import io.grpc.Context; import java.util.List; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import javax.annotation.Nullable; import org.threeten.bp.Duration; @@ -191,7 +195,7 @@ public GapicSpannerRpc(SpannerOptions options) { spannerWatchdog = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() .setDaemon(true) - .setNameFormat("RK-Cloud-Spanner-WatchdogProvider-%d") + .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") .build()); WatchdogProvider watchdogProvider = InstantiatingWatchdogProvider.create() From eff50d15487e4609602228455b6f41fa30e5a922 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Dec 2018 09:27:06 -0500 Subject: [PATCH 3/4] Minor code formatting --- .../java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index 506dac84d50e..dcdeff1d54b4 100644 --- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -141,6 +141,7 @@ public class GapicSpannerRpc implements SpannerRpc { systemProperty(PROPERTY_PERIOD_SECONDS, DEFAULT_PERIOD_SECONDS); private final ScheduledExecutorService spannerWatchdog; + public static GapicSpannerRpc create(SpannerOptions options) { return new GapicSpannerRpc(options); } From 235f85f360c112e26e827feb11d89244afc3ec93 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Dec 2018 14:16:56 -0500 Subject: [PATCH 4/4] Fixed Kokoro code format issue --- .../google/cloud/spanner/spi/v1/GapicSpannerRpc.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index dcdeff1d54b4..5469699abd63 100644 --- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -104,10 +104,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CancellationException; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nullable; import org.threeten.bp.Duration; @@ -194,10 +194,12 @@ public GapicSpannerRpc(SpannerOptions options) { CredentialsProvider credentialsProvider = GrpcTransportOptions.setUpCredentialsProvider(options); - spannerWatchdog = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() - .setDaemon(true) - .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") - .build()); + spannerWatchdog = + Executors.newSingleThreadScheduledExecutor( + new ThreadFactoryBuilder() + .setDaemon(true) + .setNameFormat("Cloud-Spanner-WatchdogProvider-%d") + .build()); WatchdogProvider watchdogProvider = InstantiatingWatchdogProvider.create() .withExecutor(spannerWatchdog)