Skip to content

Commit c6773ce

Browse files
feat(bigtable): introduce prime() method and load counting based on unary,streaming and ability to remove connection (#13419)
no-op from sushanb#1 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent fc154ca commit c6773ce

File tree

5 files changed

+1645
-419
lines changed

5 files changed

+1645
-419
lines changed

bigtable/bigtable.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,23 @@ func NewClientWithConfig(ctx context.Context, project, instance string, config C
183183
var connPoolErr error
184184
enableBigtableConnPool := btopt.EnableBigtableConnectionPool()
185185
if enableBigtableConnPool {
186-
connPool, connPoolErr = btransport.NewBigtableChannelPool(defaultBigtableConnPoolSize, btopt.BigtableLoadBalancingStrategy(), func() (*grpc.ClientConn, error) {
187-
return gtransport.Dial(ctx, o...)
188-
})
186+
fullInstanceName := fmt.Sprintf("projects/%s/instances/%s", project, instance)
187+
connPool, connPoolErr = btransport.NewBigtableChannelPool(ctx,
188+
defaultBigtableConnPoolSize,
189+
btopt.BigtableLoadBalancingStrategy(),
190+
func() (*btransport.BigtableConn, error) {
191+
grpcConn, err := gtransport.Dial(ctx, o...)
192+
if err != nil {
193+
return nil, err
194+
}
195+
return btransport.NewBigtableConn(grpcConn), nil
196+
},
197+
// options
198+
btransport.WithInstanceName(fullInstanceName),
199+
btransport.WithAppProfile(config.AppProfile),
200+
btransport.WithFeatureFlagsMetadata(ffMD),
201+
)
202+
189203
} else {
190204
// use to regular ConnPool
191205
connPool, connPoolErr = gtransport.DialPool(ctx, o...)

bigtable/internal/option/option.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package option
2020
import (
2121
"context"
2222
"fmt"
23+
"log"
2324
"os"
2425
"strconv"
2526
"strings"
@@ -201,3 +202,27 @@ func EnableBigtableConnectionPool() bool {
201202
}
202203
return enableBigtableConnPool
203204
}
205+
206+
// Logf logs the given message to the given logger, or the standard logger if
207+
// the given logger is nil.
208+
func logf(logger *log.Logger, format string, v ...interface{}) {
209+
if logger == nil {
210+
log.Printf(format, v...)
211+
} else {
212+
logger.Printf(format, v...)
213+
}
214+
}
215+
216+
var debug = os.Getenv("CBT_ENABLE_DEBUG") == "true"
217+
218+
// Debugf logs the given message *only if* the global Debug flag is true.
219+
// It reuses Logf to handle the nil logger logic and prepends "DEBUG: "
220+
// to the message.
221+
func Debugf(logger *log.Logger, format string, v ...interface{}) {
222+
// Only log if the Debug flag is set
223+
if debug {
224+
// Prepend "DEBUG: " to the format string
225+
debugFormat := "DEBUG: " + format
226+
logf(logger, debugFormat, v...)
227+
}
228+
}

0 commit comments

Comments
 (0)