68
68
import com .google .common .base .Function ;
69
69
import com .google .common .base .MoreObjects ;
70
70
import com .google .common .base .Preconditions ;
71
- import com .google .common .base .Supplier ;
72
71
import com .google .common .collect .ImmutableList ;
73
72
import com .google .common .util .concurrent .ForwardingListenableFuture ;
74
73
import com .google .common .util .concurrent .ForwardingListenableFuture .SimpleForwardingListenableFuture ;
@@ -156,7 +155,8 @@ void maybeWaitOnMinSessions() {
156
155
}
157
156
}
158
157
159
- private abstract static class CachedResultSetSupplier implements Supplier <ResultSet > {
158
+ private abstract static class CachedResultSetSupplier
159
+ implements com .google .common .base .Supplier <ResultSet > {
160
160
161
161
private ResultSet cached ;
162
162
@@ -2265,7 +2265,6 @@ public String getName() {
2265
2265
@ Override
2266
2266
public void close () {
2267
2267
synchronized (lock ) {
2268
- numMultiplexedSessionsReleased ++;
2269
2268
if (lastException != null && isDatabaseOrInstanceNotFound (lastException )) {
2270
2269
SessionPool .this .resourceNotFoundException =
2271
2270
MoreObjects .firstNonNull (
@@ -2771,15 +2770,9 @@ enum Position {
2771
2770
@ GuardedBy ("lock" )
2772
2771
private long numSessionsAcquired = 0 ;
2773
2772
2774
- @ GuardedBy ("lock" )
2775
- private long numMultiplexedSessionsAcquired = 0 ;
2776
-
2777
2773
@ GuardedBy ("lock" )
2778
2774
private long numSessionsReleased = 0 ;
2779
2775
2780
- @ GuardedBy ("lock" )
2781
- private long numMultiplexedSessionsReleased = 0 ;
2782
-
2783
2776
@ GuardedBy ("lock" )
2784
2777
private long numIdleSessionsRemoved = 0 ;
2785
2778
@@ -2830,7 +2823,9 @@ static SessionPool createPool(
2830
2823
SessionClient sessionClient ,
2831
2824
TraceWrapper tracer ,
2832
2825
List <LabelValue > labelValues ,
2833
- Attributes attributes ) {
2826
+ Attributes attributes ,
2827
+ AtomicLong numMultiplexedSessionsAcquired ,
2828
+ AtomicLong numMultiplexedSessionsReleased ) {
2834
2829
final SessionPoolOptions sessionPoolOptions = spannerOptions .getSessionPoolOptions ();
2835
2830
2836
2831
// A clock instance is passed in {@code SessionPoolOptions} in order to allow mocking via tests.
@@ -2846,7 +2841,9 @@ static SessionPool createPool(
2846
2841
tracer ,
2847
2842
labelValues ,
2848
2843
spannerOptions .getOpenTelemetry (),
2849
- attributes );
2844
+ attributes ,
2845
+ numMultiplexedSessionsAcquired ,
2846
+ numMultiplexedSessionsReleased );
2850
2847
}
2851
2848
2852
2849
static SessionPool createPool (
@@ -2884,7 +2881,9 @@ static SessionPool createPool(
2884
2881
tracer ,
2885
2882
SPANNER_DEFAULT_LABEL_VALUES ,
2886
2883
openTelemetry ,
2887
- null );
2884
+ null ,
2885
+ new AtomicLong (),
2886
+ new AtomicLong ());
2888
2887
}
2889
2888
2890
2889
static SessionPool createPool (
@@ -2898,7 +2897,9 @@ static SessionPool createPool(
2898
2897
TraceWrapper tracer ,
2899
2898
List <LabelValue > labelValues ,
2900
2899
OpenTelemetry openTelemetry ,
2901
- Attributes attributes ) {
2900
+ Attributes attributes ,
2901
+ AtomicLong numMultiplexedSessionsAcquired ,
2902
+ AtomicLong numMultiplexedSessionsReleased ) {
2902
2903
SessionPool pool =
2903
2904
new SessionPool (
2904
2905
poolOptions ,
@@ -2912,7 +2913,9 @@ static SessionPool createPool(
2912
2913
tracer ,
2913
2914
labelValues ,
2914
2915
openTelemetry ,
2915
- attributes );
2916
+ attributes ,
2917
+ numMultiplexedSessionsAcquired ,
2918
+ numMultiplexedSessionsReleased );
2916
2919
pool .initPool ();
2917
2920
return pool ;
2918
2921
}
@@ -2929,7 +2932,9 @@ private SessionPool(
2929
2932
TraceWrapper tracer ,
2930
2933
List <LabelValue > labelValues ,
2931
2934
OpenTelemetry openTelemetry ,
2932
- Attributes attributes ) {
2935
+ Attributes attributes ,
2936
+ AtomicLong numMultiplexedSessionsAcquired ,
2937
+ AtomicLong numMultiplexedSessionsReleased ) {
2933
2938
this .options = options ;
2934
2939
this .databaseRole = databaseRole ;
2935
2940
this .executorFactory = executorFactory ;
@@ -2940,8 +2945,13 @@ private SessionPool(
2940
2945
this .initialReleasePosition = initialReleasePosition ;
2941
2946
this .poolMaintainer = new PoolMaintainer ();
2942
2947
this .tracer = tracer ;
2943
- this .initOpenCensusMetricsCollection (metricRegistry , labelValues );
2944
- this .initOpenTelemetryMetricsCollection (openTelemetry , attributes );
2948
+ this .initOpenCensusMetricsCollection (
2949
+ metricRegistry ,
2950
+ labelValues ,
2951
+ numMultiplexedSessionsAcquired ,
2952
+ numMultiplexedSessionsReleased );
2953
+ this .initOpenTelemetryMetricsCollection (
2954
+ openTelemetry , attributes , numMultiplexedSessionsAcquired , numMultiplexedSessionsReleased );
2945
2955
this .waitOnMinSessionsLatch =
2946
2956
options .getMinSessions () > 0 ? new CountDownLatch (1 ) : new CountDownLatch (0 );
2947
2957
this .waitOnMultiplexedSessionsLatch = new CountDownLatch (1 );
@@ -3143,7 +3153,7 @@ boolean isValid() {
3143
3153
3144
3154
/**
3145
3155
* Returns a multiplexed session. The method fallbacks to a regular session if {@link
3146
- * SessionPoolOptions#useMultiplexedSession } is not set.
3156
+ * SessionPoolOptions#getUseMultiplexedSession } is not set.
3147
3157
*/
3148
3158
SessionFutureWrapper getMultiplexedSessionWithFallback () throws SpannerException {
3149
3159
if (useMultiplexedSessions ()) {
@@ -3250,8 +3260,6 @@ private void incrementNumSessionsInUse(boolean isMultiplexed) {
3250
3260
maxSessionsInUse = numSessionsInUse ;
3251
3261
}
3252
3262
numSessionsAcquired ++;
3253
- } else {
3254
- numMultiplexedSessionsAcquired ++;
3255
3263
}
3256
3264
}
3257
3265
}
@@ -3775,7 +3783,10 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount
3775
3783
* exporter, it allows users to monitor client behavior.
3776
3784
*/
3777
3785
private void initOpenCensusMetricsCollection (
3778
- MetricRegistry metricRegistry , List <LabelValue > labelValues ) {
3786
+ MetricRegistry metricRegistry ,
3787
+ List <LabelValue > labelValues ,
3788
+ AtomicLong numMultiplexedSessionsAcquired ,
3789
+ AtomicLong numMultiplexedSessionsReleased ) {
3779
3790
if (!SpannerOptions .isEnabledOpenCensusMetrics ()) {
3780
3791
return ;
3781
3792
}
@@ -3860,18 +3871,14 @@ private void initOpenCensusMetricsCollection(
3860
3871
labelValuesWithRegularSessions , this , sessionPool -> sessionPool .numSessionsAcquired );
3861
3872
numAcquiredSessionsMetric .removeTimeSeries (labelValuesWithMultiplexedSessions );
3862
3873
numAcquiredSessionsMetric .createTimeSeries (
3863
- labelValuesWithMultiplexedSessions ,
3864
- this ,
3865
- sessionPool -> sessionPool .numMultiplexedSessionsAcquired );
3874
+ labelValuesWithMultiplexedSessions , this , unused -> numMultiplexedSessionsAcquired .get ());
3866
3875
3867
3876
numReleasedSessionsMetric .removeTimeSeries (labelValuesWithRegularSessions );
3868
3877
numReleasedSessionsMetric .createTimeSeries (
3869
3878
labelValuesWithRegularSessions , this , sessionPool -> sessionPool .numSessionsReleased );
3870
3879
numReleasedSessionsMetric .removeTimeSeries (labelValuesWithMultiplexedSessions );
3871
3880
numReleasedSessionsMetric .createTimeSeries (
3872
- labelValuesWithMultiplexedSessions ,
3873
- this ,
3874
- sessionPool -> sessionPool .numMultiplexedSessionsReleased );
3881
+ labelValuesWithMultiplexedSessions , this , unused -> numMultiplexedSessionsReleased .get ());
3875
3882
3876
3883
List <LabelValue > labelValuesWithBeingPreparedType = new ArrayList <>(labelValues );
3877
3884
labelValuesWithBeingPreparedType .add (NUM_SESSIONS_BEING_PREPARED );
@@ -3909,7 +3916,10 @@ private void initOpenCensusMetricsCollection(
3909
3916
* an exporter, it allows users to monitor client behavior.
3910
3917
*/
3911
3918
private void initOpenTelemetryMetricsCollection (
3912
- OpenTelemetry openTelemetry , Attributes attributes ) {
3919
+ OpenTelemetry openTelemetry ,
3920
+ Attributes attributes ,
3921
+ AtomicLong numMultiplexedSessionsAcquired ,
3922
+ AtomicLong numMultiplexedSessionsReleased ) {
3913
3923
if (openTelemetry == null || !SpannerOptions .isEnabledOpenTelemetryMetrics ()) {
3914
3924
return ;
3915
3925
}
@@ -3981,7 +3991,8 @@ private void initOpenTelemetryMetricsCollection(
3981
3991
.buildWithCallback (
3982
3992
measurement -> {
3983
3993
measurement .record (this .numSessionsAcquired , attributesRegularSession );
3984
- measurement .record (this .numMultiplexedSessionsAcquired , attributesMultiplexedSession );
3994
+ measurement .record (
3995
+ numMultiplexedSessionsAcquired .get (), attributesMultiplexedSession );
3985
3996
});
3986
3997
3987
3998
meter
@@ -3991,7 +4002,8 @@ private void initOpenTelemetryMetricsCollection(
3991
4002
.buildWithCallback (
3992
4003
measurement -> {
3993
4004
measurement .record (this .numSessionsReleased , attributesRegularSession );
3994
- measurement .record (this .numMultiplexedSessionsReleased , attributesMultiplexedSession );
4005
+ measurement .record (
4006
+ numMultiplexedSessionsReleased .get (), attributesMultiplexedSession );
3995
4007
});
3996
4008
}
3997
4009
}
0 commit comments