~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/filesystem_engine/filesystem_engine.h

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
merge lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (C) 2010 Zimin
3
 
 
4
 
  This program is free software; you can redistribute it and/or
5
 
  modify it under the terms of the GNU General Public License
6
 
  as published by the Free Software Foundation; either version 2
7
 
  of the License, or (at your option) any later version.
8
 
 
9
 
  This program is distributed in the hope that it will be useful,
10
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
  GNU General Public License for more details.
13
 
 
14
 
  You should have received a copy of the GNU General Public License
15
 
  along with this program; if not, write to the Free Software
16
 
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
 
*/
18
 
 
19
 
#ifndef PLUGIN_FILESYSTEM_ENGINE_FILESYSTEM_ENGINE_H
20
 
#define PLUGIN_FILESYSTEM_ENGINE_FILESYSTEM_ENGINE_H
21
 
 
22
 
#include <drizzled/cursor.h>
23
 
#include <drizzled/thr_lock.h>
24
 
 
25
 
#include <boost/scoped_ptr.hpp>
26
 
 
27
 
#include <sys/types.h>
28
 
#include <sys/stat.h>
29
 
#include <fstream>
30
 
 
31
 
#include "transparent_file.h"
32
 
#include "formatinfo.h"
33
 
#include "filesystemlock.h"
34
 
 
35
 
class FilesystemTableShare
36
 
{
37
 
  FilesystemTableShare();
38
 
  FilesystemTableShare(const FilesystemTableShare &);
39
 
  FilesystemTableShare& operator=(const FilesystemTableShare &);
40
 
public:
41
 
  explicit FilesystemTableShare(const std::string name);
42
 
  ~FilesystemTableShare();
43
 
 
44
 
  uint32_t use_count;
45
 
  const std::string table_name;
46
 
  bool update_file_opened;
47
 
  bool needs_reopen;
48
 
  pthread_mutex_t mutex;
49
 
  FormatInfo format;
50
 
  std::vector< std::map<std::string, std::string> > vm;
51
 
  FilesystemLock filesystem_lock;
52
 
};
53
 
 
54
 
class FilesystemCursor : public drizzled::Cursor
55
 
{
56
 
  FilesystemTableShare *share;       /* Shared lock info */
57
 
  boost::scoped_ptr<TransparentFile> file_buff;
58
 
  int file_desc;
59
 
  std::string update_file_name;
60
 
  int update_file_desc;
61
 
  size_t tag_depth;
62
 
  off_t current_position;
63
 
  off_t next_position;
64
 
  bool thread_locked;
65
 
  uint32_t sql_command_type; /* Type of SQL command to process */
66
 
  /* each slot means an interval in a file which will be deleted later */
67
 
  std::vector< std::pair<off_t, off_t> > slots;
68
 
 
69
 
public:
70
 
  FilesystemCursor(drizzled::plugin::StorageEngine &engine, drizzled::Table &table_arg);
71
 
  ~FilesystemCursor()
72
 
  {
73
 
  }
74
 
 
75
 
  /** @brief
76
 
    The name that will be used for display purposes.
77
 
   */
78
 
  const char *table_type(void) const { return "FILESYSTEM"; }
79
 
 
80
 
  /*
81
 
     Called in test_quick_select to determine if indexes should be used.
82
 
   */
83
 
  virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; }
84
 
 
85
 
  /* The next method will never be called */
86
 
  virtual bool fast_key_read() { return 1;}
87
 
  drizzled::ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; }
88
 
 
89
 
  int doOpen(const drizzled::identifier::Table &, int, uint32_t);
90
 
  int close(void);
91
 
  int doStartTableScan(bool scan=1);
92
 
  int rnd_next(unsigned char *);
93
 
  int rnd_pos(unsigned char * , unsigned char *);
94
 
  void position(const unsigned char *);
95
 
  int info(uint);
96
 
  int doEndTableScan();
97
 
  int doInsertRecord(unsigned char * buf);
98
 
  int doUpdateRecord(const unsigned char *, unsigned char *);
99
 
  int doDeleteRecord(const unsigned char *);
100
 
 
101
 
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
102
 
                                  uint64_t nb_desired_values,
103
 
                                  uint64_t *first_value,
104
 
                                  uint64_t *nb_reserved_values) { (void)offset; (void)increment; (void)nb_desired_values; (void)first_value; (void)nb_reserved_values; }
105
 
  FilesystemTableShare *get_share(const char *table_name);
106
 
  void free_share();
107
 
  void critical_section_enter();
108
 
  void critical_section_exit();
109
 
private:
110
 
  void recordToString(std::string& output);
111
 
  void addSlot();
112
 
  int openUpdateFile();
113
 
  int find_current_row(unsigned char *buf);
114
 
};
115
 
 
116
 
#endif /* PLUGIN_FILESYSTEM_ENGINE_FILESYSTEM_ENGINE_H */