Drizzled Public API Documentation

drizzled::TransactionServices Class Reference

#include <transaction_services.h>

Static Public Member Functions

static bool shouldConstructMessages ()
static void finalizeStatementMessage (message::Statement &, Session &)
static bool insertRecord (Session &, Table &in_table)
static void updateRecord (Session &, Table &, const unsigned char *old_record, const unsigned char *new_record)
static void deleteRecord (Session &, Table &, bool use_update_record=false)
static void createSchema (Session &, const message::Schema &schema)
static void dropSchema (Session &, const identifier::Schema &identifier, message::schema::const_reference schema)
static void alterSchema (Session &, const message::Schema &old_schema, const message::Schema &new_schema)
static void createTable (Session &, const message::Table &)
static void dropTable (Session &, const identifier::Table &identifier, message::table::const_reference table, bool if_exists)
static void truncateTable (Session &, Table &)
static void rawStatement (Session &, const std::string &query, const std::string &schema)
static void rawStatement (Session &session, const std::string &query)
static int rollbackTransaction (Session &, bool all)
static int commitTransaction (Session &, bool all)
static int autocommitOrRollback (Session &, int error)
static int rollbackToSavepoint (Session &, NamedSavepoint &sv)
static int setSavepoint (Session &, NamedSavepoint &sv)
static int releaseSavepoint (Session &, NamedSavepoint &sv)
static void registerResourceForStatement (Session &, plugin::MonitoredInTransaction *, plugin::TransactionalStorageEngine *)
static void registerResourceForStatement (Session &, plugin::MonitoredInTransaction *monitored, plugin::TransactionalStorageEngine *engine, plugin::XaResourceManager *resource_manager)
static void registerResourceForTransaction (Session &, plugin::MonitoredInTransaction *, plugin::TransactionalStorageEngine *)
static void registerResourceForTransaction (Session &, plugin::MonitoredInTransaction *, plugin::TransactionalStorageEngine *, plugin::XaResourceManager *)
static void allocateNewTransactionId ()
static bool sendStartupEvent (Session &)
static bool sendShutdownEvent (Session &)

Static Public Attributes

static const size_t DEFAULT_RECORD_SIZE = 100

Static Private Member Functions

static message::TransactiongetActiveTransactionMessage (Session &, bool should_inc_trx_id=true)
static void initTransactionMessage (message::Transaction &, Session &, bool should_inc_trx_id)
static void initStatementMessage (message::Statement &, message::Statement::Type type, const Session &)
static void finalizeTransactionMessage (message::Transaction &, const Session &)
static void cleanupTransactionMessage (message::Transaction *transaction, Session &)
static message::StatementgetInsertStatement (Session &, Table &, uint32_t *next_segment_id)
static void setInsertHeader (message::Statement &, const Session &, Table &)
static message::StatementgetUpdateStatement (Session &, Table &, const unsigned char *old_record, const unsigned char *new_record, uint32_t *next_segment_id)
static void setUpdateHeader (message::Statement &, const Session &, Table &, const unsigned char *old_record, const unsigned char *new_record)
static message::StatementgetDeleteStatement (Session &, Table &, uint32_t *next_segment_id)
static void setDeleteHeader (message::Statement &, const Session &, Table &)
static int commitTransactionMessage (Session &)
static void rollbackTransactionMessage (Session &)
static void rollbackStatementMessage (Session &)
static bool isFieldUpdated (Field *current_field, Table &, const unsigned char *old_record, const unsigned char *new_record)
static int sendEvent (Session &, const message::Event &event)
static message::TransactionsegmentTransactionMessage (Session &, message::Transaction *)
static int commitPhaseOne (Session &, bool all)
static uint64_t getCurrentTransactionId (Session &)

Detailed Description

This is a class which manages the XA transaction processing in the server

Definition at line 42 of file transaction_services.h.

Member Function Documentation

void drizzled::TransactionServices::alterSchema ( Session session,
const message::Schema old_schema,
const message::Schema new_schema 
)
static

Creates an AlterSchema Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]old_schemaOriginal schema definition
[in]new_schemaNew schema definition

Definition at line 1936 of file transaction_services.cc.

int drizzled::TransactionServices::autocommitOrRollback ( Session session,
int  error 
)
static

This is used to commit or rollback a single statement depending on the value of error.

