~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/hp_clear.cc

Fix pidfile argument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2002, 2004, 2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
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 */
15
 
 
16
 
/*
17
 
  remove all records from database
18
 
  Identical as hp_create() and hp_open() but used HP_SHARE* instead of name and
19
 
  database remains open.
20
 
*/
21
 
 
22
 
#include "heap_priv.h"
23
 
 
24
 
using namespace drizzled;
25
 
 
26
 
static void hp_clear_keys(HP_SHARE *info);
27
 
 
28
 
void heap_clear(HP_INFO *info)
29
 
{
30
 
  hp_clear(info->getShare());
31
 
}
32
 
 
33
 
void hp_clear(HP_SHARE *info)
34
 
{
35
 
  hp_clear_dataspace(&info->recordspace);
36
 
  hp_clear_keys(info);
37
 
  info->records= 0;
38
 
  info->blength=1;
39
 
  info->changed=0;
40
 
  return;
41
 
}
42
 
 
43
 
/*
44
 
  Clear all keys.
45
 
 
46
 
  SYNOPSIS
47
 
    hp_clear_keys()
48
 
    info      A pointer to the heap storage engine HP_SHARE struct.
49
 
 
50
 
  DESCRIPTION
51
 
    Delete all trees of all indexes and leave them empty.
52
 
 
53
 
  RETURN
54
 
    void
55
 
*/
56
 
 
57
 
static void hp_clear_keys(HP_SHARE *info)
58
 
{
59
 
  for (uint32_t key=0 ; key < info->keys ; key++)
60
 
  {
61
 
    HP_KEYDEF *keyinfo = info->keydef + key;
62
 
    {
63
 
      HP_BLOCK *block= &keyinfo->block;
64
 
      if (block->levels)
65
 
        hp_free_level(block,block->levels,block->root,(unsigned char*) 0);
66
 
      block->levels=0;
67
 
      block->last_allocated=0;
68
 
      keyinfo->hash_buckets= 0;
69
 
    }
70
 
  }
71
 
  info->index_length=0;
72
 
}
73
 
 
74
 
 
75
 
/*
76
 
  Disable all indexes.
77
 
 
78
 
  SYNOPSIS
79
 
    heap_disable_indexes()
80
 
    info      A pointer to the heap storage engine HP_INFO struct.
81
 
 
82
 
  DESCRIPTION
83
 
    Disable and clear (remove contents of) all indexes.
84
 
 
85
 
  RETURN
86
 
    0  ok
87
 
*/
88
 
 
89
 
int heap_disable_indexes(HP_INFO *info)
90
 
{
91
 
  HP_SHARE *share= info->getShare();
92
 
 
93
 
  if (share->keys)
94
 
  {
95
 
    hp_clear_keys(share);
96
 
    share->currently_disabled_keys= share->keys;
97
 
    share->keys= 0;
98
 
  }
99
 
  return 0;
100
 
}
101
 
 
102
 
 
103
 
/*
104
 
  Enable all indexes
105
 
 
106
 
  SYNOPSIS
107
 
    heap_enable_indexes()
108
 
    info      A pointer to the heap storage engine HP_INFO struct.
109
 
 
110
 
  DESCRIPTION
111
 
    Enable all indexes. The indexes might have been disabled
112
 
    by heap_disable_index() before.
113
 
    The function works only if both data and indexes are empty,
114
 
    since the heap storage engine cannot repair the indexes.
115
 
    To be sure, call handler::delete_all_rows() before.
116
 
 
117
 
  RETURN
118
 
    0  ok
119
 
    HA_ERR_CRASHED data or index is non-empty.
120
 
*/
121
 
 
122
 
int heap_enable_indexes(HP_INFO *info)
123
 
{
124
 
  int error= 0;
125
 
  HP_SHARE *share= info->getShare();
126
 
 
127
 
  if (share->recordspace.total_data_length || share->index_length)
128
 
    error= HA_ERR_CRASHED;
129
 
  else
130
 
    if (share->currently_disabled_keys)
131
 
    {
132
 
      share->keys= share->currently_disabled_keys;
133
 
      share->currently_disabled_keys= 0;
134
 
    }
135
 
  return error;
136
 
}
137
 
 
138
 
 
139
 
/*
140
 
  Test if indexes are disabled.
141
 
 
142
 
  SYNOPSIS
143
 
    heap_indexes_are_disabled()
144
 
    info      A pointer to the heap storage engine HP_INFO struct.
145
 
 
146
 
  DESCRIPTION
147
 
    Test if indexes are disabled.
148
 
 
149
 
  RETURN
150
 
    0  indexes are not disabled
151
 
    1  all indexes are disabled
152
 
   [2  non-unique indexes are disabled - NOT YET IMPLEMENTED]
153
 
*/
154
 
 
155
 
int heap_indexes_are_disabled(HP_INFO *info)
156
 
{
157
 
  HP_SHARE *share= info->getShare();
158
 
 
159
 
  return (! share->keys && share->currently_disabled_keys);
160
 
}