~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/ha_trx_info.h

  • Committer: Monty Taylor
  • Date: 2008-11-04 18:01:26 UTC
  • mto: (575.1.7 fix-headers)
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: monty@inaugust.com-20081104180126-88cfh3g4q1szu7us
Moved some stuff out of handler.h.

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) 2008 Sun Microsystems
 
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
#ifndef DRIZZLED_HA_TRX_INFO_H
 
21
#define DRIZZLED_HA_TRX_INFO_H
 
22
 
 
23
/**
 
24
  Either statement transaction or normal transaction - related
 
25
  thread-specific storage engine data.
 
26
 
 
27
  If a storage engine participates in a statement/transaction,
 
28
  an instance of this class is present in
 
29
  session->transaction.{stmt|all}.ha_list. The addition to
 
30
  {stmt|all}.ha_list is made by trans_register_ha().
 
31
 
 
32
  When it's time to commit or rollback, each element of ha_list
 
33
  is used to access storage engine's prepare()/commit()/rollback()
 
34
  methods, and also to evaluate if a full two phase commit is
 
35
  necessary.
 
36
 
 
37
  @sa General description of transaction handling in handler.cc.
 
38
*/
 
39
 
 
40
class Ha_trx_info
 
41
{
 
42
public:
 
43
  /** Register this storage engine in the given transaction context. */
 
44
  void register_ha(Session_TRANS *trans, handlerton *ht_arg)
 
45
  {
 
46
    assert(m_flags == 0);
 
47
    assert(m_ht == NULL);
 
48
    assert(m_next == NULL);
 
49
 
 
50
    m_ht= ht_arg;
 
51
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
 
52
 
 
53
    m_next= trans->ha_list;
 
54
    trans->ha_list= this;
 
55
  }
 
56
 
 
57
  /** Clear, prepare for reuse. */
 
58
  void reset()
 
59
  {
 
60
    m_next= NULL;
 
61
    m_ht= NULL;
 
62
    m_flags= 0;
 
63
  }
 
64
 
 
65
  Ha_trx_info() { reset(); }
 
66
 
 
67
  void set_trx_read_write()
 
68
  {
 
69
    assert(is_started());
 
70
    m_flags|= (int) TRX_READ_WRITE;
 
71
  }
 
72
  bool is_trx_read_write() const
 
73
  {
 
74
    assert(is_started());
 
75
    return m_flags & (int) TRX_READ_WRITE;
 
76
  }
 
77
  bool is_started() const { return m_ht != NULL; }
 
78
  /** Mark this transaction read-write if the argument is read-write. */
 
79
  void coalesce_trx_with(const Ha_trx_info *stmt_trx)
 
80
  {
 
81
    /*
 
82
      Must be called only after the transaction has been started.
 
83
      Can be called many times, e.g. when we have many
 
84
      read-write statements in a transaction.
 
85
    */
 
86
    assert(is_started());
 
87
    if (stmt_trx->is_trx_read_write())
 
88
      set_trx_read_write();
 
89
  }
 
90
  Ha_trx_info *next() const
 
91
  {
 
92
    assert(is_started());
 
93
    return m_next;
 
94
  }
 
95
  handlerton *ht() const
 
96
  {
 
97
    assert(is_started());
 
98
    return m_ht;
 
99
  }
 
100
private:
 
101
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
 
102
  /** Auxiliary, used for ha_list management */
 
103
  Ha_trx_info *m_next;
 
104
  /**
 
105
    Although a given Ha_trx_info instance is currently always used
 
106
    for the same storage engine, 'ht' is not-NULL only when the
 
107
    corresponding storage is a part of a transaction.
 
108
  */
 
109
  handlerton *m_ht;
 
110
  /**
 
111
    Transaction flags related to this engine.
 
112
    Not-null only if this instance is a part of transaction.
 
113
    May assume a combination of enum values above.
 
114
  */
 
115
  unsigned char       m_flags;
 
116
};
 
117
 
 
118
#endif /* DRIZZLED_HA_TRX_INFO_H */