~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/client/concurrent.h

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

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, Inc.
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_PLUGIN_CLIENT_CONCURRENT_H
21
 
#define DRIZZLED_PLUGIN_CLIENT_CONCURRENT_H
22
 
 
23
 
#include <drizzled/plugin/client.h>
24
 
#include <boost/tokenizer.hpp>
25
 
#include <vector>
26
 
#include <queue>
27
 
#include <string>
28
 
 
29
 
namespace drizzled
30
 
{
31
 
namespace plugin
32
 
{
33
 
namespace client
34
 
{
35
 
 
36
 
/**
37
 
 * This class is an empty client implementation for internal used.
38
 
 */
39
 
class Concurrent: public Client
40
 
{
41
 
  typedef std::vector<char> Bytes;
42
 
  typedef std::queue <Bytes> Queue;
43
 
  Queue to_execute;
44
 
  bool is_dead;
45
 
  Bytes packet_buffer;
46
 
 
47
 
public:
48
 
 
49
 
  Concurrent() :
50
 
    is_dead(false)
51
 
  {
52
 
  }
53
 
 
54
 
  virtual int getFileDescriptor(void) { return -1; }
55
 
  virtual bool isConnected(void) { return true; }
56
 
  virtual bool isReading(void) { return false; }
57
 
  virtual bool isWriting(void) { return false; }
58
 
  virtual bool flush(void) { return false; }
59
 
  virtual void close(void) {}
60
 
  virtual bool authenticate(void) { return true; }
61
 
 
62
 
  virtual bool readCommand(char **packet, uint32_t *packet_length)
63
 
  {
64
 
    while(not to_execute.empty())
65
 
    {
66
 
      Queue::value_type next= to_execute.front();
67
 
      packet_buffer.resize(next.size());
68
 
      memcpy(&packet_buffer[0], &next[0], next.size());
69
 
 
70
 
      *packet= &packet_buffer[0];
71
 
 
72
 
      *packet_length= next.size();
73
 
 
74
 
      to_execute.pop();
75
 
 
76
 
      return true;
77
 
    }
78
 
 
79
 
    if (not is_dead)
80
 
    {
81
 
      packet_buffer.resize(1);
82
 
      *packet_length= 1;
83
 
      *packet= &packet_buffer[0];
84
 
      is_dead= true;
85
 
 
86
 
      return true;
87
 
    }
88
 
 
89
 
    *packet_length= 0;
90
 
    return false;
91
 
  }
92
 
 
93
 
  virtual void sendOK(void) {}
94
 
  virtual void sendEOF(void) {}
95
 
  virtual void sendError(const drizzled::error_t, const char*) {}
96
 
  virtual bool sendFields(List<Item>*) { return false; }
97
 
  virtual bool store(Field *) { return false; }
98
 
  virtual bool store(void) { return false; }
99
 
  virtual bool store(int32_t) { return false; }
100
 
  virtual bool store(uint32_t) { return false; }
101
 
  virtual bool store(int64_t) { return false; }
102
 
  virtual bool store(uint64_t) { return false; }
103
 
  virtual bool store(double, uint32_t, String*) { return false; }
104
 
  virtual bool store(const type::Time*) { return false; }
105
 
  virtual bool store(const char*) { return false; }
106
 
  virtual bool store(const char*, size_t) { return false; }
107
 
  virtual bool store(const std::string &) { return false; }
108
 
  virtual bool haveMoreData(void) { return false;}
109
 
  virtual bool haveError(void) { return false; }
110
 
  virtual bool wasAborted(void) { return false; }
111
 
 
112
 
  void pushSQL(const std::string &arg)
113
 
  {
114
 
    Bytes byte;
115
 
    typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
116
 
    Tokenizer tok(arg, boost::escaped_list_separator<char>("\\", ";", "\""));
117
 
 
118
 
    {
119
 
      byte.resize(sizeof("START TRANSACTION")); // +1 for the COM_QUERY, provided by null count from sizeof()
120
 
      byte[0]= COM_QUERY;
121
 
      memcpy(&byte[1], "START TRANSACTION", sizeof("START TRANSACTION") -1);
122
 
      to_execute.push(byte);
123
 
    }
124
 
 
125
 
    for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
126
 
    {
127
 
      byte.resize((*iter).size() +1); // +1 for the COM_QUERY
128
 
      byte[0]= COM_QUERY;
129
 
      memcpy(&byte[1], (*iter).c_str(), (*iter).size());
130
 
      to_execute.push(byte);
131
 
    }
132
 
 
133
 
    {
134
 
      byte.resize(sizeof("COMMIT")); // +1 for the COM_QUERY, provided by null count from sizeof()
135
 
      byte[0]= COM_QUERY;
136
 
      memcpy(&byte[1], "COMMIT", sizeof("COMMIT") -1);
137
 
      to_execute.push(byte);
138
 
    }
139
 
  }
140
 
};
141
 
 
142
 
} /* namespace client */
143
 
} /* namespace plugin */
144
 
} /* namespace drizzled */
145
 
 
146
 
#endif /* DRIZZLED_PLUGIN_CLIENT_CONCURRENT_H */