Note
Note that if the autocommit is on, then the following call inside InnoDB will commit or rollback the whole transaction (= the statement). The autocommit mechanism built into InnoDB is based on counting locks, but if the user has used LOCK TABLES then that mechanism does not know to do the commit.

Definition at line 699 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), drizzled::session::Transactions::stmt, drizzled::Session::transaction_rollback_request, and drizzled::Session::variables.

Referenced by drizzled::Session::close_thread_tables().

void drizzled::TransactionServices::cleanupTransactionMessage ( message::Transaction transaction,
Session session 
)
staticprivate

Helper method which deletes transaction memory and unsets Session's transaction and statement messages.

Definition at line 994 of file transaction_services.cc.

References drizzled::Session::setStatementMessage(), and drizzled::Session::setTransactionMessage().

int drizzled::TransactionServices::commitPhaseOne ( Session session,
bool  normal_transaction 
)
staticprivate
int drizzled::TransactionServices::commitTransaction ( Session session,
bool  all 
)
static

Commit the current transaction.

Return values
0ok
1transaction was rolled back
2error during commit, data may be inconsistent
Todo:
Since we don't support nested statement transactions in 5.0, we can't commit or rollback stmt transactions while we are inside stored functions or triggers. So we simply do nothing now. This should be fixed in later ( >= 5.1) releases.

Definition at line 459 of file transaction_services.cc.

References drizzled::session::Transactions::all, drizzled::plugin::MonitoredInTransaction::participatesInXaTransaction(), and drizzled::session::Transactions::stmt.

Referenced by drizzled::Session::endTransaction().

int drizzled::TransactionServices::commitTransactionMessage ( Session session)
staticprivate

Commits a normal transaction (see above) and pushes the transaction message out to the replicators.

Parameters
sessionSession object committing the transaction

Definition at line 1003 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), and drizzled::Session::getTransactionMessage().

void drizzled::TransactionServices::createSchema ( Session session,
const message::Schema schema 
)
static

Creates a CreateSchema Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]schemamessage::Schema message describing new schema

Definition at line 1872 of file transaction_services.cc.

void drizzled::TransactionServices::createTable ( Session session,
const message::Table table 
)
static

Creates a CreateTable Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]tablemessage::Table message describing new schema

Definition at line 1840 of file transaction_services.cc.

void drizzled::TransactionServices::deleteRecord ( Session session,
Table table,
bool  use_update_record = false 
)
static

Creates a new DeleteRecord GPB message and pushes it to replicators.

Parameters
sessionSession object which has deleted a record
tableTable object containing delete information
use_update_recordIf true, uses the values from the update row instead

Store optional old record value in the before data member

Definition at line 1781 of file transaction_services.cc.

References drizzled::TableShare::fieldInPrimaryKey(), drizzled::Session::mem_root, and drizzled::Field::ptr.

void drizzled::TransactionServices::dropSchema ( Session session,
const identifier::Schema identifier,
message::schema::const_reference  schema 
)
static

Creates a DropSchema Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]identifierIdentifier for the schema to drop

Definition at line 1904 of file transaction_services.cc.

void drizzled::TransactionServices::dropTable ( Session session,
const identifier::Table identifier,
message::table::const_reference  table,
bool  if_exists 
)
static

Creates a DropTable Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]tableIdentifier for the table being dropped
[in]if_existsDid the user specify an IF EXISTS clause?

Definition at line 1972 of file transaction_services.cc.

void drizzled::TransactionServices::finalizeStatementMessage ( message::Statement statement,
Session session 
)
static

Finalizes a Statement message and sets the Session's statement message to NULL.

Parameters
statementThe statement to initialize
sessionThe Session object processing this statement

Definition at line 1057 of file transaction_services.cc.

References drizzled::Session::setStatementMessage().

void drizzled::TransactionServices::finalizeTransactionMessage ( message::Transaction transaction,
const Session session 
)
staticprivate

Helper method which finalizes data members for the supplied transaction's context.

Parameters
transactionThe transaction message to finalize
sessionThe Session object processing this transaction

Definition at line 987 of file transaction_services.cc.

message::Transaction * drizzled::TransactionServices::getActiveTransactionMessage ( Session session,
bool  should_inc_trx_id = true 
)
staticprivate

