~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_dspace.cc

  • Committer: Brian Aker
  • Date: 2010-02-14 01:56:51 UTC
  • mto: (1273.16.5 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: brian@gaz-20100214015651-ror9j0xu7dccz0ct
Two fixes for "make dist"

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
   You should have received a copy of the GNU General Public License
14
14
   along with this program; if not, write to the Free Software
15
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
16
16
 
17
17
/* Implements various base dataspace-related functions - allocate, free, clear */
18
18
 
179
179
 
180
180
 
181
181
/**
 
182
  Allocate or reallocate a chunkset in the dataspace
 
183
 
 
184
  Attempts to allocate a new chunkset or change the size of an existing chunkset
 
185
 
 
186
  @param  info            the hosting dataspace
 
187
  @param  chunk_count     the number of chunks that we expect as the result
 
188
  @param  existing_set    non-null value asks function to resize existing chunkset,
 
189
                          return value would point to this set
 
190
 
 
191
  @return  Pointer to the first chunk in the new or updated chunkset, or NULL if unsuccessful
 
192
*/
 
193
 
 
194
static unsigned char *hp_allocate_variable_chunkset(HP_DATASPACE *info,
 
195
                                           uint32_t chunk_count, unsigned char* existing_set)
 
196
{
 
197
  int alloc_count= chunk_count, i;
 
198
  unsigned char *first_chunk= 0, *curr_chunk= 0, *prev_chunk= 0, *last_existing_chunk= 0;
 
199
 
 
200
  assert(alloc_count);
 
201
 
 
202
  if (existing_set)
 
203
  {
 
204
    first_chunk= existing_set;
 
205
 
 
206
    curr_chunk= existing_set;
 
207
    while (curr_chunk && alloc_count)
 
208
    {
 
209
      prev_chunk= curr_chunk;
 
210
      curr_chunk= *((unsigned char**)(curr_chunk + info->offset_link));
 
211
      alloc_count--;
 
212
    }
 
213
 
 
214
    if (!alloc_count)
 
215
    {
 
216
      if (curr_chunk)
 
217
      {
 
218
        /* We came through all chunks and there is more left, let's truncate the list */
 
219
        *((unsigned char**)(prev_chunk + info->offset_link)) = NULL;
 
220
        hp_free_chunks(info, curr_chunk);
 
221
      }
 
222
 
 
223
      return first_chunk;
 
224
    }
 
225
 
 
226
    last_existing_chunk = prev_chunk;
 
227
  }
 
228
 
 
229
  /* We can reach this point only if we're allocating new chunkset or more chunks in existing set */
 
230
 
 
231
  for (i=0; i<alloc_count; i++)
 
232
  {
 
233
      curr_chunk= hp_allocate_one_chunk(info);
 
234
      if (!curr_chunk)
 
235
      {
 
236
        /* no space in the current block */
 
237
 
 
238
        if (last_existing_chunk)
 
239
        {
 
240
          /* Truncate whatever was added at the end of the existing chunkset */
 
241
          prev_chunk= last_existing_chunk;
 
242
          curr_chunk= *((unsigned char**)(prev_chunk + info->offset_link));
 
243
          *((unsigned char**)(prev_chunk + info->offset_link)) = NULL;
 
244
          hp_free_chunks(info, curr_chunk);
 
245
        }
 
246
        else if (first_chunk)
 
247
        {
 
248
          /* free any chunks previously allocated */
 
249
          hp_free_chunks(info, first_chunk);
 
250
        }
 
251
 
 
252
        return NULL;
 
253
      }
 
254
 
 
255
      /* mark as if this chunk is last in the chunkset */
 
256
      *((unsigned char**) (curr_chunk + info->offset_link))= 0;
 
257
 
 
258
      if (prev_chunk)
 
259
      {
 
260
        /* tie them into a linked list */
 
261
        *((unsigned char**) (prev_chunk + info->offset_link))= curr_chunk;
 
262
        curr_chunk[info->offset_status]= CHUNK_STATUS_LINKED;                   /* Record linked from active */
 
263
      }
 
264
      else
 
265
      {
 
266
        curr_chunk[info->offset_status]= CHUNK_STATUS_ACTIVE;                     /* Record active */
 
267
      }
 
268
 
 
269
      if (!first_chunk)
 
270
      {
 
271
        first_chunk= curr_chunk;
 
272
      }
 
273
 
 
274
      prev_chunk= curr_chunk;
 
275
  }
 
276
 
 
277
  return first_chunk;
 
278
}
 
279
 
 
280
 
 
281
/**
182
282
  Allocate a new chunkset in the dataspace
183
283
 
184
284
  Attempts to allocate a new chunkset
189
289
  @return  Pointer to the first chunk in the new or updated chunkset, or NULL if unsuccessful
190
290
*/
191
291
 
192
 
unsigned char *hp_allocate_chunkset(HP_DATASPACE *info, uint32_t )
 
292
unsigned char *hp_allocate_chunkset(HP_DATASPACE *info, uint32_t chunk_count)
193
293
{
194
294
  unsigned char* result;
195
295
 
196
 
  result= hp_allocate_one_chunk(info);
197
 
  if (result)
198
 
  {
199
 
    result[info->offset_status]= CHUNK_STATUS_ACTIVE;
 
296
 
 
297
  if (info->is_variable_size)
 
298
  {
 
299
    result = hp_allocate_variable_chunkset(info, chunk_count, NULL);
 
300
  }
 
301
  else
 
302
  {
 
303
    result= hp_allocate_one_chunk(info);
 
304
    if (result)
 
305
    {
 
306
      result[info->offset_status]= CHUNK_STATUS_ACTIVE;
 
307
    }
 
308
 
 
309
    return(result);
200
310
  }
201
311
 
202
312
  return(result);
204
314
 
205
315
 
206
316
/**
 
317
  Reallocate an existing chunkset in the dataspace
 
318
 
 
319
  Attempts to change the size of an existing chunkset
 
320
 
 
321
  @param  info            the hosting dataspace
 
322
  @param  chunk_count     the number of chunks that we expect as the result
 
323
  @param  pos             pointer to the existing chunkset
 
324
 
 
325
  @return  Error code or zero if successful
 
326
*/
 
327
 
 
328
int hp_reallocate_chunkset(HP_DATASPACE *info, uint32_t chunk_count, unsigned char* pos)
 
329
{
 
330
 
 
331
  if (!info->is_variable_size)
 
332
  {
 
333
    /* Update should never change chunk_count in fixed-size mode */
 
334
    errno=HA_ERR_WRONG_COMMAND;
 
335
    return errno;
 
336
  }
 
337
 
 
338
  /* Reallocate never moves the first chunk */
 
339
  if (!hp_allocate_variable_chunkset(info, chunk_count, pos))
 
340
    return(errno);
 
341
 
 
342
  return(0);
 
343
}
 
344
 
 
345
 
 
346
/**
207
347
  Allocate a single chunk in the dataspace
208
348
 
209
349
  Attempts to allocate a new chunk or reuse one from deleted list
241
381
 
242
382
  info->chunk_count++;
243
383
  curr_chunk= ((unsigned char*) info->block.level_info[0].last_blocks +
244
 
               block_pos * info->block.recbuffer);
 
384
    block_pos * info->block.recbuffer);
245
385
 
246
386
 
247
387
  return curr_chunk;
262
402
{
263
403
  unsigned char* curr_chunk= pos;
264
404
 
265
 
  if (curr_chunk) 
266
 
  {
 
405
  while (curr_chunk) {
267
406
    info->del_chunk_count++;
268
407
    *((unsigned char**) curr_chunk)= info->del_link;
269
408
    info->del_link= curr_chunk;
270
409
 
271
410
    curr_chunk[info->offset_status]= CHUNK_STATUS_DELETED;
 
411
 
 
412
 
 
413
    if (!info->is_variable_size)
 
414
    {
 
415
      break;
 
416
    }
 
417
 
 
418
    /* Delete next chunk in this chunkset */
 
419
    curr_chunk= *((unsigned char**)(curr_chunk + info->offset_link));
272
420
  }
273
421
}