~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_context.h

* Renames Ha_trx_info to drizzled::ResourceContext
* Renames Sesssion_TRANS to drizzled::TransactionContext
* Replaces homegrown linked-lists of Ha_trx_info pointers
  with vector<drizzled::ResourceContext> operations
* Renames Session::getEngineInfo() to Session::getResourceContext()

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_TRANSACTION_CONTEXT_H
 
21
#define DRIZZLED_TRANSACTION_CONTEXT_H
 
22
 
 
23
#include <vector>
 
24
 
 
25
namespace drizzled
 
26
{
 
27
class ResourceContext;
 
28
 
 
29
class TransactionContext
 
30
{
 
31
public:
 
32
  TransactionContext() :
 
33
    no_2pc(false),
 
34
    resource_contexts(),
 
35
    modified_non_trans_table(false)
 
36
  {}
 
37
 
 
38
  void reset() { no_2pc= false; modified_non_trans_table= false; resource_contexts.clear();}
 
39
 
 
40
  typedef std::vector<ResourceContext *> ResourceContexts;
 
41
 
 
42
  void setResourceContexts(ResourceContexts &new_contexts)
 
43
  {
 
44
    resource_contexts.assign(new_contexts.begin(), new_contexts.end());
 
45
  }
 
46
 
 
47
  ResourceContexts &getResourceContexts()
 
48
  {
 
49
    return resource_contexts;
 
50
  }
 
51
  /** Register a resource context in this transaction context */
 
52
  void registerResource(ResourceContext *resource)
 
53
  {
 
54
    resource_contexts.push_back(resource);
 
55
  }
 
56
 
 
57
  /* true is not all entries in the resource contexts support 2pc */
 
58
  bool no_2pc;
 
59
private:
 
60
  /* storage engines that registered in this transaction */
 
61
  ResourceContexts resource_contexts;
 
62
public:
 
63
  /*
 
64
    The purpose of this flag is to keep track of non-transactional
 
65
    tables that were modified in scope of:
 
66
    - transaction, when the variable is a member of
 
67
    Session::transaction.all
 
68
    - top-level statement or sub-statement, when the variable is a
 
69
    member of Session::transaction.stmt
 
70
    This member has the following life cycle:
 
71
    * stmt.modified_non_trans_table is used to keep track of
 
72
    modified non-transactional tables of top-level statements. At
 
73
    the end of the previous statement and at the beginning of the session,
 
74
    it is reset to false.  If such functions
 
75
    as mysql_insert, mysql_update, mysql_delete etc modify a
 
76
    non-transactional table, they set this flag to true.  At the
 
77
    end of the statement, the value of stmt.modified_non_trans_table
 
78
    is merged with all.modified_non_trans_table and gets reset.
 
79
    * all.modified_non_trans_table is reset at the end of transaction
 
80
 
 
81
    * Since we do not have a dedicated context for execution of a
 
82
    sub-statement, to keep track of non-transactional changes in a
 
83
    sub-statement, we re-use stmt.modified_non_trans_table.
 
84
    At entrance into a sub-statement, a copy of the value of
 
85
    stmt.modified_non_trans_table (containing the changes of the
 
86
    outer statement) is saved on stack. Then
 
87
    stmt.modified_non_trans_table is reset to false and the
 
88
    substatement is executed. Then the new value is merged with the
 
89
    saved value.
 
90
  */
 
91
  bool modified_non_trans_table;
 
92
};
 
93
 
 
94
} /* namespace drizzled */
 
95
 
 
96
#endif /* DRIZZLED_TRANSACTION_CONTEXT_H */