~drizzle-trunk/drizzle/development

1143.3.4 by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log:
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1143.3.4 by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log:
5
 *
6
 *  Authors:
7
 *
8
 *  Jay Pipes <joinfu@sun.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 the API of a simple index for the transaction log
29
 */
30
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
31
#pragma once
1143.3.4 by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log:
32
33
#include "transaction_log.h"
34
#include "transaction_log_entry.h"
35
36
#include <pthread.h>
37
#include <string>
38
39
namespace drizzled { namespace message {class Transaction;}}
40
41
class TransactionLogIndex
42
{
43
public:
44
  explicit TransactionLogIndex(TransactionLog &in_log);
45
  ~TransactionLogIndex();
46
  /**
47
   * Returns the minimum end timestamp of a transaction
48
   * in the transaction log.
49
   */
50
  uint64_t getMinEndTimestamp() const;
51
  /**
52
   * Returns the maximum end timestamp of a transaction
53
   * in the transaction log.
54
   */
55
  uint64_t getMaxEndTimestamp() const;
56
  /**
57
   * Returns the minimum transaction ID of a transaction
58
   * in the transaction log.
59
   */
60
  uint64_t getMinTransactionId() const;
61
  /**
62
   * Returns the maximum transaction ID of a transaction
63
   * in the transaction log.
64
   */
65
  uint64_t getMaxTransactionId() const;
66
  /**
67
   * Returns the total number of entries in the transaction log
68
   */
69
  uint64_t getNumLogEntries() const;
70
  /**
71
   * Returns the total number of transaction entries in the transaction log
72
   */
73
  uint64_t getNumTransactionEntries() const;
74
  /**
75
   * Returns whether the index encountered an
76
   * error on its last action.
77
   */
78
  bool hasError() const;
79
  /**
80
   * Returns the current error message
81
   */
82
  const std::string &getErrorMessage() const;
83
  /**
84
   * Returns a reference to the index's collection
85
   * of log entry objects
86
   */
87
  TransactionLog::Entries &getEntries();
88
  /**
89
   * Returns a reference to the index's collection
90
   * of transaction entry objects
91
   */
92
  TransactionLog::TransactionEntries &getTransactionEntries();
93
  /**
94
   * Adds a new entry to the index of type Transaction message.
95
   *
96
   * @param[in] The transaction log entry
97
   * @param[in] The transaction message
98
   * @param[in] The checksum for the transaction message bytes
99
   */
100
  void addEntry(const TransactionLogEntry &entry,
101
                const drizzled::message::Transaction &transaction,
102
                uint32_t checksum);
1273.1.33 by Jay Pipes
Adds concurrency tests for transaction log and its data dictionary table. Adds ability to see size of the in-memory index of the transaction log in bytes to the transaction_log data dictionary table.
103
  /**
104
   * Clears all data out of the transaction log
105
   * index.
106
   *
107
   * @note
108
   *
109
   * No locks are taken here.  Currently only used in debugging.
110
   */
111
  void clear();
112
113
  /* Some methods returning size in bytes of the index and its parts */
114
  size_t getTransactionEntriesSizeInBytes();
115
  size_t getEntriesSizeInBytes();
116
  size_t getSizeInBytes();
1143.3.4 by Jay Pipes
Adds INFORMATION_SCHEMA views for the transaction log:
117
private:
118
  /**
119
   * Helper function to open/create the index from 
120
   * the transaction log.
121
   */
122
  void open();
123
  /**
124
   * Clears the internal error state
125
   */
126
  void clearError();
127
128
  TransactionLog &log; ///< The transaction log instance
129
  int index_file; ///< File descriptor for the transaction log on-disk index file
130
  const std::string index_file_path; ///< Filename of the on-disk transaction log index
131
  bool has_error; ///< Index is in error mode?
132
  std::string error_message; ///< Current error message
133
134
  uint64_t min_end_timestamp; ///< Minimum end timestamp in log
135
  uint64_t max_end_timestamp; ///< Maximim end timestamp in log
136
  uint64_t min_transaction_id; ///< Minimum transaction ID in log
137
  uint64_t max_transaction_id; ///< Maximum transaction ID in log
138
139
  TransactionLog::Entries entries; ///< Collection of information about the entries in the log
140
  TransactionLog::TransactionEntries transaction_entries; ///<
141
142
  pthread_mutex_t index_lock; ///< The global index lock
143
};
144