Class OptimisticZoneTree<TKey, TValue>
Inherited Members
Namespace: Tenray.ZoneTree.Transactional
Assembly: ZoneTree.dll
Syntax
public sealed class OptimisticZoneTree<TKey, TValue> : ITransactionalZoneTree<TKey, TValue>, IDisposable, ITransactionalZoneTreeMaintenance<TKey, TValue>
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Constructors
| Improve this Doc View SourceOptimisticZoneTree(ZoneTreeOptions<TKey, TValue>, ITransactionLog<TKey, TValue>, IZoneTree<TKey, TValue>)
Declaration
public OptimisticZoneTree(ZoneTreeOptions<TKey, TValue> options, ITransactionLog<TKey, TValue> transactionLog, IZoneTree<TKey, TValue> zoneTree = null)
Parameters
Type | Name | Description |
---|---|---|
ZoneTreeOptions<TKey, TValue> | options | |
ITransactionLog<TKey, TValue> | transactionLog | |
IZoneTree<TKey, TValue> | zoneTree |
Properties
| Improve this Doc View SourceIsReadOnly
Enables read-only mode.
Declaration
public bool IsReadOnly { get; set; }
Property Value
Type | Description |
---|---|
bool |
Logger
ZoneTree Logger.
Declaration
public ILogger Logger { get; }
Property Value
Type | Description |
---|---|
ILogger |
Maintenance
Returns maintenance object belongs to this TransactionalZoneTree.
Declaration
public ITransactionalZoneTreeMaintenance<TKey, TValue> Maintenance { get; }
Property Value
Type | Description |
---|---|
ITransactionalZoneTreeMaintenance<TKey, TValue> |
TransactionLog
Transaction Log instance.
Declaration
public ITransactionLog<TKey, TValue> TransactionLog { get; }
Property Value
Type | Description |
---|---|
ITransactionLog<TKey, TValue> |
UncommittedTransactionIds
Retrieves uncommitted transaction ids.
Declaration
public IReadOnlyList<long> UncommittedTransactionIds { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<long> |
ZoneTree
Underlying non-transactional ZoneTree.
Declaration
public IZoneTree<TKey, TValue> ZoneTree { get; }
Property Value
Type | Description |
---|---|
IZoneTree<TKey, TValue> |
Methods
| Improve this Doc View SourceBeginFluentTransaction()
Creates a fluent transaction.
Declaration
public FluentTransaction<TKey, TValue> BeginFluentTransaction()
Returns
Type | Description |
---|---|
FluentTransaction<TKey, TValue> | Fluent transaction. |
BeginTransaction()
Begins the transaction. Creates a transaction id and informs the transaction manager that a new transaction started.
Declaration
public long BeginTransaction()
Returns
Type | Description |
---|---|
long | Transaction Id |
Commit(long)
Commits if the transaction is in ready to commit state. It is necessary to call PrepareCommit before calling this method.
Declaration
public CommitResult Commit(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId |
Returns
Type | Description |
---|---|
CommitResult |
Exceptions
Type | Condition |
---|---|
TransactionIsNotReadyToCommitException | |
TransactionAbortedException |
CommitNoThrow(long)
Commits if the transaction is in ready to commit state. It is necessary to call PrepareCommit before calling this method. This method does not throw transaction aborted exception.
Declaration
public CommitResult CommitNoThrow(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId |
Returns
Type | Description |
---|---|
CommitResult |
Exceptions
Type | Condition |
---|---|
TransactionIsNotReadyToCommitException |
ContainsKey(long, in TKey)
Contains Key query.
Declaration
public bool ContainsKey(long transactionId, in TKey key)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
ContainsKeyNoThrow(long, in TKey)
Contains Key query without abort exception.
Declaration
public TransactionResult<bool> ContainsKeyNoThrow(long transactionId, in TKey key)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
Returns
Type | Description |
---|---|
TransactionResult<bool> |
CreateMaintainer()
Creates the default ZoneTree Maintainer.
Declaration
public IMaintainer CreateMaintainer()
Returns
Type | Description |
---|---|
IMaintainer |
Delete(long, in TKey)
Deletes the key.
Declaration
public void Delete(long transactionId, in TKey key)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
DeleteAutoCommit(in TKey)
Starts a transaction, deletes the key-value, and commits the transaction.
Declaration
public void DeleteAutoCommit(in TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | Key |
DeleteNoThrow(long, in TKey)
Deletes the key without abort exception.
Declaration
public TransactionResult DeleteNoThrow(long transactionId, in TKey key)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
Returns
Type | Description |
---|---|
TransactionResult |
DestroyTree()
Removes the transactional tree from the universe. Destroys the tree, transaction logs, entire data and WAL store or folder.
Declaration
public void DestroyTree()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
GetTransactionState(long)
Retrieves transaction state of given transaction id.
Declaration
public TransactionState GetTransactionState(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
Returns
Type | Description |
---|---|
TransactionState | Transaction State |
Prepare(long)
Prepares to Commit. Aborts transaction if needed.
Declaration
public CommitResult Prepare(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
Returns
Type | Description |
---|---|
CommitResult |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
PrepareAndCommit(long)
Prepares to Commit. Aborts transaction if needed. If commit is possible does the commit.
Declaration
public CommitResult PrepareAndCommit(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
Returns
Type | Description |
---|---|
CommitResult |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
PrepareAndCommitNoThrow(long)
Prepares to Commit. Aborts transaction if needed. If commit is possible does the commit. This method does not throw transaction aborted exception.
Declaration
public CommitResult PrepareAndCommitNoThrow(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
Returns
Type | Description |
---|---|
CommitResult |
PrepareNoThrow(long)
Prepares to Commit. Aborts transaction if needed. This method does not throw transaction aborted exception.
Declaration
public CommitResult PrepareNoThrow(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
Returns
Type | Description |
---|---|
CommitResult |
ReadCommittedContainsKey(in TKey, long)
Contains Key query without a transaction. This method avoids dirty reads. The query is executed on committed data. If current transaction id given, this method reads uncommitted key for given transaction and committed keys for other transactions.
Declaration
public bool ReadCommittedContainsKey(in TKey key, long currentTransactionId = -1)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | Key |
long | currentTransactionId | Current transaction. |
Returns
Type | Description |
---|---|
bool |
ReadCommittedTryGet(in TKey, out TValue, long)
Tries to get the value of given key without a transaction. This method avoids dirty reads. The query is executed on committed data. If current transaction id given, this method reads uncommitted key for given transaction and committed keys for other transactions.
Declaration
public bool ReadCommittedTryGet(in TKey key, out TValue value, long currentTransactionId = -1)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | Key |
TValue | value | Value |
long | currentTransactionId | Current transaction. |
Returns
Type | Description |
---|---|
bool |
Rollback(long)
Rollbacks the transaction by undoing all writes by this transaction.
Declaration
public void Rollback(long transactionId)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId |
RollbackAllUncommitted()
Rollbacks all uncommitted transactions.
Declaration
public int RollbackAllUncommitted()
Returns
Type | Description |
---|---|
int | Count of rollbacked transactions. |
RollbackUncommittedTransactionIdsBefore(DateTime)
Rollbacks all uncommitted transaction ids started before given date-time. Transaction log memory usage increases by state uncommitted transaction ids. Those must be rollbacked.
Declaration
public int RollbackUncommittedTransactionIdsBefore(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Max start time (exclusive) |
Returns
Type | Description |
---|---|
int | Count of rollbacked transactions. |
RollbackUncommittedTransactions()
Declaration
public void RollbackUncommittedTransactions()
SaveMetaData()
Saves tree meta data and clears the meta wal record. After calling this method, the JSON meta file contains up to date tree meta data.
Saving meta file helps following:
- Reduce the size of meta wal file.
- Make Json meta file up to date to analyze parts of the LSM tree. Because Meta WAL file is not human readable.
It is up to user to decide when and how frequently save the meta file.
Declaration
public void SaveMetaData()
TryGet(long, in TKey, out TValue)
Tries to get the value of given key.
Declaration
public bool TryGet(long transactionId, in TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
TValue | value | Value |
Returns
Type | Description |
---|---|
bool | true if key is found, otherwise false. |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
TryGetNoThrow(long, in TKey, out TValue)
Tries to get the value of given key without abort exception.
Declaration
public TransactionResult<bool> TryGetNoThrow(long transactionId, in TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
TValue | value | Value |
Returns
Type | Description |
---|---|
TransactionResult<bool> | true if key is found, otherwise false. |
Upsert(long, in TKey, in TValue)
Upserts the key and value.
Declaration
public bool Upsert(long transactionId, in TKey key, in TValue value)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
TValue | value | Value |
Returns
Type | Description |
---|---|
bool | true if the key/value pair was inserted; false if the key/value pair was updated. |
Exceptions
Type | Condition |
---|---|
TransactionAbortedException |
UpsertAutoCommit(in TKey, in TValue)
Starts a transaction, upserts the key-value, and commits the transaction.
Declaration
public void UpsertAutoCommit(in TKey key, in TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | Key |
TValue | value | Value |
UpsertNoThrow(long, in TKey, in TValue)
Upserts the key and value without abort exception.
Declaration
public TransactionResult<bool> UpsertNoThrow(long transactionId, in TKey key, in TValue value)
Parameters
Type | Name | Description |
---|---|---|
long | transactionId | Transaction Id |
TKey | key | Key |
TValue | value | Value |
Returns
Type | Description |
---|---|
TransactionResult<bool> | true if the key/value pair was inserted; false if the key/value pair was updated. |