~fallenpegasus/drizzle/work-foo

« back to all changes in this revision

Viewing changes to plugin/transaction_log/utilities/transaction_manager.h

  • Committer: Continuous Integration
  • Date: 2012-03-04 12:46:01 UTC
  • mfrom: (2516.2.1 workspace)
  • Revision ID: ci@drizzle.org-20120304124601-nqj8znhwmhhbsbha
Merge staging tree to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 David Shrewsbury <shrewsbury.dave@gmail.com>
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
/**
21
 
 * @file
22
 
 * Declaration of a class used to manage Transaction messages so that they
23
 
 * can be retrieved as a collection.
24
 
 */
25
 
 
26
 
#pragma once
27
 
 
28
 
#include <drizzled/message/transaction.pb.h>
29
 
#include <string>
30
 
#include <vector>
31
 
#include <boost/unordered_map.hpp>
32
 
 
33
 
typedef std::vector<std::string> MsgBufferType;
34
 
 
35
 
 
36
 
/**
37
 
 * Simple (example) Transaction message buffer and content manager.
38
 
 *
39
 
 * @details
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.
44
 
 *
45
 
 * @note
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.
48
 
 */
49
 
class TransactionManager
50
 
{
51
 
public:
52
 
  /**
53
 
   * Store the given Transaction message in a buffer.
54
 
   *
55
 
   * @param[in] transaction Pointer to the Transaction message to store.
56
 
   *
57
 
   * @retval true Success
58
 
   * @retval false Failure
59
 
   */
60
 
  bool store(const drizzled::message::Transaction &transaction);
61
 
 
62
 
  /**
63
 
   * Clear the buffer contents for a given transaction ID.
64
 
   *
65
 
   * @param[in] trx_id The transaction ID for the transaction to remove
66
 
   *
67
 
   * @retval true Success
68
 
   * @retval false Failure
69
 
   */
70
 
  bool remove(uint64_t trx_id);
71
 
 
72
 
  /**
73
 
   * Check to see if any Transaction messages exist for a given transaction.
74
 
   *
75
 
   * @param[in] trx_id The transaction ID to check for.
76
 
   *
77
 
   * @retval true Transaction messages exist
78
 
   * @retval false No Transaction messages found
79
 
   */
80
 
  bool contains(uint64_t trx_id);
81
 
 
82
 
  /**
83
 
   * Return number of cached elements for the given transaction ID.
84
 
   *
85
 
   * @param[in] trx_id Transaction ID
86
 
   *
87
 
   * @returns The number of cached elements associated with trx_id.
88
 
   */
89
 
  uint32_t getTransactionBufferSize(uint64_t trx_id);
90
 
 
91
 
  /**
92
 
   * Retrieve a Transaction message from the managed cache.
93
 
   *
94
 
   * Caller must supply a Transaction message to populate. The Transaction
95
 
   * message to retrieve is indexed by a combination of transaction ID and
96
 
   * position.
97
 
   *
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
101
 
   *
102
 
   * @retval true Success
103
 
   * @retval false Failure
104
 
   */
105
 
  bool getTransactionMessage(drizzled::message::Transaction &transaction,
106
 
                             uint64_t trx_id,
107
 
                             uint32_t position);
108
 
 
109
 
private:
110
 
  /**
111
 
   * Our message buffer cache, mapped by the transaction ID.
112
 
   *
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).
117
 
   */
118
 
  boost::unordered_map<uint64_t,MsgBufferType> cache;
119
 
};
120