cassandra

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package Cassandra contains code for integration or inter-operation with Cassandra DB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseConnection

func CloseConnection()

Close the singleton connection if open.

func GetBlobPayloadCount

func GetBlobPayloadCount[T btree.UUID](payloads []BlobsPayload[T]) int

func GetRegistryPayloadCount

func GetRegistryPayloadCount[T btree.UUID](payloads []RegistryPayload[T]) int

func IsConnectionInstantiated

func IsConnectionInstantiated() bool

Returns true if connection instance is valid.

func SetRegistryCacheDuration

func SetRegistryCacheDuration(duration time.Duration)

SetRegistryDuration allows registry cache duration to get set globally.

func SetStoreCacheDuration

func SetStoreCacheDuration(duration time.Duration)

SetStoreCacheDuration allows store repository cache duration to get set globally.

Types

type BlobStore

type BlobStore interface {
	// Get or fetch a blob given an Id.
	GetOne(ctx context.Context, blobTable string, blobId btree.UUID, target interface{}) error
	// Add blobs to store.
	Add(ctx context.Context, blobs ...BlobsPayload[sop.KeyValuePair[btree.UUID, interface{}]]) error
	// Update blobs in store.
	Update(ctx context.Context, blobs ...BlobsPayload[sop.KeyValuePair[btree.UUID, interface{}]]) error
	// Remove blobs in store with given Ids.
	Remove(ctx context.Context, blobsIds ...BlobsPayload[btree.UUID]) error
}

BlobStore specifies the backend blob store interface used for storing & managing data blobs. Blobs are data that can vary in size and is big enough that they can't be stored in database as it will impose performance penalties. This kind of data are typically stored in blob stores like AWS S3, or file system, etc...

func NewBlobStore

func NewBlobStore() BlobStore

func NewMockBlobStore

func NewMockBlobStore() BlobStore

NewBlobStore instantiates a new (mocked) blobstore.

type BlobsPayload

type BlobsPayload[T btree.UUID | sop.KeyValuePair[btree.UUID, interface{}]] struct {
	// Blob store table name.
	BlobTable string
	// Blobs contains the blobs Ids and blobs data for upsert to the store or the blobs Ids to be removed.
	Blobs []T
}

Manage or fetch node blobs request/response payload.

type Config

type Config struct {
	ClusterHosts []string
	// Keyspace to be used when doing I/O to cassandra.
	Keyspace string
	// Consistency
	Consistency       gocql.Consistency
	ConnectionTimeout time.Duration
	Authenticator     gocql.Authenticator
	// Defaults to simple strategy & replication factor of 1.
	ReplicationClause string
}

type Connection

type Connection struct {
	Session *gocql.Session
	Config
}

func GetConnection

func GetConnection(config Config) (*Connection, error)

GetConnection will create(& return) a new Connection to Cassandra if there is not one yet, otherwise, will just return existing singleton connection.

type Registry

type Registry interface {
	// Get will fetch handles(given their Ids) from stores.
	Get(context.Context, ...RegistryPayload[btree.UUID]) ([]RegistryPayload[sop.Handle], error)
	// Add will insert handles to stores.
	Add(context.Context, ...RegistryPayload[sop.Handle]) error
	// Update will update handles of stores.
	// Set allOrNothing to true if Update operation is crucial for data consistency and
	// wanting to do an all or nothing update for the entire batch of handles.
	// False is recommended if such consistency is not significant.
	Update(ctx context.Context, allOrNothing bool, handles ...RegistryPayload[sop.Handle]) error
	// Remove will delete handles(given their Ids) from stores.
	Remove(context.Context, ...RegistryPayload[btree.UUID]) error
}

Virtual Id registry is essential in our support for all or nothing (sub)feature, which is essential in "fault tolerant" & "self healing" feature.

All methods are taking in a set of items.

func NewMockRegistry

func NewMockRegistry() Registry

NewMockRegistry manages the Handle in memory for mocking.

func NewRegistry

func NewRegistry() Registry

NewRegistry manages the Handle in the store's Cassandra registry table.

type RegistryPayload

type RegistryPayload[T sop.Handle | btree.UUID] struct {
	// Registry table (name) where the Virtual Ids will be stored or fetched from.
	RegistryTable string
	// IDs is an array containing the Virtual Ids details to be stored or to be fetched.
	IDs []T
}

Manage or fetch Virtual Id request/response payload.

type StoreRepository

type StoreRepository interface {
	// Fetch store info with name.
	Get(context.Context, ...string) ([]btree.StoreInfo, error)
	// Add store info.
	Add(context.Context, ...btree.StoreInfo) error
	// Update store info. Update should also merge the Count of items between the incoming store info
	// and the target store info on the backend, as they may differ. It should use StoreInfo.CountDelta to reconcile the two.
	Update(context.Context, ...btree.StoreInfo) error
	// Remove store info with name.
	Remove(context.Context, ...string) error
}

StoreRepository interface specifies the store repository.

func NewMockStoreRepository

func NewMockStoreRepository() StoreRepository

NewMockStoreRepository manages the StoreInfo in Cassandra table.

func NewStoreRepository

func NewStoreRepository() StoreRepository

NewStoreRepository manages the StoreInfo in Cassandra table.

Jump to

Keyboard shortcuts

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