in_red_ck

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package contains SOP in Redis, Cassandra & Kafka(in_red_c) integration code.

Index

Constants

This section is empty.

Variables

View Source
var IsDeleteServiceEnabled bool

Enable the delete service(defaults to false) if you want this host to (enqueue &) poll kafka periodically to send/process deleted unused Nodes leftover of transaction.

View Source
var ServiceIntervalInHour int = 2

Service interval defaults to 2 hours. That is, process deleted items every two hours.

Functions

func DeleteService

func DeleteService(ctx context.Context)

DeleteService runs the DoDeleteItemsProcessing function below periodically, like every 2 hours(default).

func DoDeletedItemsProcessing

func DoDeletedItemsProcessing(ctx context.Context)

Process(issue delete SQL stmt) the deleted items from the kafka queue.

func EnableDeleteService

func EnableDeleteService(yes bool)

Sets the Delete Service to enabled(yes = true) or disabled(yes = false).

func Initialize

func Initialize(cassandraConfig cas.Config, redisConfig redis.Options) error

Assign the configs & open connections to different sub-systems used by this package. Example, connection to Cassandra, Redis.

func IsInitialized

func IsInitialized() bool

Returns true if components required were initialized, false otherwise.

func NewBtree

func NewBtree[TK btree.Comparable, TV any](ctx context.Context, name string, slotLength int, isUnique bool,
	isValueDataInNodeSegment bool, leafLoadBalancing bool, desciption string, t Transaction) (btree.BtreeInterface[TK, TV], error)

NewBtree will create a new B-Tree instance with data persisted to backend storage upon commit. If B-Tree(name) is not found in the backend, a new one will be created. Otherwise, the existing one will be opened and the parameters checked if matching. If you know that it exists, then it is more convenient and more readable to call the OpenBtree function.

Parameters: name - specifies the name of the store/b-tree. This has to follow valid Cassandra table name, e.g. - it should start with a letter, etc... as we generate Cassandra tables on the back, one for blob(_b) & one for registry(_r). slotLength - specifies the number of item slots per node of a b-tree. isUnique - specifies whether the b-tree will enforce key uniqueness(true) or not(false). isValueDataInNodeSegment - specifies whether the b-tree will store the "value" data in the tree's node segment together with

the key, or store it in another (data) segment. Currently not implemented and always stores the data in the node segment.

leafLoadBalancing - true means leaf load balancing feature is enabled, false otherwise. description - (optional) description about the store. t - transaction that the instance will participate in.

func OpenBtree

func OpenBtree[TK btree.Comparable, TV any](ctx context.Context, name string, t Transaction) (btree.BtreeInterface[TK, TV], error)

OpenBtree will open an existing B-Tree instance & prepare it for use in a transaction.

func RemoveBtree added in v1.6.7

func RemoveBtree(ctx context.Context, name string) error

Removes B-Tree with a given name from the backend storage. This involves dropping tables (registry & node blob) that are permanent action and thus, 'can't get rolled back.

Use with care and only when you are sure to delete the tables.

func SetNodeCacheDuration

func SetNodeCacheDuration(duration time.Duration)

SetNodeCacheDuration allows node cache duration to get set globally.

func Shutdown

func Shutdown()

Shutdown or closes all connections used in this package.

Types

type StoreInterface

type StoreInterface[TK btree.Comparable, TV any] struct {
	btree.StoreInterface[TK, TV]
	// contains filtered or unexported fields
}

StoreInterface contains different repositories needed/used by B-Tree to manage/access its data/objects.

type Transaction

type Transaction interface {
	// Begin the transaction.
	Begin() error
	// Commit the transaction.
	Commit(ctx context.Context) error
	// Rollback the transaction.
	Rollback(ctx context.Context) error
	// Returns true if transaction has begun, false otherwise.
	HasBegun() bool

	// Returns the two phased commit transaction object. Useful for integration with your application
	// "other" database transactions. Returned transaction object will allow your code to call the
	// two phases commit of SOP.
	GetPhasedTransaction() TwoPhaseCommitTransaction
	// Add your two phases commit implementation for managing your/3rd party database transaction.
	AddPhasedTransaction(otherTransaction ...TwoPhaseCommitTransaction)
}

Transaction interface defines the "enduser facing" transaction methods.

func NewTransaction

func NewTransaction(forWriting bool, maxTime time.Duration) (Transaction, error)

NewTransaction creates an enduser facing transaction object. forWriting - if true will create a transaction that allows create, update, delete operations on B-Tree(s) created or opened in the transaction. Otherwise it will be for read-only operations. maxTime - specify the maximum "commit" time of the transaction. That is, upon call to commit, it is given this amount of time to conclude, otherwise, it will time out and rollback. If -1 is specified, 15 minute max commit time will be assigned.

type TwoPhaseCommitTransaction

type TwoPhaseCommitTransaction interface {
	// Begin the transaction.
	Begin() error
	// Phase1Commit of the transaction.
	Phase1Commit(ctx context.Context) error
	// Phase2Commit of the transaction.
	Phase2Commit(ctx context.Context) error
	// Rollback the transaction.
	Rollback(ctx context.Context) error
	// Returns true if transaction has begun, false otherwise.
	HasBegun() bool
}

TwoPhaseCommitTransaction interface defines the "infrastructure facing" transaction methods.

func NewTwoPhaseCommitTransaction

func NewTwoPhaseCommitTransaction(forWriting bool, maxTime time.Duration) (TwoPhaseCommitTransaction, error)

NewTwoPhaseCommitTransaction will instantiate a transaction object for writing(forWriting=true) or for reading(forWriting=false). Pass in -1 on maxTime to default to 15 minutes of max "commit" duration.

Directories

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

Jump to

Keyboard shortcuts

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