Skip to content

Commit

Permalink
More low-risk cleanup/refactoring
Browse files Browse the repository at this point in the history
- Move `DatabaseLogCtx` earlier in `_getOrAddDatabaseFromConfig` so we can identify which database init-related logging is for
- `t.Run`->`rt.Run` fixes (prevents panics with failing subtests)
- Minor rename and TODO comment for upcoming work
  • Loading branch information
bbrks committed Sep 20, 2024
1 parent 7b5a401 commit 50ffa43
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions db/design_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func stripSyncProperty(row *sgbucket.ViewRow) {
}

func InitializeViews(ctx context.Context, ds sgbucket.DataStore) error {
collection, ok := ds.(*base.Collection)
if ok && !collection.IsDefaultScopeCollection() {
return fmt.Errorf("Can not initialize views on a non default collection")
collection, isCBServerCollection := ds.(*base.Collection)
if isCBServerCollection && !collection.IsDefaultScopeCollection() {
return fmt.Errorf("Can not initialize views on a non-default Couchbase Server collection")
}

viewStore, ok := ds.(sgbucket.ViewStore)
Expand Down
1 change: 1 addition & 0 deletions db/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func InitializeIndexes(ctx context.Context, n1QLStore base.N1QLStore, options In
deferredIndexes := make([]string, 0)
for _, sgIndex := range sgIndexes {

// TODO CBG-2838: build list of indexes to create (with one GetIndexMeta call)
if !sgIndex.shouldCreate(options) {
base.DebugfCtx(ctx, base.KeyAll, "Skipping index: %s ...", sgIndex.simpleName)
continue
Expand Down
4 changes: 2 additions & 2 deletions rest/indextest/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestSyncGatewayStartupIndexes(t *testing.T) {
}

// tests sg_users index
t.Run("testUserQueries", func(t *testing.T) {
rt.Run("testUserQueries", func(t *testing.T) {
users := []string{"alice", "bob"}

for _, user := range users {
Expand All @@ -96,7 +96,7 @@ func TestSyncGatewayStartupIndexes(t *testing.T) {
})

// tests sg_roles index
t.Run("testRoleQueries", func(t *testing.T) {
rt.Run("testRoleQueries", func(t *testing.T) {
roles := []string{"roleA", "roleB"}

for _, role := range roles {
Expand Down
16 changes: 8 additions & 8 deletions rest/server_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ func (sc *ServerContext) _getOrAddDatabaseFromConfig(ctx context.Context, config
dbName = spec.BucketName
}

// Generate database context options from config and server context
contextOptions, err := dbcOptionsFromConfig(ctx, sc, &config.DbConfig, dbName)
if err != nil {
return nil, err
}
// set this early so we have dbName available in db-init related logging, before we have an actual database
ctx = base.DatabaseLogCtx(ctx, dbName, contextOptions.LoggingConfig)

defer func() {
if returnedError == nil {
return
Expand Down Expand Up @@ -777,14 +785,6 @@ func (sc *ServerContext) _getOrAddDatabaseFromConfig(ctx context.Context, config
return nil, err
}

// Generate database context options from config and server context
contextOptions, err := dbcOptionsFromConfig(ctx, sc, &config.DbConfig, dbName)
if err != nil {
return nil, err
}

ctx = base.DatabaseLogCtx(ctx, dbName, contextOptions.LoggingConfig)

contextOptions.UseViews = useViews

javascriptTimeout := getJavascriptTimeout(&config.DbConfig)
Expand Down

0 comments on commit 50ffa43

Please sign in to comment.