mockdb

package
v0.0.1-77 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDocExists = errors.New("document already exists")

ErrDocExists is thrown when document was expected not to exist, but did.

View Source
var ErrDocNotFound = errors.New("document not found")

ErrDocNotFound is thrown when a document was expected to exist but did not.

View Source
var ErrValueTooBig = errors.New("document value too large")

ErrValueTooBig is thrown when a document was set with a value that is too large.

Functions

func GenerateNewCas

func GenerateNewCas(now time.Time) uint64

GenerateNewCas will generate a new CAS to use with a document.

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket represents a Bucket store

func NewBucket

func NewBucket(opts NewBucketOptions) (*Bucket, error)

NewBucket will create a new Bucket store.

func (*Bucket) Chrono

func (b *Bucket) Chrono() *mocktime.Chrono

Chrono returns the chrono responsible for this bucket.

func (*Bucket) Compact

func (b *Bucket) Compact() error

Compact will compact all of the vbuckets within this bucket. This is not yet supported. See Vbucket::Compact for details on why.

func (*Bucket) Flush

func (b *Bucket) Flush()

func (*Bucket) Get

func (b *Bucket) Get(repIdx, vbIdx uint, collectionID uint, key []byte) (*Document, error)

Get fetches a document from a particular replica and vbucket index.

func (*Bucket) GetAll

func (b *Bucket) GetAll(repIdx, collectionID uint) ([]*Document, error)

GetAll fetches all documents from a particular replica.

func (*Bucket) GetRandom

func (b *Bucket) GetRandom(repIdx, collectionID uint) (*Document, error)

GetRandom fetches a random document from a particular replica and vbucket index.

func (*Bucket) GetVbucket

func (b *Bucket) GetVbucket(vbIdx uint) *Vbucket

GetVbucket will return the Vbucket object for a particular replica and vbucket index within this particular bucket store.

func (*Bucket) Insert

func (b *Bucket) Insert(doc *Document) (*Document, error)

Insert inserts a document into the master replica of a vbucket.

func (*Bucket) Remove

func (b *Bucket) Remove(vbIdx uint, key []byte) (*Document, error)

Remove removes a document from the master replica of a vbucket.

func (*Bucket) Rollback

func (b *Bucket) Rollback(snap *BucketSnapshot) error

Rollback will rollback the bucket to a previously snapshotted state.

func (*Bucket) Snapshot

func (b *Bucket) Snapshot() *BucketSnapshot

Snapshot returns a snapshot of the current state of a Bucket which can be used to later rollback to the bucket to that point in time.

func (*Bucket) Update

func (b *Bucket) Update(vbID, collectionID uint, key []byte, fn UpdateFunc) (*Document, error)

Update allows a document to be atomically operated upon in the bucket.

type BucketSnapshot

type BucketSnapshot struct {
	// contains filtered or unexported fields
}

BucketSnapshot represents a snapshot of the bucket at a point in time. This can later be used to rollback the bucket to this point in time.

type Document

type Document struct {
	VbID         uint
	CollectionID uint
	Key          []byte
	Value        []byte
	Xattrs       map[string][]byte
	Flags        uint32
	Datatype     uint8
	IsDeleted    bool
	Expiry       time.Time
	LockExpiry   time.Time

	VbUUID       uint64
	Cas          uint64
	SeqNo        uint64
	ModifiedTime time.Time
	RevID        uint64
}

Document represents one document stored in the vbucket. For the purposes of simplicity of this mock storage engine, this one object is used throughout the implementation.

type NewBucketOptions

type NewBucketOptions struct {
	Chrono         *mocktime.Chrono
	NumReplicas    uint
	NumVbuckets    uint
	ReplicaLatency time.Duration
	PersistLatency time.Duration
}

NewBucketOptions specifies the configuration for a new Bucket store.

type UpdateFunc

type UpdateFunc func(*Document) (*Document, error)

UpdateFunc represents a function which can modify the state of a document.

type VbMetaState

type VbMetaState struct {
	VbUUID       uint64
	CurrentSeqNo uint64
	PersistSeqNo uint64
}

VbMetaState holds some information about the meta-state of a vbucket.

type VbRevData

type VbRevData struct {
	VbUUID uint64
	SeqNo  uint64
}

VbRevData represents an entry in the revision history for this vbucket.

type Vbucket

type Vbucket struct {
	// contains filtered or unexported fields
}

Vbucket represents a single Vbucket worth of documents

func (*Vbucket) Compact

func (s *Vbucket) Compact() error

Compact will compact all of the mutations within a vbucket such that no two sequence numbers exist which are for the same document key.

func (*Vbucket) CurrentMetaState

func (s *Vbucket) CurrentMetaState(repIdx uint) VbMetaState

CurrentMetaState returns the current sequence numbering information. Returns the vbuuid, seqno and persistSeqno.

func (*Vbucket) Flush

func (s *Vbucket) Flush()

Flush is a basic implementation of this process and simply resets the documents in the vbucket and resets the max seq no

func (*Vbucket) Get

func (s *Vbucket) Get(repIdx, collectionID uint, key []byte) (*Document, error)

Get returns a document in the vbucket by key

func (*Vbucket) GetAll

func (s *Vbucket) GetAll(repIdx, collectionID uint) ([]*Document, error)

GetAll returns all documents in the vbucket.

func (*Vbucket) GetAllWithin

func (s *Vbucket) GetAllWithin(repIdx uint, startSeqNo, endSeqNo uint64) ([]*Document, uint64, error)

GetAllWithin returns a list of all the mutations that have occurred in a vbucket within the bounds of the sequence numbers passed. NOTE: There is an assumption that the items returned by this method are in ascending seqno order, and that last-modified times are in ascending order as well.

func (*Vbucket) GetRandom

func (s *Vbucket) GetRandom(repIdx, collectionID uint) *Document

GetRandom returns a random, not deleted or expired, document in the vbucket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL