~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/xa_storage_engine.h

  • Committer: Brian Aker
  • Date: 2010-03-05 03:12:24 UTC
  • mfrom: (1273.1.32 bug530870)
  • Revision ID: brian@gaz-20100305031224-ijnk5d5n4dut5mtv
Merge Jay's bugfix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *  Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
7
8
 *  it under the terms of the GNU General Public License as published by
21
22
#define DRIZZLED_PLUGIN_XA_STORAGE_ENGINE_H
22
23
 
23
24
#include "drizzled/plugin/transactional_storage_engine.h"
 
25
#include "drizzled/plugin/xa_resource_manager.h"
24
26
 
25
27
namespace drizzled
26
28
{
33
35
/**
34
36
 * A type of storage engine which supports distributed
35
37
 * transactions in the XA protocol.
 
38
 *
 
39
 * The real XA resource manager interface is in the
 
40
 * plugin::XaResourceManager class.  We would extend
 
41
 * XaResourceManager from plugin::Plugin but unfortunately
 
42
 * that would lead to member name ambiguity (because plugin::Plugin
 
43
 * has member data).  So, in this case, TransactionalStorageEngine
 
44
 * inherits from plugin::Plugin and XaResourceManager is a pure
 
45
 * virtual abstract base class with the X/Open XA distributed
 
46
 * transaction protocol interface for resource managers.
36
47
 */
37
 
class XaStorageEngine :public TransactionalStorageEngine
 
48
class XaStorageEngine :public TransactionalStorageEngine,
 
49
                       public XaResourceManager
38
50
{
39
51
public:
40
52
  XaStorageEngine(const std::string name_arg,
42
54
 
43
55
  virtual ~XaStorageEngine();
44
56
 
45
 
  int prepare(Session *session, bool normal_transaction)
46
 
  {
47
 
    return doPrepare(session, normal_transaction);
48
 
  }
49
 
 
50
 
  int commitXid(XID *xid)
51
 
  {
52
 
    return doCommitXid(xid);
53
 
  }
54
 
 
55
 
  int rollbackXid(XID *xid)
56
 
  {
57
 
    return doRollbackXid(xid);
58
 
  }
59
 
 
60
 
  int recover(XID * append_to, size_t len)
61
 
  {
62
 
    return doRecover(append_to, len);
63
 
  }
64
 
 
65
 
  /** 
66
 
   * The below static class methods wrap the interaction
67
 
   * of the vector of registered XA storage engines.
 
57
  int startTransaction(Session *session, start_transaction_option_t options)
 
58
  {
 
59
    TransactionServices &transaction_services= TransactionServices::singleton();
 
60
    transaction_services.registerResourceForTransaction(session, this, this, this);
 
61
    return doStartTransaction(session, options);
 
62
  }
 
63
 
 
64
  void startStatement(Session *session)
 
65
  {
 
66
    TransactionServices &transaction_services= TransactionServices::singleton();
 
67
    transaction_services.registerResourceForStatement(session, this, this, this);
 
68
    doStartStatement(session);
 
69
  }
 
70
 
 
71
  /* 
 
72
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
 
73
   * interface.
68
74
   */
69
 
  static int commitOrRollbackXID(XID *xid, bool commit);
70
 
  static int recoverAllXids(HASH *commit_list);
 
75
  bool participatesInSqlTransaction() const
 
76
  {
 
77
    return true; /* We DO participate in the SQL transaction */
 
78
  }
 
79
  bool participatesInXaTransaction() const
 
80
  {
 
81
    return true; /* We DO participate in the XA transaction */
 
82
  }
 
83
  bool alwaysRegisterForXaTransaction() const
 
84
  {
 
85
    return false; /* We only register in the XA transaction if the engine's data is modified */
 
86
  }
71
87
 
72
88
  /* Class Methods for operating on plugin */
73
89
  static bool addPlugin(plugin::XaStorageEngine *engine);
74
90
  static void removePlugin(plugin::XaStorageEngine *engine);
75
91
 
76
92
private:
77
 
  /**
78
 
   * Does the PREPARE stage of the two-phase commit.
79
 
   */
80
 
  virtual int doPrepare(Session *session, bool normal_transaction)= 0;
81
 
  /**
82
 
   * Rolls back a transaction identified by a XID.
83
 
   */
84
 
  virtual int doRollbackXid(XID *xid)= 0;
85
 
  /**
86
 
   * Commits a transaction identified by a XID.
87
 
   */
88
 
  virtual int doCommitXid(XID *xid)= 0;
89
 
  /**
90
 
   * Notifies the transaction manager of any transactions
91
 
   * which had been marked prepared but not committed at
92
 
   * crash time or that have been heurtistically completed
93
 
   * by the storage engine.
94
 
   *
95
 
   * @param[out] Reference to a vector of XIDs to add to
96
 
   *
97
 
   * @retval
98
 
   *  Returns the number of transactions left to recover
99
 
   *  for this engine.
100
 
   */
101
 
  virtual int doRecover(XID * append_to, size_t len)= 0;
 
93
  /*
 
94
   * Indicates to a storage engine the start of a
 
95
   * new SQL transaction.  This is called ONLY in the following
 
96
   * scenarios:
 
97
   *
 
98
   * 1) An explicit BEGIN WORK/START TRANSACTION is called
 
99
   * 2) After an explicit COMMIT AND CHAIN is called
 
100
   * 3) After an explicit ROLLBACK AND RELEASE is called
 
101
   * 4) When in AUTOCOMMIT mode and directly before a new
 
102
   *    SQL statement is started.
 
103
   *
 
104
   * Engines should typically use the doStartStatement()
 
105
   * and doEndStatement() methods to manage transaction state,
 
106
   * since the kernel ALWAYS notifies engines at the start
 
107
   * and end of statement transactions and at the end of the
 
108
   * normal transaction by calling doCommit() or doRollback().
 
109
   */
 
110
  virtual int doStartTransaction(Session *session, start_transaction_option_t options)
 
111
  {
 
112
    (void) session;
 
113
    (void) options;
 
114
    return 0;
 
115
  }
102
116
 
 
117
  /*
 
118
   * Indicates to a storage engine the start of a
 
119
   * new SQL statement.
 
120
   */
 
121
  virtual void doStartStatement(Session *session)
 
122
  {
 
123
    (void) session;
 
124
  }
103
125
};
104
126
 
105
127
} /* namespace plugin */