~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/ha_trx_info.h

  • Committer: Jay Pipes
  • Date: 2009-09-15 21:01:42 UTC
  • mto: (1126.2.5 merge)
  • mto: This revision was merged to the branch mainline in revision 1128.
  • Revision ID: jpipes@serialcoder-20090915210142-x8mwiqn1q0vzjspp
Moves Alter_info out into its own header and source file, cleans up some related include mess in sql_lex.h, and renames Alter_info to AlterInfo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *  Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
 
4
 *  Copyright (C) 2008 Sun Microsystems
6
5
 *
7
6
 *  This program is free software; you can redistribute it and/or modify
8
7
 *  it under the terms of the GNU General Public License as published by
18
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
18
 */
20
19
 
21
 
#ifndef DRIZZLED_RESOURCE_CONTEXT_H
22
 
#define DRIZZLED_RESOURCE_CONTEXT_H
23
 
 
24
 
#include <cstddef>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
namespace plugin
30
 
{
31
 
class MonitoredInTransaction;
32
 
class TransactionalStorageEngine;
33
 
class XaResourceManager;
34
 
}
 
20
#ifndef DRIZZLED_HA_TRX_INFO_H
 
21
#define DRIZZLED_HA_TRX_INFO_H
 
22
 
 
23
 
 
24
class Session_TRANS;
 
25
class StorageEngine;
35
26
 
36
27
/**
37
 
 * Either statement transaction or normal transaction - related
38
 
 * session-specific resource manager data state.
39
 
 *
40
 
 * If a resource manager participates in a statement/transaction,
41
 
 * an instance of this class is present in
42
 
 * session->transaction.{stmt|all}.resource_contexts.
43
 
 *
44
 
 * When it's time to commit or rollback, each resource context
45
 
 * is used to access the resource manager's prepare()/commit()/rollback()
46
 
 * methods, and also to evaluate if a full two phase commit is
47
 
 * necessary.
48
 
 * 
49
 
 * @sa General description of transaction handling in drizzled/transaction_services.cc.
50
 
 */
51
 
class ResourceContext
 
28
  Either statement transaction or normal transaction - related
 
29
  thread-specific storage engine data.
 
30
 
 
31
  If a storage engine participates in a statement/transaction,
 
32
  an instance of this class is present in
 
33
  session->transaction.{stmt|all}.ha_list. The addition to
 
34
  {stmt|all}.ha_list is made by trans_register_ha().
 
35
 
 
36
  When it's time to commit or rollback, each element of ha_list
 
37
  is used to access storage engine's prepare()/commit()/rollback()
 
38
  methods, and also to evaluate if a full two phase commit is
 
39
  necessary.
 
40
 
 
41
  @sa General description of transaction handling in handler.cc.
 
42
*/
 
