Documentation ¶
Overview ¶
Package contains SOP in Redis, Cassandra & Kafka(in_red_c) integration code.
Index ¶
- Constants
- Variables
- func Initialize(cassandraConfig cas.Config, redisConfig redis.Options) error
- func IsInitialized() bool
- func NewBtree[TK btree.Comparable, TV any](ctx context.Context, si sop.StoreOptions, t Transaction) (btree.BtreeInterface[TK, TV], error)
- func OpenBtree[TK btree.Comparable, TV any](ctx context.Context, name string, t Transaction) (btree.BtreeInterface[TK, TV], error)
- func RemoveBtree(ctx context.Context, name string) error
- func SetNodeCacheDuration(duration time.Duration)
- func Shutdown()
- type StoreInterface
- type Transaction
- type TransactionMode
- type TwoPhaseCommitTransaction
Constants ¶
const ( // No check does not allow any change to the Btree stores and does not check // read items' versions (for consistency) during commit. NoCheck = iota // For writing mode allows changes to be done to the Btree stores. ForWriting // For reading mode does not allow any change to the Btree stores. ForReading )
Variables ¶
var Now = time.Now
Use lambda for time.Now so automated test can replace with replayable time if needed.
Functions ¶
func Initialize ¶
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, si sop.StoreOptions, 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.
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
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 ¶
SetNodeCacheDuration allows node cache duration to get set globally.
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(mode TransactionMode, maxTime time.Duration, logging bool) (Transaction, error)
NewTransaction creates an enduser facing transaction object. mode - if ForWriting 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 ForReading(or NoCheck) mode. 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. logging - true will turn on transaction logging, otherwise will not. If turned on, SOP will log each step of the commit and these logs will help SOP to cleanup any uncommitted resources in case there are some build up, e.g. crash or host reboot left ongoing commits' temp changes. In time these will expire and SOP to clean them up.
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(mode TransactionMode, maxTime time.Duration, logging bool) (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. If logging is on, 'will log changes so it can get rolledback if transaction got left unfinished, e.g. crash or power reboot. However, without logging, the transaction commit can execute faster because there is no data getting logged.
Source Files ¶
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. |