~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/mf_cache.cc

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:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Open a temporary file and cache it with io_cache. Delete it on close */
17
17
 
18
 
#include <config.h>
 
18
#include "config.h"
19
19
 
20
 
#include <drizzled/internal/my_sys.h>
21
 
#include <drizzled/internal/m_string.h>
22
 
#include <drizzled/internal/my_static.h>
23
 
#include <drizzled/internal/iocache.h>
24
 
#include <drizzled/error.h>
 
20
#include "drizzled/internal/my_sys.h"
 
21
#include "drizzled/internal/m_string.h"
 
22
#include "drizzled/internal/my_static.h"
 
23
#include "drizzled/my_error.h"
 
24
#include "drizzled/internal/iocache.h"
25
25
 
26
26
namespace drizzled
27
27
{
28
28
namespace internal
29
29
{
30
30
 
31
 
/*
32
 
** Open tempfile cached by st_io_cache
33
 
** Should be used when no seeks are done (only reinit_io_buff)
34
 
** Return false if cache is inited ok
35
 
** The actual file is created when the st_io_cache buffer gets filled
36
 
** If dir is not given, use TMPDIR.
37
 
*/
 
31
        /*
 
32
        ** Open tempfile cached by IO_CACHE
 
33
        ** Should be used when no seeks are done (only reinit_io_buff)
 
34
        ** Return false if cache is inited ok
 
35
        ** The actual file is created when the IO_CACHE buffer gets filled
 
36
        ** If dir is not given, use TMPDIR.
 
37
        */
38
38
 
39
 
bool st_io_cache::open_cached_file(const char *dir_arg, const char *prefix_arg,
40
 
                      size_t cache_size_arg, myf cache_myflags)
 
39
bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
 
40
                         size_t cache_size, myf cache_myflags)
41
41
{
42
 
  dir=   dir_arg ? strdup(dir_arg) : (char*) 0;
43
 
  prefix= (prefix_arg ? strdup(prefix_arg) : (char*) 0);
44
 
 
45
 
  if ((dir == NULL) || (prefix == NULL))
 
42
  cache->dir=    dir ? strdup(dir) : (char*) 0;
 
43
  cache->prefix= (prefix ? strdup(prefix) :
 
44
                 (char*) 0);
 
45
  if ((cache->dir == NULL) || (cache->prefix == NULL))
46
46
    return true;
47
 
 
48
 
  file_name= 0;
49
 
  buffer= 0;                            /* Mark that not open */
50
 
  if (not init_io_cache(-1, cache_size_arg,WRITE_CACHE,0L,0, MYF(cache_myflags | MY_NABP)))
 
47
  cache->file_name=0;
 
48
  cache->buffer=0;                              /* Mark that not open */
 
49
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
 
50
                     MYF(cache_myflags | MY_NABP)))
51
51
  {
52
52
    return false;
53
53
  }
54
 
  free(dir);
55
 
  free(prefix);
56
 
 
 
54
  free(cache->dir);
 
55
  free(cache->prefix);
57
56
  return true;
58
57
}
59
58
 
60
 
/* Create the temporary file */
 
59
        /* Create the temporary file */
61
60
 
62
 
bool st_io_cache::real_open_cached_file()
 
61
bool real_open_cached_file(IO_CACHE *cache)
63
62
{
64
63
  char name_buff[FN_REFLEN];
65
 
 
66
 
  if ((file= create_temp_file(name_buff, dir, prefix, MYF(MY_WME))) >= 0)
 
64
  int error=1;
 
65
  if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix, MYF(MY_WME))) >= 0)
67
66
  {
 
67
    error=0;
68
68
    my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
69
 
    return false;
70
69
  }
71
 
 
72
 
  return true;
 
70
  return(error);
73
71
}
74
72
 
75
73
 
76
 
void st_io_cache::close_cached_file()
 
74
void close_cached_file(IO_CACHE *cache)
77
75
{
78
 
  if (my_b_inited(this))
 
76
  if (my_b_inited(cache))
79
77
  {
80
 
    int _file= file;
81
 
    file= -1;                           /* Don't flush data */
82
 
    (void) end_io_cache();
83
 
    if (_file >= 0)
 
78
    int file=cache->file;
 
79
    cache->file= -1;                            /* Don't flush data */
 
80
    (void) end_io_cache(cache);
 
81
    if (file >= 0)
84
82
    {
85
 
      (void) my_close(_file, MYF(0));
 
83
      (void) my_close(file,MYF(0));
86
84
#ifdef CANT_DELETE_OPEN_FILES
87
 
      if (file_name)
 
85
      if (cache->file_name)
88
86
      {
89
 
        (void) my_delete(file_name, MYF(MY_WME | ME_NOINPUT));
90
 
        free(file_name);
 
87
        (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
 
88
        free(cache->file_name);
91
89
      }
92
90
#endif
93
91
    }
94
 
    free(dir);
95
 
    free(prefix);
 
92
    free(cache->dir);
 
93
    free(cache->prefix);
96
94
  }
 
95
  return;
97
96
}
98
97
 
99
98
} /* namespace internal */