43
 
 
44
class Ha_trx_info
52
45
{
53
46
public:
54
 
  ResourceContext() :
55
 
    monitored(NULL),
56
 
    xa_resource_manager(NULL),
57
 
    trx_storage_engine(NULL),
58
 
    modified_data(false)
59
 
  {}
 
47
  /** Register this storage engine in the given transaction context. */
 
48
  void register_ha(Session_TRANS *trans, StorageEngine *engine_arg);
60
49
 
61
50
  /** Clear, prepare for reuse. */
62
51
  void reset();
63
 
 
64
 
  /**
65
 
   * Marks that the underlying resource manager
66
 
   * has modified data state.
67
 
   */
68
 
  void markModifiedData();
69
 
 
70
 
  /**
71
 
   * Returns true if the underlying resource manager
72
 
   * has modified data state.
73
 
   */
74
 
  bool hasModifiedData() const;
75
 
 
76
 
  /**
77
 
   * Returns true if the underlying resource
78
 
   * manager has registered with the transaction
79
 
   * manager for this transaction.
80
 
   */
81
 
  bool isStarted() const;
82
 
 
83
 
  /** 
84
 
   * Mark this context as modifying data if the argument has also modified data
85
 
   */
86
 
  void coalesceWith(const ResourceContext *stmt_trx);
87
 
 
88
 
  /**
89
 
   * Returns the underlying descriptor for the resource
90
 
   * this context tracks.
91
 
   */
92
 
  plugin::MonitoredInTransaction *getMonitored() const
93
 
  {
94
 
    return monitored;
95
 
  }
96
 
 
97
 
  /**
98
 
   * Sets the underlying descriptor for the resource
99
 
   */
100
 
  void setMonitored(plugin::MonitoredInTransaction *in_monitored)
101
 
  {
102
 
    monitored= in_monitored;
103
 
  }
104
 
 
105
 
  /**
106
 
   * Returns the underlying transactional storage engine
107
 
   * this context tracks or NULL if not SQL transactional capable.
108
 
   */
109
 
  plugin::TransactionalStorageEngine *getTransactionalStorageEngine() const
110
 
  {
111
 
    return trx_storage_engine;
112
 
  }
113
 
 
114
 
  /**
115
 
   * Sets the underlying transactional storage engine
116
 
   */
117
 
  void setTransactionalStorageEngine(plugin::TransactionalStorageEngine *in_trx_storage_engine)
118
 
  {
119
 
    trx_storage_engine= in_trx_storage_engine;
120
 
  }
121
 
 
122
 
  /**
123
 
   * Returns the underlying XA resource manager
124
 
   * this context tracks or NULL if not XA capable.
125
 
   */
126
 
  plugin::XaResourceManager *getXaResourceManager() const
127
 
  {
128
 
    return xa_resource_manager;
129
 
  }
130
 
 
131
 
  /**
132
 
   * Sets the underlying xa resource manager
133
 
   */
134
 
  void setXaResourceManager(plugin::XaResourceManager *in_xa_resource_manager)
135
 
  {
136
 
    xa_resource_manager= in_xa_resource_manager;
137
 
  }
 
52
  Ha_trx_info() { reset(); }
 
53
 
 
54
  void set_trx_read_write();
 
55
  bool is_trx_read_write() const;
 
56
  bool is_started() const;
 
57
 
 
58
  /** Mark this transaction read-write if the argument is read-write. */
 
59
  void coalesce_trx_with(const Ha_trx_info *stmt_trx);
 
60
  Ha_trx_info *next() const;
 
61
  StorageEngine *engine() const;
 
62
 
138
63
private:
139
 
  /**
140
 
   * A descriptor of the monitored resource
141
 
   */
142
 
  plugin::MonitoredInTransaction *monitored;
143
 
  /**
144
 
   * The XA resource manager or NULL if not XA capable.
145
 
   */
146
 
  plugin::XaResourceManager *xa_resource_manager;
147
 
  /**
148
 
   * The transactional storage engine or NULL if not SQL transaction capable.
149
 
   */
150
 
  plugin::TransactionalStorageEngine *trx_storage_engine;
151
 
  /**
152
 
   * Whether the underlying resource manager has changed
153
 
   * some data state.
154
 
   */
155
 
  bool modified_data;
 
64
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
 
65
  /** Auxiliary, used for ha_list management */
 
66
  Ha_trx_info *m_next;
 
67
  /**
 
68
    Although a given Ha_trx_info instance is currently always used
 
69
    for the same storage engine, 'engine' is not-NULL only when the
 
70
    corresponding storage is a part of a transaction.
 
71
  */
 
72
  StorageEngine *m_engine;
 
73
  /**
 
74
    Transaction flags related to this engine.
 
75
    Not-null only if this instance is a part of transaction.
 
76
    May assume a combination of enum values above.
 
77
  */
 
78
  unsigned char       m_flags;
156
79
};
157
80
 
158
 
} /* namespace drizzled */
159
 
 
160
 
#endif /* DRIZZLED_RESOURCE_CONTEXT_H */
 
81
#endif /* DRIZZLED_HA_TRX_INFO_H */