297
300
* transaction after all DDLs, just like the statement transaction
298
301
* is always committed at the end of all statements.
303
TransactionServices::TransactionServices()
305
plugin::StorageEngine *engine= plugin::StorageEngine::findByName("InnoDB");
308
xa_storage_engine= (plugin::XaStorageEngine*)engine;
312
xa_storage_engine= NULL;
300
316
void TransactionServices::registerResourceForStatement(Session *session,
301
317
plugin::MonitoredInTransaction *monitored,
302
318
plugin::TransactionalStorageEngine *engine)
424
440
registerResourceForStatement(session, monitored, engine, resource_manager);
443
void TransactionServices::allocateNewTransactionId()
445
ReplicationServices &replication_services= ReplicationServices::singleton();
446
if (! replication_services.isActive())
451
Session *my_session= current_session;
452
uint64_t xa_id= xa_storage_engine->getNewTransactionId(my_session);
453
my_session->setXaId(xa_id);
456
uint64_t TransactionServices::getCurrentTransactionId(Session *session)
458
if (session->getXaId() == 0)
460
session->setXaId(xa_storage_engine->getNewTransactionId(session));
463
return session->getXaId();
1886
* Template for removing Statement records of different types.
1888
* The code for removing records from different Statement message types
1889
* is identical except for the class types that are embedded within the
1892
* There are 3 scenarios we need to look for:
1893
* - We've been asked to remove more records than exist in the Statement
1894
* - We've been asked to remove less records than exist in the Statement
1895
* - We've been asked to remove ALL records that exist in the Statement
1897
* If we are removing ALL records, then effectively we would be left with
1898
* an empty Statement message, so we should just remove it and clean up
1899
* message pointers in the Session object.
1901
template <class DataType, class RecordType>
1902
static bool removeStatementRecordsWithType(Session *session,
1906
uint32_t num_avail_recs= static_cast<uint32_t>(data->record_size());
1908
/* If there aren't enough records to remove 'count' of them, error. */
1909
if (num_avail_recs < count)
1913
* If we are removing all of the data records, we'll just remove this
1914
* entire Statement message.
1916
if (num_avail_recs == count)
1918
message::Transaction *transaction= session->getTransactionMessage();
1919
protobuf::RepeatedPtrField<message::Statement> *statements= transaction->mutable_statement();
1920
statements->RemoveLast();
1923
* Now need to set the Session Statement pointer to either the previous
1924
* Statement, or NULL if there isn't one.
1926
if (statements->size() == 0)
1928
session->setStatementMessage(NULL);
1933
* There isn't a great way to get a pointer to the previous Statement
1934
* message using the RepeatedPtrField object, so we'll just get to it
1935
* using the Transaction message.
1937
int last_stmt_idx= transaction->statement_size() - 1;
1938
session->setStatementMessage(transaction->mutable_statement(last_stmt_idx));
1941
/* We only need to remove 'count' records */
1942
else if (num_avail_recs > count)
1944
protobuf::RepeatedPtrField<RecordType> *records= data->mutable_record();
1946
records->RemoveLast();
1953
bool TransactionServices::removeStatementRecords(Session *session,
1956
ReplicationServices &replication_services= ReplicationServices::singleton();
1957
if (! replication_services.isActive())
1960
/* Get the most current Statement */
1961
message::Statement *statement= session->getStatementMessage();
1963
/* Make sure we have work to do */
1964
if (statement == NULL)
1969
switch (statement->type())
1971
case message::Statement::INSERT:
1973
message::InsertData *data= statement->mutable_insert_data();
1974
retval= removeStatementRecordsWithType<message::InsertData, message::InsertRecord>(session, data, count);
1978
case message::Statement::UPDATE:
1980
message::UpdateData *data= statement->mutable_update_data();
1981
retval= removeStatementRecordsWithType<message::UpdateData, message::UpdateRecord>(session, data, count);
1985
case message::Statement::DELETE: /* not sure if this one is possible... */
1987
message::DeleteData *data= statement->mutable_delete_data();
1988
retval= removeStatementRecordsWithType<message::DeleteData, message::DeleteRecord>(session, data, count);
1839
2001
void TransactionServices::createTable(Session *in_session,
1840
2002
const message::Table &table)