Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,23 @@ func NewClientWithConfig(ctx context.Context, project, instance string, config C
var connPoolErr error
enableBigtableConnPool := btopt.EnableBigtableConnectionPool()
if enableBigtableConnPool {
connPool, connPoolErr = btransport.NewBigtableChannelPool(defaultBigtableConnPoolSize, btopt.BigtableLoadBalancingStrategy(), func() (*grpc.ClientConn, error) {
return gtransport.Dial(ctx, o...)
})
fullInstanceName := fmt.Sprintf("projects/%s/instances/%s", project, instance)
connPool, connPoolErr = btransport.NewBigtableChannelPool(ctx,
defaultBigtableConnPoolSize,
btopt.LeastInFlight,
func() (*btransport.BigtableConn, error) {
grpcConn, err := gtransport.Dial(ctx, o...)
if err != nil {
return nil, err
}
return btransport.NewBigtableConn(grpcConn), nil
},
// options
btransport.WithInstanceName(fullInstanceName),
btransport.WithAppProfile(config.AppProfile),
btransport.WithFeatureFlagsMetadata(ffMD),
)

} else {
// use to regular ConnPool
connPool, connPoolErr = gtransport.DialPool(ctx, o...)
Expand Down
25 changes: 25 additions & 0 deletions bigtable/internal/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package option
import (
"context"
"fmt"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -201,3 +202,27 @@ func EnableBigtableConnectionPool() bool {
}
return enableBigtableConnPool
}

// Logf logs the given message to the given logger, or the standard logger if
// the given logger is nil.
func logf(logger *log.Logger, format string, v ...interface{}) {
if logger == nil {
log.Printf(format, v...)
} else {
logger.Printf(format, v...)
}
}

var debug = os.Getenv("CBT_ENABLE_DEBUG") == "true"

// Debugf logs the given message *only if* the global Debug flag is true.
// It reuses Logf to handle the nil logger logic and prepends "DEBUG: "
// to the message.
func Debugf(logger *log.Logger, format string, v ...interface{}) {
// Only log if the Debug flag is set
if debug {
// Prepend "DEBUG: " to the format string
debugFormat := "DEBUG: " + format
logf(logger, debugFormat, v...)
}
}
Loading
Loading