The types os_int32 and os_boolean, used throughout this manual, are each defined as a signed 32-bit integer type. The type os_unsigned_int32 is defined as an unsigned 32-bit integer type.
All ObjectStore programs must include the header file <ostore/ostore.hh>.
static void abort(os_transaction* = get_current());Aborts the specified transaction. For dynamic transactions, control flows to the next statement after you call abort(). For lexical transactions, control flows to the next statement after the end of the current transaction block. Persistent data is rolled back to its state as of the beginning of the transaction. In addition, if the aborted transaction is not nested within another transaction, all locks are released, and other processes can access the pages that the aborted transaction accessed.
There are no write locks for any pages that are written during an abort-only transaction. This allows multiple concurrent abort-only writers to a database. However, there are read locks for all pages the client reads or writes. When used with MVCC-opened databases, the standard MVCC locks apply.
The client raises the exception err_commit_abort_only if an attempt is made to commit an abort-only transaction. If the top-level transaction is abort-only, both abort-only and update transactions can nest within it. Otherwise, the nesting rule described in os_transaction::begin() applies.
Note that an abort_only transaction does not automatically abort. You must specifically use the os_transaction::abort() function to abort the abort_only transaction, otherwise an exception is signaled.
OS_BEGIN_TXN(txn, 0, os_transaction::abort_only) { ... os_transaction::abort(); } OS_END_TXN(txn);
static void abort_top_level();Aborts the outermost transaction within which control currently resides. If the current transaction is not nested, this function aborts the current transaction.
static os_transaction *begin( transaction_type_enum t_type = update, transaction_scope_enum t_scope = local);Begins a dynamic transaction. A pointer to an object representing the transaction is returned. The user is responsible for deleting this object after terminating the transaction. The os_int32 argument should be coded as either os_transaction::update or os_transaction::read_only, depending on the type of transaction desired. Unlike transactions started with a transaction macro or statement, dynamic transactions are not automatically retried when aborted because of deadlock. Unless the top-level transaction is abort-only, a nested transaction must be of the same type (os_transaction::update or os_transaction::read_only) as its parent; otherwise err_trans_wrong_type is signaled.
To support multithreaded applications, dynamic transactions can be either local or global. By default, dynamic transactions are local. You start a global transaction by passing the enumerator os_transaction::global as the second argument to os_transaction::begin().
The two kinds of transactions have the following characteristics:
Global transactions allow for a somewhat higher degree of concurrency. After one thread enters the ObjectStore run time, if another thread attempts to enter the ObjectStore run time, it is blocked until control in the first thread exits from the run time. Although two threads cannot be in the ObjectStore run time at the same time, there can be some interleaving of operations of different threads within a transaction.
If you use global transactions, be sure to synchronize the threads so that no thread attempts to access persistent data while another thread is committing or aborting. Place a barrier before the end of the transaction so that all participating threads complete work on persistent data before the end-of-transaction operation is allowed to proceed.
You cannot nest a local transaction within a global transaction, nor can you nest a global transaction within a local one. This table specifies how two transactions can
static os_transaction *os_transaction::begin( transaction_type_enum t_type = update, transaction_scope_enum t_scope = local, os_transaction *parentLike the previous overloading, except that the new transaction is nested within the specified transaction.
);
static os_transaction *os_transaction::begin( char *name, transaction_type_enum t_type = update, transaction_scope_enum t_scope = local);Like the first overloading, except that the new transaction has the specified name.
static os_transaction *os_transaction::begin( char *name, transaction_type_enum t_type = update, transaction_scope_enum t_scope = local, os_transaction *parentLike the first overloading, except that the new transaction has the specified name and is nested within the specified transaction.
);
static void checkpoint();Invokes checkpoint on the current transaction.
static checkpoint(os_transaction*);Invokes checkpoint on the given transaction. Note that checkpoint is only valid for a top-level dynamic transaction. Attempts to checkpoint nested or stack transactions result in an exception's being thrown.
os_boolean os_transaction::checkpoint_in_progress();Returns 1 if a checkpoint is currently in progress. This function is for use in hook functions registered for invocation during transaction commit processing.
static void commit(os_transaction* = get_current());Commits the specified dynamic transaction. Unlike transactions started with a transaction statement, dynamic transactions are not automatically retried when aborted because of deadlock.
tix_exception *exception_status;ObjectStore stores an exception* in this member if the specified transaction is aborted because of the raising of an exception. The stored exception* indicates the exception that caused the abort. ObjectStore stores 0 in this location at the beginning of each transaction.
Raising an exception will cause a transaction to abort if the exception is handled outside the transaction's dynamic scope, or if there is no handler for the exception.
static os_transaction *get_current();Returns a pointer to the most deeply nested transaction in which control currently resides. The value is 0 if no transaction is in progress.
static os_int32 get_max_retries();Returns, for the current process, the number of times a transaction is automatically retried after being aborted because of deadlock. (Note that this does not apply to dynamic transactions, which are not automatically retried.)
char *get_name() const;Returns the name of the specified transaction, as set by os_transaction::set_name(). It is the caller's responsibility to deallocate the string when it is no longer needed.
os_transaction *get_parent() const;Returns a pointer to the transaction within which the specified transaction is directly nested.
os_transaction_scope_enum get_scope() const;Returns os_transaction::local or os_transaction::global, depending on which is true of the current transaction.
os_transaction_type get_type() const;Returns os_transaction::abort-only, os_transaction::read_only, or os_transaction::update, depending on which is true of the current transaction.
os_boolean is_aborted() const;Returns nonzero if the specified dynamic transaction is aborted, and 0 otherwise. For a transaction newly created by os_transaction::begin(), 0 is returned.
os_boolean is_committed() const;Returns nonzero if the specified dynamic transaction is committed, and 0 otherwise. For a transaction newly created by os_transaction::begin(), 0 is returned.
is_prepare_to_commit_completed();Returns true if a prepare_to_commit was invoked and completed in the current transaction and false otherwise.
is_prepare_to_commit_invoked();Returns true if a prepare_to_commit was invoked in the current transaction and false otherwise.
prepare_to_commit();Performs, in advance, the parts of transaction commit that can fail due to the inability to acquire a resource. If this method successfully completes, the actual transaction commit is virtually reduced to sending a commit message to the ObjectStore Server. All the modified data was sent to the Server during the invocation of the prepare_to_commit call. After the call to prepare_to_commit, the only ObjectStore operations that should occur are transaction commit or abort.
Some of the failures that can occur during the call to prepare_to_commit() are
The exception err_prepare_to_commit is generated if
static void set_max_retries(os_int32);Sets, for the current process, the number of times a transaction is automatically retried after being aborted because of deadlock.
void set_name(const char *new_name);Sets the name of the specified transaction. The function copies the string new_name.
os_boolean top_level() const;Returns nonzero if the specified transaction is nonnested; returns 0 otherwise.
Updated: 03/31/98 17:25:09