~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/write_buffer.h

Adds a vector of write buffers to the transaction log applier
object.  This eliminates the calls to malloc() for writing
most transaction log entries (the only calls to malloc() will
be when an existing write buffer is not large enough).  

There is a configuration setting now for the number of write
buffers to create on startup.  The slot algorithm is a simple
modulo on the session ID.

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) 2010 Jay Pipes <jaypipes@gmail.com>
 
5
 *
 
6
 *  Authors:
 
7
 *
 
8
 *  Jay Pipes <jaypipes@gmail.com>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
23
 */
 
24
 
 
25
/**
 
26
 * @file
 
27
 *
 
28
 * Defines a simple structure for maintaining a write buffer.
 
29
 */
 
30
 
 
31
#ifndef PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H
 
32
#define PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H
 
33
 
 
34
#include <stdint.h>
 
35
#include <string>
 
36
#include <pthread.h>
 
37
 
 
38
class WriteBuffer
 
39
{
 
40
public:
 
41
  static const size_t DEFAULT_WRITE_BUFFER_SIZE= 1024; /* Many GPB messages are < 1 KB... */
 
42
  /**
 
43
   * Constructor.
 
44
   */
 
45
  WriteBuffer();
 
46
  ~WriteBuffer();
 
47
  /**
 
48
   * Locks the log write buffer
 
49
   */
 
50
  void lock()
 
51
  {
 
52
    pthread_mutex_lock(&latch);
 
53
  }
 
54
  /**
 
55
   * Unlocks the log's write buffer
 
56
   */
 
57
  void unlock()
 
58
  {
 
59
    pthread_mutex_unlock(&latch);
 
60
  }
 
61
  /**
 
62
   * Resizes the internal raw byte buffer
 
63
   *
 
64
   * @param[in] New size to allocate
 
65
   */
 
66
  void resize(size_t new_size);
 
67
  /**
 
68
   * Returns the pointer to the raw bytes.
 
69
   */
 
70
  uint8_t *getRawBytes()
 
71
  {
 
72
    return buffer;
 
73
  }
 
74
  /**
 
75
   * Returns the size of the write buffer
 
76
   */
 
77
  size_t getCapacity()
 
78
  {
 
79
    return buffer_size;
 
80
  }
 
81
private:
 
82
  /* Prohibit these */
 
83
  WriteBuffer(const WriteBuffer&);
 
84
  WriteBuffer &operator=(const WriteBuffer&);
 
85
 
 
86
  uint8_t *buffer; ///< Raw memory buffer managed by the log
 
87
  size_t buffer_size; ///< Current size of write buffer
 
88
  pthread_mutex_t latch; ///< Lock around the synchronized parts of the log (the write buffer)
 
89
};
 
90
 
 
91
#endif /* PLUGIN_TRANSACTION_LOG_UNDO_LOG_H */