Skip to content
Merged
2 changes: 1 addition & 1 deletion base/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func ServerIsTLS(server string) bool {
// Equivalent to the old regexp: `^(walrus:|file:|/|\.)`
func ServerIsWalrus(server string) bool {
return strings.HasPrefix(server, "walrus:") ||
strings.HasPrefix(server, "rosmar:") ||
strings.HasPrefix(server, "rosmar") ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
strings.HasPrefix(server, "rosmar") ||
strings.HasPrefix(server, "rosmar:") ||

Can we leave this code the way it used to look?

strings.HasPrefix(server, "file:") ||
strings.HasPrefix(server, "/") ||
strings.HasPrefix(server, ".")
Expand Down
119 changes: 119 additions & 0 deletions rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3532,3 +3532,122 @@ func TestDisableAllowStarChannel(t *testing.T) {
assert.Error(t, err, errResp)
base.DebugfCtx(t.Context(), base.KeySGTest, "additional logs")
}

func TestUnsupportedServerConfigOptions(t *testing.T) {
tests := []struct {
name string
expectedConnStr string
kvBuffer int
dcpBuffer int
serverless bool
params string
}{
{
name: "serverless-no_query_param-no_unsupported_options",
serverless: true,
expectedConnStr: "?dcp_buffer_size=1048576&idle_http_connection_timeout=90000&kv_buffer_size=1048576&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
},
{
name: "non_serverless-no_query_param_and_no_unsupported_options",
serverless: false,
expectedConnStr: "?idle_http_connection_timeout=90000&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
},
{
name: "serverless-no_query_param-unsupported_options",
serverless: true,
expectedConnStr: "?dcp_buffer_size=3000&idle_http_connection_timeout=90000&kv_buffer_size=2000&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
dcpBuffer: 3000,
},
{
name: "non_serverless-no_query_param-unsupported_options",
serverless: false,
expectedConnStr: "?dcp_buffer_size=3000&idle_http_connection_timeout=90000&kv_buffer_size=2000&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
dcpBuffer: 3000,
},
{
name: "serverless-dcp_buffer_query_param-kv_buffer_unsupported_option",
serverless: true,
params: "?dcp_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=20&idle_http_connection_timeout=90000&kv_buffer_size=2000&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
},
{
name: "non_serverless-dcp_buffer_query_param-kv_buffer_unsupported_option",
serverless: false,
params: "?dcp_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=20&idle_http_connection_timeout=90000&kv_buffer_size=2000&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
},
{
name: "serverless-dcp_buffer_query_param-dcp_buffer_unsupported_option",
serverless: true,
params: "?dcp_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=20&idle_http_connection_timeout=90000&kv_buffer_size=1048576&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
dcpBuffer: 3000,
},
{
name: "non_serverless-dcp_buffer_query_param-dcp_buffer_unsupported_option",
serverless: false,
params: "?dcp_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=20&idle_http_connection_timeout=90000&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
dcpBuffer: 3000,
},
{
name: "serverless-kv_buffer_query_param-kv_buffer_unsupported_option",
serverless: true,
params: "?kv_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=1048576&idle_http_connection_timeout=90000&kv_buffer_size=20&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
},
{
name: "non_serverless-kv_buffer_query_param-kv_buffer_unsupported_option",
serverless: false,
params: "?kv_buffer_size=20",
expectedConnStr: "?idle_http_connection_timeout=90000&kv_buffer_size=20&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
kvBuffer: 2000,
},
{
name: "serverless-kv_buffer_query_param-dcp_buffer_unsupported_option",
serverless: true,
params: "?kv_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=3000&idle_http_connection_timeout=90000&kv_buffer_size=20&kv_pool_size=1&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
dcpBuffer: 3000,
},
{
name: "non_serverless-kv_buffer_query_param-dcp_buffer_unsupported_option",
serverless: false,
params: "?kv_buffer_size=20",
expectedConnStr: "?dcp_buffer_size=3000&idle_http_connection_timeout=90000&kv_buffer_size=20&kv_pool_size=2&max_idle_http_connections=64000&max_perhost_idle_http_connections=256",
dcpBuffer: 3000,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := base.TestCtx(t)
serverBase := "couchbases://example.com"
sc := &StartupConfig{
Bootstrap: BootstrapConfig{
Server: serverBase + test.params,
},
Unsupported: UnsupportedConfig{
Serverless: ServerlessConfig{
Enabled: base.Ptr(test.serverless),
},
},
}
dbConfig := &DatabaseConfig{
DbConfig: DbConfig{
Unsupported: &db.UnsupportedOptions{
KVBufferSize: test.kvBuffer,
DCPReadBuffer: test.dcpBuffer,
},
},
}
spec, err := GetBucketSpec(ctx, dbConfig, sc)
require.NoError(t, err)
require.Equal(t, serverBase+test.expectedConnStr, spec.Server)
})
}
}
10 changes: 8 additions & 2 deletions rest/server_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,14 @@ func GetBucketSpec(ctx context.Context, config *DatabaseConfig, serverConfig *St
} else {
server = serverConfig.Bootstrap.Server
}
if serverConfig.IsServerless() {
params := base.DefaultServerlessGoCBConnStringParams()

if !base.ServerIsWalrus(server) && server != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is production code so I'm cautious about modifying it, what's an example test that fails? It feels like we should define a Server in all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestDeleteDatabasePointingAtSameBucket kept failing if I did not add server != "". When I dug into it, the test tries to create a db on the same bucket.
When the createDB handler handles this request and then tries to setup the config passed here, it updates the config string to "" from nil, while inheriting the connection string from bootstrapConfig, here. Since this is a unit test, so we do not set the bootstrap config, therefore, I think it is expected for the Config.Server to be set to "".
This is why I added this additional check, I know this condition looks very suspicious, but I'm not not sure as to how else do I prevent the test from failing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight correction to my comment earlier,

while inheriting the connection string from bootstrapConfig, here. Since this is a unit test, so we do not set the bootstrap config, therefore, I think it is expected for the Config.Server to be set to "".

It does not inherit the existing Bootstrap config, instead it inherits an empty bootstrap config

var params *base.GoCBConnStringParams
if serverConfig.IsServerless() {
params = base.DefaultServerlessGoCBConnStringParams()
} else {
params = base.DefaultGoCBConnStringParams()
}
if config.Unsupported != nil {
if config.Unsupported.DCPReadBuffer != 0 {
params.DcpBufferSize = config.Unsupported.DCPReadBuffer
Expand Down
Loading