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.
26
#ifndef DRIZZLED_MESSAGE_TRANSACTION_MANAGER_H
27
#define DRIZZLED_MESSAGE_TRANSACTION_MANAGER_H
29
#include "drizzled/message/transaction.pb.h"
32
#include <boost/unordered_map.hpp>
34
typedef std::vector<std::string> MsgBufferType;
42
* Simple (example) Transaction message buffer and content manager.
45
* This class groups Transaction messages together by transaction ID and
46
* buffers them together in memory. Obviously, this could eat up a lot of
47
* memory if you have very large transactions. A more robust implementation
48
* would buffer larger transactions to disk rather than memory.
51
* Once you have a complete transaction and have processed it, you should
52
* call remove() to remove the cache contents for that transaction from memory.
54
class TransactionManager
58
* Store the given Transaction message in a buffer.
60
* @param[in] transaction Pointer to the Transaction message to store.
62
* @retval true Success
63
* @retval false Failure
65
bool store(const drizzled::message::Transaction &transaction);
68
* Clear the buffer contents for a given transaction ID.
70
* @param[in] trx_id The transaction ID for the transaction to remove
72
* @retval true Success
73
* @retval false Failure
75
bool remove(uint64_t trx_id);
78
* Check to see if any Transaction messages exist for a given transaction.
80
* @param[in] trx_id The transaction ID to check for.
82
* @retval true Transaction messages exist
83
* @retval false No Transaction messages found
85
bool contains(uint64_t trx_id);
88
* Return number of cached elements for the given transaction ID.
90
* @param[in] trx_id Transaction ID
92
* @returns The number of cached elements associated with trx_id.
94
uint32_t getTransactionBufferSize(uint64_t trx_id);
97
* Retrieve a Transaction message from the managed cache.
99
* Caller must supply a Transaction message to populate. The Transaction
100
* message to retrieve is indexed by a combination of transaction ID and
103
* @param[out] transaction Transaction message to populate
104
* @param[in] trx_id Transaction ID
105
* @param[in] position Index into the buffer associated with trx_id
107
* @retval true Success
108
* @retval false Failure
110
bool getTransactionMessage(drizzled::message::Transaction &transaction,
116
* Our message buffer cache, mapped by the transaction ID.
118
* We organize Transactions messages by grouping them by transaction ID,
119
* then storing the messages in std::vectors in std::string format. The
120
* string format is convenient because it can be easily copied around
121
* (GPB messages do not provide deep copying).
123
boost::unordered_map<uint64_t,MsgBufferType> cache;
126
} /* namespace message */
127
} /* namespace drizzled */
129
#endif /* DRIZZLED_MESSAGE_TRANSACTION_MANAGER_H */