1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 David Shrewsbury <shrewsbury.dave@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
* Declaration of a class used to manage Transaction messages so that they
23
* can be retrieved as a collection.
28
#include <drizzled/message/transaction.pb.h>
31
#include <boost/unordered_map.hpp>
33
typedef std::vector<std::string> MsgBufferType;
37
* Simple (example) Transaction message buffer and content manager.
40
* This class groups Transaction messages together by transaction ID and
41
* buffers them together in memory. Obviously, this could eat up a lot of
42
* memory if you have very large transactions. A more robust implementation
43
* would buffer larger transactions to disk rather than memory.
46
* Once you have a complete transaction and have processed it, you should
47
* call remove() to remove the cache contents for that transaction from memory.
49
class TransactionManager
53
* Store the given Transaction message in a buffer.
55
* @param[in] transaction Pointer to the Transaction message to store.
57
* @retval true Success
58
* @retval false Failure
60
bool store(const drizzled::message::Transaction &transaction);
63
* Clear the buffer contents for a given transaction ID.
65
* @param[in] trx_id The transaction ID for the transaction to remove
67
* @retval true Success
68
* @retval false Failure
70
bool remove(uint64_t trx_id);
73
* Check to see if any Transaction messages exist for a given transaction.
75
* @param[in] trx_id The transaction ID to check for.
77
* @retval true Transaction messages exist
78
* @retval false No Transaction messages found
80
bool contains(uint64_t trx_id);
83
* Return number of cached elements for the given transaction ID.
85
* @param[in] trx_id Transaction ID
87
* @returns The number of cached elements associated with trx_id.
89
uint32_t getTransactionBufferSize(uint64_t trx_id);
92
* Retrieve a Transaction message from the managed cache.
94
* Caller must supply a Transaction message to populate. The Transaction
95
* message to retrieve is indexed by a combination of transaction ID and
98
* @param[out] transaction Transaction message to populate
99
* @param[in] trx_id Transaction ID
100
* @param[in] position Index into the buffer associated with trx_id
102
* @retval true Success
103
* @retval false Failure
105
bool getTransactionMessage(drizzled::message::Transaction &transaction,
111
* Our message buffer cache, mapped by the transaction ID.
113
* We organize Transactions messages by grouping them by transaction ID,
114
* then storing the messages in std::vectors in std::string format. The
115
* string format is convenient because it can be easily copied around
116
* (GPB messages do not provide deep copying).
118
boost::unordered_map<uint64_t,MsgBufferType> cache;