Method which returns the active Transaction message for the supplied Session. If one is not found, a new Transaction message is allocated, initialized, and returned. It is possible that we may want to NOT increment the transaction id for a new Transaction object (e.g., splitting up Transactions into smaller chunks). The should_inc_trx_id flag controls if we do this.

Parameters
sessionThe Session object processing the transaction
should_inc_trx_idIf true, increments the transaction id for a new trx

Definition at line 943 of file transaction_services.cc.

References drizzled::Session::getTransactionMessage(), and drizzled::Session::setTransactionMessage().

message::Statement & drizzled::TransactionServices::getDeleteStatement ( Session session,
Table table,
uint32_t *  next_segment_id 
)
staticprivate

Helper method which returns an initialized Statement message for methods doing deletion of data.

Parameters
[in]sessionSession object doing the processing
[in]tableTable object being deleted from
[out]next_segment_idThe next Statement segment id to be used

Definition at line 1654 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), and drizzled::Session::setStatementMessage().

message::Statement & drizzled::TransactionServices::getInsertStatement ( Session session,
Table table,
uint32_t *  next_segment_id 
)
staticprivate

Helper method which returns an initialized Statement message for methods doing insertion of data.

Parameters
[in]sessionSession object doing the processing
[in]tableTable object being inserted into
[out]next_segment_idThe next Statement segment id to be used

Definition at line 1202 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), and drizzled::Session::setStatementMessage().

message::Statement & drizzled::TransactionServices::getUpdateStatement ( Session session,
Table table,
const unsigned char *  old_record,
const unsigned char *  new_record,
uint32_t *  next_segment_id 
)
staticprivate

Helper method which returns an initialized Statement message for methods doing updates of data.

Parameters
[in]sessionSession object doing the processing
[in]tableTable object being updated
[in]old_recordPointer to the old data in the record
[in]new_recordPointer to the new data in the record
[out]next_segment_idThe next Statement segment id to be used

Definition at line 1382 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), and drizzled::Session::setStatementMessage().

void drizzled::TransactionServices::initStatementMessage ( message::Statement statement,
message::Statement::Type  type,
const Session session 
)
staticprivate

Helper method which initializes a Statement message

Parameters
statementThe statement to initialize
typeThe type of the statement
sessionThe Session object processing this statement

Definition at line 1046 of file transaction_services.cc.

References drizzled::Session::variables.

void drizzled::TransactionServices::initTransactionMessage ( message::Transaction transaction,
Session session,
bool  should_inc_trx_id 
)
staticprivate

Method which attaches a transaction context the supplied transaction based on the supplied Session's transaction information. This method also ensure the transaction message is attached properly to the Session object

Parameters
transactionThe transaction message to initialize
sessionThe Session object processing this transaction
should_inc_trx_idIf true, increments the transaction id for a new trx

Definition at line 962 of file transaction_services.cc.

References drizzled::Session::getServerId().

bool drizzled::TransactionServices::insertRecord ( Session session,
Table in_table 
)
static

Creates a new InsertRecord GPB message and pushes it to replicators.

Parameters
sessionSession object which has inserted a record
tableTable object containing insert information

Grr, returning "true" here on error because of the cursor reversed bool return crap...fix that.

We do this check here because we don't want to even create a statement if there isn't a primary key on the table...

Todo:

Multi-column primary keys are handled how exactly?

Definition at line 1324 of file transaction_services.cc.

References drizzled::Session::mem_root.

bool drizzled::TransactionServices::isFieldUpdated ( Field current_field,
Table table,
const unsigned char *  old_record,
const unsigned char *  new_record 
)
staticprivate

Checks if a field has been updated

Parameters
current_fieldPointer to the field to check if it is updated
tableTable object containing update information
old_recordPointer to the raw bytes representing the old record/row
new_recordPointer to the raw bytes representing the new record/row

This isn't always correct...check varchar diffs.

Definition at line 1613 of file transaction_services.cc.

References drizzled::Field::pack_length(), and drizzled::Field::ptr.

static void drizzled::TransactionServices::rawStatement ( Session ,
const std::string &  query,
const std::string &  schema 
)
static

Creates a new RawSql GPB message and pushes it to replicators.

With a real data dictionary, this really shouldn't be needed. CREATE TABLE would map to insertRecord call on the I_S, etc. Not sure what to do with administrative commands like CHECK TABLE, though..

Parameters
sessionSession object which issued the statement
queryQuery string
schemaSchema for the table affected by the raw SQL.

Referenced by drizzled::internal_alter_table().

void drizzled::TransactionServices::registerResourceForStatement ( Session session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine 
)
static

Marks a storage engine as participating in a statement transaction.

Note

This method is idempotent

Todo:

This method should not be called more than once per resource per statement, and therefore should not need to be idempotent. Put in assert()s to test this.

Parameters
[in]sessionSession object
[in]monitoredDescriptor for the resource which will be participating
[in]enginePointer to the TransactionalStorageEngine resource

Definition at line 313 of file transaction_services.cc.

References drizzled::ResourceContext::isStarted(), drizzled::plugin::MonitoredInTransaction::participatesInSqlTransaction(), drizzled::plugin::MonitoredInTransaction::participatesInXaTransaction(), drizzled::TransactionContext::registerResource(), drizzled::ResourceContext::setMonitored(), drizzled::ResourceContext::setTransactionalStorageEngine(), and drizzled::session::Transactions::stmt.

void drizzled::TransactionServices::registerResourceForStatement ( Session session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine,
plugin::XaResourceManager resource_manager 
)
static

Marks an XA storage engine as participating in a statement transaction.

Note

This method is idempotent

Todo:

This method should not be called more than once per resource per statement, and therefore should not need to be idempotent. Put in assert()s to test this.

Parameters
[in]sessionSession object
[in]monitoredDescriptor for the resource which will be participating
[in]enginePointer to the TransactionalStorageEngine resource
[in]resource_managerPointer to the XaResourceManager resource manager

Definition at line 344 of file transaction_services.cc.

References drizzled::ResourceContext::isStarted(), drizzled::plugin::MonitoredInTransaction::participatesInSqlTransaction(), drizzled::plugin::MonitoredInTransaction::participatesInXaTransaction(), drizzled::TransactionContext::registerResource(), drizzled::ResourceContext::setMonitored(), drizzled::ResourceContext::setTransactionalStorageEngine(), drizzled::ResourceContext::setXaResourceManager(), and drizzled::session::Transactions::stmt.

void drizzled::TransactionServices::registerResourceForTransaction ( Session session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine 
)
static

Registers a resource manager in the "normal" transaction.

Note

This method is idempotent and must be idempotent because it can be called both by the above TransactionServices::registerResourceForStatement(), which occurs at the beginning of each SQL statement, and also manually when a BEGIN WORK/START TRANSACTION statement is executed. If the latter case (BEGIN WORK) is called, then subsequent contained statement transactions will call this method as well.

Note

This method checks to see if the supplied resource is also registered in the statement transaction, and if not, registers the resource in the statement transaction. This happens ONLY when the user has called BEGIN WORK/START TRANSACTION, which is the only time when this method is called except from the TransactionServices::registerResourceForStatement method.

Definition at line 376 of file transaction_services.cc.

References drizzled::session::Transactions::all, drizzled::Session::getQueryId(), drizzled::ResourceContext::isStarted(), drizzled::plugin::MonitoredInTransaction::participatesInSqlTransaction(), drizzled::plugin::MonitoredInTransaction::participatesInXaTransaction(), drizzled::TransactionContext::registerResource(), drizzled::ResourceContext::setMonitored(), and drizzled::ResourceContext::setTransactionalStorageEngine().

void drizzled::TransactionServices::rollbackStatementMessage ( Session session)
staticprivate

Rolls back the current statement, deleting the last Statement out of the current Transaction message.

Parameters
sessionSession object committing the transaction
Note
This depends on having clear statement boundaries (i.e., one Statement message per actual SQL statement).

Definition at line 1119 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), and drizzled::Session::setStatementMessage().

void drizzled::TransactionServices::rollbackTransactionMessage ( Session session)
staticprivate

Marks the current active transaction message as being rolled back and pushes the transaction message out to replicators.

Parameters
sessionSession object committing the transaction

Definition at line 1064 of file transaction_services.cc.

message::Transaction * drizzled::TransactionServices::segmentTransactionMessage ( Session session,
message::Transaction transaction 
)
staticprivate

Makes a given Transaction message segmented.

