Skip to content

Conversation

@torcolvin
Copy link
Collaborator

@torcolvin torcolvin commented Nov 4, 2025

CBG-4980 support /db/_flush for internal testing

Also addresses:

  • CBG-4982 Database recreation after flush doesn't work with persistent config
  • CBG-4980 Couchbase Buckets aren't flushable

NOTE: _flush is a database call, so any other databases that are backed by the same bucket will be destroyed.

  • /db/_flush for Couchbase Server buckets has been broken since 3.2 as part of 617b873
  • /db/_flush for persistent config never worked correctly before this commit, because it would delete the database registry and only re-add the database from AddDatabaseFromConfig. It would also not block database polling while this happened which could result in a crash.

Behavior changes:

  • Support the /db/_flush endpoint which will flush a gocb bucket or delete a rosmar bucket
  • Support persistent and non persistent configuration by using InsertConfig or AddDatabaseFromConfig. Test to make sure config polling no-ops after calling /db/_flush
  • Support using serialized rosmar buckets by calling OpenBucketIn in RosmarCluster. When using rosmar.InMemoryURL, OpenBucket and OpenBucketIn behave identically, but they do not otherwise.
  • If a bucket was closed, rosmar.Bucket.DefaultDataStore() would just return nil, and we didn't do a nil check. Probably https://github.com/couchbaselabs/rosmar/blob/3b9ac157a3cd52c076649d31cbe385e76386787d/bucket_api.go#L122 should panic, or we change the sg-bucket.Bucket.DefaultDataStore API to return errors. I thought this was out of scope for this PR, and we might want to backport this to older releases where we might not want to switch rosmar.

When flushing or deleting a bucket, you need to create a copy of the bucket object.

Possible Different Approach

Since /db/_flush is database scoped, but it flushes the entire bucket, this means other databases that are backed by the same bucket are deleted. I have considered removing this API entirely, and maybe replacing it with an API that is like /_internal/rosmar/bucketName that could delete a bucket that is either in memory or on disk. This would be more clear in the behavior but add an API that we don't to use outside of some E2E testing.

Integration Tests

Copilot AI review requested due to automatic review settings November 4, 2025 18:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds test coverage for the flush operation with both transient and persistent configuration modes, ensuring compatibility with Rosmar (the in-memory bucket implementation).

Key changes:

  • Parameterized the TestFlush test to run with both persistent and non-persistent configurations
  • Added explicit database creation step when using persistent config
  • Removed redundant SetAdminParty call after flush operation
  • Added verification step to recreate and retrieve documents after flush

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Redocly previews

@torcolvin torcolvin changed the title make sure that flush works with rosmar CBG-4980: support /db/_flush for internal testing Nov 6, 2025
@torcolvin torcolvin requested a review from Copilot November 6, 2025 17:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Copy link
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

Generally looks good, a few questions on some of the specifics.

return nil, fmt.Errorf("bucket is not a gocb bucket (type %T)", baseBucket)
}

// AsRosmar returns a bucket as a rosmar.Bucket, or an error if it is not one.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels odd to stick a single *rosmar.Bucket helper function in the middle of the GocbV2Bucket implementation of BucketStore (and related interfaces), but I suppose there isn't really a natural location for it elsewhere? I might prefer it in rosmar_cluster just for the grouping of rosmar functionality, even if it's not cluster-related? If you feel it belongs where you've got it I'm ok with that, if it was an intentional choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this I'll move this. I kept it close by to AsGocbV2Bucket but I think it is weird too.

if runtime.GOOS == "windows" {
directory = strings.TrimPrefix(directory, "/")
}
err = os.MkdirAll(directory, 0750)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are group permissions needed here? (0750 vs 0700)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, no good reason.

rest/api.go Outdated
if err2 != nil {
return err2
defer bucket.Close(h.ctx())
// Flush the bucket (assuming it conforms to sgbucket.DeleteableStore interface
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't look like we're using the DeleteableStore interface check any more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, this actually requires Flush anyway.

@adamcfraser adamcfraser merged commit eaab17f into main Nov 13, 2025
44 of 45 checks passed
@adamcfraser adamcfraser deleted the test-rosmar-flush branch November 13, 2025 21:24
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.

3 participants