@@ -39,6 +39,19 @@ func newWriterClientConfig(opts ...option.ClientOption) *writerClientConfig {
39
39
wOpt .ApplyWriterOpt (conf )
40
40
}
41
41
}
42
+
43
+ // Normalize the config to ensure we're dealing with sane values.
44
+ if conf .useMultiplex {
45
+ if conf .maxMultiplexPoolSize < 1 {
46
+ conf .maxMultiplexPoolSize = 1
47
+ }
48
+ }
49
+ if conf .defaultInflightBytes < 0 {
50
+ conf .defaultInflightBytes = 0
51
+ }
52
+ if conf .defaultInflightRequests < 0 {
53
+ conf .defaultInflightRequests = 0
54
+ }
42
55
return conf
43
56
}
44
57
@@ -48,31 +61,55 @@ type writerClientOption interface {
48
61
ApplyWriterOpt (* writerClientConfig )
49
62
}
50
63
51
- // enableMultiplex enables multiplex behavior in the client.
52
- // maxSize indicates the maximum number of shared multiplex connections
53
- // in a given location/region
64
+ // WithMultiplexing is an EXPERIMENTAL option that controls connection sharing
65
+ // when instantiating the Client. Only writes to default streams can leverage the
66
+ // multiplex pool. Internally, the client maintains a pool of connections per BigQuery
67
+ // destination region, and will grow the pool to it's maximum allowed size if there's
68
+ // sufficient traffic on the shared connection(s).
54
69
//
55
- // TODO: export this as part of the multiplex feature launch .
56
- func enableMultiplex ( enable bool , maxSize int ) option.ClientOption {
57
- return & enableMultiplexSetting {useMultiplex : enable , maxSize : maxSize }
70
+ // This ClientOption is EXPERIMENTAL and subject to change .
71
+ func WithMultiplexing ( ) option.ClientOption {
72
+ return & enableMultiplexSetting {useMultiplex : true }
58
73
}
59
74
60
75
type enableMultiplexSetting struct {
61
76
internaloption.EmbeddableAdapter
62
77
useMultiplex bool
63
- maxSize int
64
78
}
65
79
66
80
func (s * enableMultiplexSetting ) ApplyWriterOpt (c * writerClientConfig ) {
67
81
c .useMultiplex = s .useMultiplex
82
+ }
83
+
84
+ // WithMultiplexPoolLimit is an EXPERIMENTAL option that sets the maximum
85
+ // shared multiplex pool size when instantiating the Client. If multiplexing
86
+ // is not enabled, this setting is ignored. By default, the limit is a single
87
+ // shared connection. This limit is applied per destination region.
88
+ //
89
+ // This ClientOption is EXPERIMENTAL and subject to change.
90
+ func WithMultiplexPoolLimit (maxSize int ) option.ClientOption {
91
+ return & maxMultiplexPoolSizeSetting {maxSize : maxSize }
92
+ }
93
+
94
+ type maxMultiplexPoolSizeSetting struct {
95
+ internaloption.EmbeddableAdapter
96
+ maxSize int
97
+ }
98
+
99
+ func (s * maxMultiplexPoolSizeSetting ) ApplyWriterOpt (c * writerClientConfig ) {
68
100
c .maxMultiplexPoolSize = s .maxSize
69
101
}
70
102
71
- // defaultMaxInflightRequests sets the default flow controller limit for requests for
72
- // all AppendRows connections created by this client.
103
+ // WithDefaultInflightRequests is an EXPERIMENTAL ClientOption for controlling
104
+ // the default limit of how many individual AppendRows write requests can
105
+ // be in flight on a connection at a time. This limit is enforced on all connections
106
+ // created by the instantiated Client.
73
107
//
74
- // TODO: export this as part of the multiplex feature launch.
75
- func defaultMaxInflightRequests (n int ) option.ClientOption {
108
+ // Note: the WithMaxInflightRequests WriterOption can still be used to control
109
+ // the behavior for individual ManagedStream writers when not using multiplexing.
110
+ //
111
+ // This ClientOption is EXPERIMENTAL and subject to change.
112
+ func WithDefaultInflightRequests (n int ) option.ClientOption {
76
113
return & defaultInflightRequestsSetting {maxRequests : n }
77
114
}
78
115
@@ -85,11 +122,16 @@ func (s *defaultInflightRequestsSetting) ApplyWriterOpt(c *writerClientConfig) {
85
122
c .defaultInflightRequests = s .maxRequests
86
123
}
87
124
88
- // defaultMaxInflightBytes sets the default flow controller limit for bytes for
89
- // all AppendRows connections created by this client.
125
+ // WithDefaultInflightBytes is an EXPERIMENTAL ClientOption for controlling
126
+ // the default byte limit for how many individual AppendRows write requests can
127
+ // be in flight on a connection at a time. This limit is enforced on all connections
128
+ // created by the instantiated Client.
129
+ //
130
+ // Note: the WithMaxInflightBytes WriterOption can still be used to control
131
+ // the behavior for individual ManagedStream writers when not using multiplexing.
90
132
//
91
- // TODO: export this as part of the multiplex feature launch .
92
- func defaultMaxInflightBytes (n int ) option.ClientOption {
133
+ // This ClientOption is EXPERIMENTAL and subject to change .
134
+ func WithDefaultInflightBytes (n int ) option.ClientOption {
93
135
return & defaultInflightBytesSetting {maxBytes : n }
94
136
}
95
137
@@ -102,11 +144,18 @@ func (s *defaultInflightBytesSetting) ApplyWriterOpt(c *writerClientConfig) {
102
144
c .defaultInflightBytes = s .maxBytes
103
145
}
104
146
105
- // defaultAppendRowsCallOptions sets a gax.CallOption passed when opening
106
- // the AppendRows bidi connection.
147
+ // WithDefaultAppendRowsCallOption is an EXPERIMENTAL ClientOption for controlling
148
+ // the gax.CallOptions passed when opening the underlying AppendRows bidi
149
+ // stream connections used by this library to communicate with the BigQuery
150
+ // Storage service. This option is propagated to all
151
+ // connections created by the instantiated Client.
107
152
//
108
- // TODO: export this as part of the multiplex feature launch.
109
- func defaultAppendRowsCallOption (o gax.CallOption ) option.ClientOption {
153
+ // Note: the WithAppendRowsCallOption WriterOption can still be used to control
154
+ // the behavior for individual ManagedStream writers that don't participate
155
+ // in multiplexing.
156
+ //
157
+ // This ClientOption is EXPERIMENTAL and subject to change.
158
+ func WithDefaultAppendRowsCallOption (o gax.CallOption ) option.ClientOption {
110
159
return & defaultAppendRowsCallOptionSetting {opt : o }
111
160
}
112
161
@@ -152,13 +201,21 @@ func WithDestinationTable(destTable string) WriterOption {
152
201
}
153
202
154
203
// WithMaxInflightRequests bounds the inflight appends on the write connection.
204
+ //
205
+ // Note: See the WithDefaultInflightRequests ClientOption for setting a default
206
+ // when instantiating a client, rather than setting this limit per-writer.
207
+ // This WriterOption is ignored for ManagedStreams that participate in multiplexing.
155
208
func WithMaxInflightRequests (n int ) WriterOption {
156
209
return func (ms * ManagedStream ) {
157
210
ms .streamSettings .MaxInflightRequests = n
158
211
}
159
212
}
160
213
161
214
// WithMaxInflightBytes bounds the inflight append request bytes on the write connection.
215
+ //
216
+ // Note: See the WithDefaultInflightBytes ClientOption for setting a default
217
+ // when instantiating a client, rather than setting this limit per-writer.
218
+ // This WriterOption is ignored for ManagedStreams that participate in multiplexing.
162
219
func WithMaxInflightBytes (n int ) WriterOption {
163
220
return func (ms * ManagedStream ) {
164
221
ms .streamSettings .MaxInflightBytes = n
@@ -191,6 +248,10 @@ func WithDataOrigin(dataOrigin string) WriterOption {
191
248
192
249
// WithAppendRowsCallOption is used to supply additional call options to the ManagedStream when
193
250
// it opens the underlying append stream.
251
+ //
252
+ // Note: See the DefaultAppendRowsCallOption ClientOption for setting defaults
253
+ // when instantiating a client, rather than setting this limit per-writer. This WriterOption
254
+ // is ignored for ManagedStream writers that participate in multiplexing.
194
255
func WithAppendRowsCallOption (o gax.CallOption ) WriterOption {
195
256
return func (ms * ManagedStream ) {
196
257
ms .streamSettings .appendCallOptions = append (ms .streamSettings .appendCallOptions , o )
0 commit comments