Skip to content

Comments

Decouple BucketSpec from DatabaseContext#8075

Merged
bbrks merged 1 commit intomainfrom
decouple-bucketspec
Feb 23, 2026
Merged

Decouple BucketSpec from DatabaseContext#8075
bbrks merged 1 commit intomainfrom
decouple-bucketspec

Conversation

@torcolvin
Copy link
Collaborator

Decouple BucketSpec from DatabaseContext

This fixes an issue where DatabaseContext.BucketSpec was only set by the initialization of NewDatabaseContext in server_context.go. This meant that a call like db.BucketSpec.IsWalrusBucket() would only be valid if called via server_context.go and not in the db package. This addresses problems running unit tests, but does not affect production code.

I am planning to add a check for using rosmar bucket to avoid sharded DCP code, and it was adding this code where I realized there was a problem.

I considered alternate approaches, and I'm open to these or others:

  1. Requiring BucketSpec as a parameter to DatabaseContextOptions. This would work but I would have had to modify more test code.
  2. Constructing a bucket spec inside NewDatabaseContext by either finding bucketSpec after type assertion to GocbV2Bucket or reconstructing the value from rosmar. The problem is that once a rosmar bucket has been opened, I would have to modify rosmar.Bucket to be able to find BucketSpec.Server
    bucket, err = rosmar.OpenBucketIn(spec.Server, spec.BucketName, rosmar.CreateOrOpen)
  3. Move BucketSpec code into sgbucket and add BucketStore.GetSpec interface. However, the BucketSpec is pretty much only gocb options, with the exception of Server (typically rosmar in memory URL, but can be an on disk URL). This felt overkill.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Integration Tests

@torcolvin
Copy link
Collaborator Author

This has some implications on code I wanted to do for #8074 / #8057 but I can drop this and determine in a better way if a bucket is a rosmar bucket and add this to DatabaseContext struct if I don't want to do AsRosmarBucket(db.Bucket).

However, the code in

if spec.Server == "" || spec.IsWalrusBucket() {
is wrong for logging in the db package since spec.Server == ""

@bbrks bbrks merged commit 0d35105 into main Feb 23, 2026
32 checks passed
@bbrks bbrks deleted the decouple-bucketspec branch February 23, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants