Drizzled Public API Documentation

drizzled::TransactionServices Class Reference

#include <transaction_services.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

static TransactionServicessingleton ()

Static Public Attributes

static const size_t DEFAULT_RECORD_SIZE = 100

Private Member Functions

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

Private Attributes

plugin::XaStorageEnginexa_storage_engine

Detailed Description

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

Definition at line 56 of file transaction_services.h.


Member Function Documentation

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

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 2008 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

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 719 of file transaction_services.cc.

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

Referenced by drizzled::Session::close_thread_tables(), and drizzled::dispatch_command().

void drizzled::TransactionServices::cleanupTransactionMessage ( message::Transaction transaction,
Session::reference  session 
) [private]

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

Definition at line 1041 of file transaction_services.cc.

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

int drizzled::TransactionServices::commitTransaction ( Session::reference  session,
bool  all 
)

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 466 of file transaction_services.cc.

References drizzled::session::Transactions::all, drizzled::ResourceContext::getMonitored(), drizzled::ResourceContext::getXaResourceManager(), drizzled::ResourceContext::hasModifiedData(), drizzled::plugin::MonitoredInTransaction::participatesInXaTransaction(), drizzled::Session::status_var, and drizzled::session::Transactions::stmt.

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

int drizzled::TransactionServices::commitTransactionMessage ( Session::reference  session) [private]

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

Parameters:
sessionSession object committing the transaction

Definition at line 1050 of file transaction_services.cc.

References drizzled::Session::getStatementMessage(), drizzled::Session::getTransactionMessage(), drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

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 1942 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

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 1909 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

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 1849 of file transaction_services.cc.

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

Referenced by drizzled::log_row_for_replication().

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

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 255 of file schema_engine.cc.

References drizzled::Session::clear_error(), drizzled::Open_tables_state::drop_temporary_table(), dropSchema(), drizzled::Session::my_ok(), and singleton().

Referenced by dropSchema().

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

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 2045 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

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 1105 of file transaction_services.cc.

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

Referenced by drizzled::log_row_for_replication().

void drizzled::TransactionServices::finalizeTransactionMessage ( message::Transaction transaction,
Session::const_reference  session 
) [private]

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 1034 of file transaction_services.cc.

References drizzled::Session::getCurrentTimestamp().

message::Transaction * drizzled::TransactionServices::getActiveTransactionMessage ( Session::reference  session,
bool  should_inc_trx_id = true 
) [private]

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 988 of file transaction_services.cc.

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

message::Statement & drizzled::TransactionServices::getDeleteStatement ( Session::reference  session,
Table table,
uint32_t *  next_segment_id 
) [private]

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 1717 of file transaction_services.cc.

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

message::Statement & drizzled::TransactionServices::getInsertStatement ( Session::reference  session,
Table table,
uint32_t *  next_segment_id 
) [private]

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 1252 of file transaction_services.cc.

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

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

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 1439 of file transaction_services.cc.

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

void drizzled::TransactionServices::initStatementMessage ( message::Statement statement,
message::Statement::Type  type,
Session::const_reference  session 
) [private]

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 1094 of file transaction_services.cc.

References drizzled::Session::getCurrentTimestamp(), and drizzled::Session::variables.

void drizzled::TransactionServices::initTransactionMessage ( message::Transaction transaction,
Session::reference  session,
bool  should_inc_trx_id 
) [private]

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 1009 of file transaction_services.cc.

References drizzled::Session::getCurrentTimestamp(), and drizzled::Session::getServerId().

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

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 1380 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::Session::mem_root.

Referenced by drizzled::log_row_for_replication().

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

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 1676 of file transaction_services.cc.

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

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

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::reference  session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine,
plugin::XaResourceManager resource_manager 
)

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 348 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::registerResourceForStatement ( Session::reference  session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine 
)

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 316 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::registerResourceForTransaction ( Session::reference  session,
plugin::MonitoredInTransaction monitored,
plugin::TransactionalStorageEngine engine 
)

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 382 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::reference  session) [private]

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 1168 of file transaction_services.cc.

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

void drizzled::TransactionServices::rollbackTransactionMessage ( Session::reference  session) [private]

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 1112 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

message::Transaction * drizzled::TransactionServices::segmentTransactionMessage ( Session::reference  session,
message::Transaction transaction 
) [private]

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 1234 of file transaction_services.cc.

int drizzled::TransactionServices::sendEvent ( Session::reference  session,
const message::Event event 
) [private]

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 2148 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

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

Send server shutdown event.

Parameters:
sessionSession object
Return values:
trueSuccess
falseFailure

Definition at line 2183 of file transaction_services.cc.

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

Send server startup event.

Parameters:
sessionSession object
Return values:
trueSuccess
falseFailure

Definition at line 2174 of file transaction_services.cc.

void drizzled::TransactionServices::setDeleteHeader ( message::Statement statement,
Session::const_reference  session,
Table table 
) [private]

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 1807 of file transaction_services.cc.

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

void drizzled::TransactionServices::setInsertHeader ( message::Statement statement,
Session::const_reference  session,
Table table 
) [private]

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 1342 of file transaction_services.cc.

References drizzled::Field::field_name.

int drizzled::TransactionServices::setSavepoint ( Session::reference  session,
NamedSavepoint sv 
)
void drizzled::TransactionServices::setUpdateHeader ( message::Statement statement,
Session::const_reference  session,
Table table,
const unsigned char *  old_record,
const unsigned char *  new_record 
) [private]

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 1531 of file transaction_services.cc.

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

bool drizzled::TransactionServices::shouldConstructMessages ( )

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

Definition at line 982 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive().

Referenced by drizzled::log_row_for_replication().

static TransactionServices& drizzled::TransactionServices::singleton ( ) [inline, static]
void drizzled::TransactionServices::truncateTable ( Session::reference  session,
Table table 
)

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 2084 of file transaction_services.cc.

References drizzled::ReplicationServices::isActive(), and drizzled::ReplicationServices::pushTransactionMessage().

Referenced by drizzled::Cursor::ha_delete_all_rows().

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

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 1586 of file transaction_services.cc.

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

Referenced by drizzled::log_row_for_replication().


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