The given Transaction message will have its segment information set appropriately and a new Transaction message, containing the same transaction ID as the supplied Transaction, and is created.

Parameters
sessionSession object
transactionTransaction message to segment.
Returns
Returns a pointer to a new Transaction message ready for use.

Definition at line 1184 of file transaction_services.cc.

int drizzled::TransactionServices::sendEvent ( Session session,
const message::Event event 
)
staticprivate

Create a Transaction that contains event information and send it off.

This differs from other uses of Transaction in that we don't use the message associated with Session. We create a totally new message and use it.

Parameters
sessionSession object
eventEvent message to send
Note
Used by the public Events API.
Returns
Non-zero on error

Definition at line 2065 of file transaction_services.cc.

bool drizzled::TransactionServices::sendShutdownEvent ( Session session)
static

Send server shutdown event.

Parameters
sessionSession object
Return values
trueSuccess
falseFailure

Definition at line 2090 of file transaction_services.cc.

bool drizzled::TransactionServices::sendStartupEvent ( Session session)
static

Send server startup event.

Parameters
sessionSession object
Return values
trueSuccess
falseFailure

Definition at line 2083 of file transaction_services.cc.

void drizzled::TransactionServices::setDeleteHeader ( message::Statement statement,
const Session session,
Table table 
)
staticprivate

Helper method which initializes the header message for insert operations.

Parameters
[in,out]statementStatement message container to modify
[in]sessionSession object doing the processing
[in]tableTable object being deleted from

Definition at line 1744 of file transaction_services.cc.

References drizzled::Field::field_name, and drizzled::TableShare::fieldInPrimaryKey().

void drizzled::TransactionServices::setInsertHeader ( message::Statement statement,
const Session session,
Table table 
)
staticprivate

Helper method which initializes the header message for insert operations.

Parameters
[in,out]statementStatement message container to modify
[in]sessionSession object doing the processing
[in]tableTable object being inserted into

Definition at line 1292 of file transaction_services.cc.

int drizzled::TransactionServices::setSavepoint ( Session session,
NamedSavepoint sv 
)
static
Note
according to the sql standard (ISO/IEC 9075-2:2003) section "4.33.4 SQL-statements and transaction states", NamedSavepoint is not transaction-initiating SQL-statement

Definition at line 867 of file transaction_services.cc.

References drizzled::session::Transactions::all, drizzled::Session::getTransactionMessage(), and drizzled::plugin::MonitoredInTransaction::participatesInSqlTransaction().

void drizzled::TransactionServices::setUpdateHeader ( message::Statement statement,
const Session session,
Table table,
const unsigned char *  old_record,
const unsigned char *  new_record 
)
staticprivate

Helper method which initializes the header message for update operations.

Parameters
[in,out]statementStatement message container to modify
[in]sessionSession object doing the processing
[in]tableTable object being updated
[in]old_recordPointer to the old data in the record
[in]new_recordPointer to the new data in the record

Definition at line 1474 of file transaction_services.cc.

References drizzled::Field::field_name, and drizzled::TableShare::fieldInPrimaryKey().

bool drizzled::TransactionServices::shouldConstructMessages ( )
static

Returns true if the transaction manager should construct Transaction and Statement messages, false otherwise.

Definition at line 938 of file transaction_services.cc.

void drizzled::TransactionServices::truncateTable ( Session session,
Table table 
)
static

Creates a TruncateTable Statement GPB message and adds it to the Session's active Transaction GPB message for pushing out to the replicator streams.

Parameters
[in]sessionSession object which issued the statement
[in]tableThe Table being truncated

Definition at line 2010 of file transaction_services.cc.

void drizzled::TransactionServices::updateRecord ( Session session,
Table table,
const unsigned char *  old_record,
const unsigned char *  new_record 
)
static

Creates a new UpdateRecord GPB message and pushes it to replicators.

Parameters
sessionSession object which has updated a record
tableTable object containing update information
old_recordPointer to the raw bytes representing the old record/row
new_recordPointer to the raw bytes representing the new record/row

To say the below is ugly is an understatement. But it works.

Todo:
Move this crap into a real Record API.

Definition at line 1524 of file transaction_services.cc.

References drizzled::TableShare::fieldInPrimaryKey(), and drizzled::Session::mem_root.


The documentation for this class was generated from the following files: