Skip to content

Commit

Permalink
CBG-3703 add options for XDCR
Browse files Browse the repository at this point in the history
- putting options for XDCR in sg-bucket allows full XDCR implementation
  to be in rosmar
- place sync metadata constants into sg-bucket for rosmar
- merge GetCollectionID()/DataStoreName() into DataStore to avoid extra
  casting.
  • Loading branch information
torcolvin committed Mar 27, 2024
1 parent 0b197e1 commit f0ad62e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
17 changes: 6 additions & 11 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,21 @@ type BucketStoreFeatureIsSupported interface {
// A Couchbase Server collection within a bucket is an example of a DataStore.
// The expiry field (exp) can take offsets or UNIX Epoch times. See https://developer.couchbase.com/documentation/server/3.x/developer/dev-guide-3.0/doc-expiration.html
type DataStore interface {
// The datastore name (usually a qualified collection name)
// The datastore name (usually a qualified collection name, bucket.scope.collection)
GetName() string
// DataStoreName() DataStoreName // TODO: Implement later
// The name of the datastore, without the bucket name
DataStoreName() DataStoreName

// An integer that uniquely identifies this Collection in its Bucket.
// The default collection always has the ID zero.
GetCollectionID() uint32
KVStore
XattrStore
SubdocStore
TypedErrorStore
BucketStoreFeatureIsSupported
}

// A Collection is the typical type of DataStore. It has an integer identifier.
type Collection interface {
// An integer that uniquely identifies this Collection in its Bucket.
// The default collection always has the ID zero.
GetCollectionID() uint32

DataStore
}

// UpsertOptions are the options to use with the set operations
type UpsertOptions struct {
PreserveExpiry bool // GoCB v2 option
Expand Down
6 changes: 6 additions & 0 deletions sync_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sgbucket

const (
SyncDocPrefix = "_sync:" // SyncDocPrefix is a document prefix for all sync metadata
Att2Prefix = SyncDocPrefix + "att2:" // Att2Prefix is a document prefix for v2 attachment data
)
49 changes: 49 additions & 0 deletions xdcr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package sgbucket

import "context"

// XDCRStats represents the stats of a replication.
type XDCRStats struct {
// DocsFiltered is the number of documents that have been filtered out and have not been replicated to the target cluster.
DocsFiltered uint64
// DocsWritten is the number of documents written to the destination cluster, since the start or resumption of the current replication.
DocsWritten uint64
}

// XDCR represents a bucket to bucket XDCR replication.
type XDCR interface {
// Start starts the replication.
Start(context.Context) error
// Stop terminates the replication.
Stop(context.Context) error
// Stats returns the stats for the replication.
Stats(context.Context) (*XDCRStats, error)
}

// XDcrManager represents the presence of "-mobile" flag for Couchbase Server replications. -mobile implies filtering sync metadata, handling version vectors, and filtering sync documents.
type XDCRMobileSetting uint8

const (
XDCRMobileOff = iota
XDCRMobileOn
)

// String returns the string representation of the XDCRMobileSetting, used for directly passing on to the Couchbase Server REST API.
func (s XDCRMobileSetting) String() string {
switch s {
case XDCRMobileOff:
return "Off"
case XDCRMobileOn:
return "Active"
default:
return "Unknown"
}
}

// XDCROptions represents the options for creating an XDCR.
type XDCROptions struct {
// FilterExpression is the filter expression to use for the replication.
FilterExpression string
// XDCR mobile setting defines whether XDCR replication will use -mobile setting behavior in Couchbase Server.
Mobile XDCRMobileSetting
}

0 comments on commit f0ad62e

Please sign in to comment.