~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/transaction_log_index.cc

  • Committer: Jay Pipes
  • Date: 2009-11-16 22:00:02 UTC
  • mto: (1234.1.1 push) (1237.2.10 push)
  • mto: This revision was merged to the branch mainline in revision 1229.
  • Revision ID: jpipes@serialcoder-20091116220002-rdsha64utt41i8w8
Adds INFORMATION_SCHEMA views for the transaction log:

TRANSACTION_LOG
TRANSACTION_LOG_ENTRIES
TRANSACTION_LOG_TRANSACTIONS

Adds a new user-defined function:

PRINT_TRANSACTION_MESSAGE(filename, offset)

Adds tests for all of the above

Implementation notes:

An indexer now runs when transaction messages are applied
to the transaction log.  It creates a simple index of the
transaction log entries.  This index is used when the
information schema views' fillTable() method is called.

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) 2009 Sun Microsystems
 
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 implementation of a simple index into a transaction log.
 
29
 */
 
30
 
 
31
#include <drizzled/server_includes.h>
 
32
#include <drizzled/message/transaction.pb.h>
 
33
 
 
34
#include "transaction_log_index.h"
 
35
 
 
36
#include <pthread.h>
 
37
 
 
38
using namespace std;
 
39
using namespace drizzled;
 
40
 
 
41
TransactionLogIndex *transaction_log_index= NULL; /* The singleton transaction log index */
 
42
 
 
43
TransactionLogIndex::TransactionLogIndex(TransactionLog &in_log) :
 
44
  log(in_log),
 
45
  log_file(-1),
 
46
  index_file(-1),
 
47
  index_file_path(),
 
48
  has_error(false),
 
49
  error_message(),
 
50
  min_end_timestamp(0),
 
51
  max_end_timestamp(0),
 
52
  min_transaction_id(0),
 
53
  max_transaction_id(0),
 
54
  num_log_entries(0)
 
55
{
 
56
  (void) pthread_mutex_init(&index_lock, NULL);
 
57
  open();
 
58
}
 
59
 
 
60
TransactionLogIndex::~TransactionLogIndex()
 
61
{
 
62
  entries.clear();
 
63
  transaction_entries.clear();
 
64
  pthread_mutex_destroy(&index_lock);
 
65
}
 
66
 
 
67
void TransactionLogIndex::open()
 
68
{
 
69
 
 
70
}
 
71
 
 
72
bool TransactionLogIndex::hasError() const
 
73
{
 
74
  return has_error;
 
75
}
 
76
 
 
77
void TransactionLogIndex::clearError()
 
78
{
 
79
  has_error= false;
 
80
  error_message.clear();
 
81
}
 
82
 
 
83
const std::string &TransactionLogIndex::getErrorMessage() const
 
84
{
 
85
  return error_message;
 
86
}
 
87
 
 
88
uint64_t TransactionLogIndex::getMinEndTimestamp() const
 
89
{
 
90
  return min_end_timestamp;
 
91
}
 
92
 
 
93
uint64_t TransactionLogIndex::getMaxEndTimestamp() const
 
94
{
 
95
  return max_end_timestamp;
 
96
}
 
97
 
 
98
uint64_t TransactionLogIndex::getMinTransactionId() const
 
99
{
 
100
  return min_transaction_id;
 
101
}
 
102
 
 
103
uint64_t TransactionLogIndex::getMaxTransactionId() const
 
104
{
 
105
  return max_transaction_id;
 
106
}
 
107
 
 
108
uint64_t TransactionLogIndex::getNumLogEntries() const
 
109
{
 
110
  return num_log_entries;
 
111
}
 
112
 
 
113
uint64_t TransactionLogIndex::getNumTransactionEntries() const
 
114
{
 
115
  return num_transaction_entries;
 
116
}
 
117
 
 
118
TransactionLog::Entries &TransactionLogIndex::getEntries()
 
119
{
 
120
  return entries;
 
121
}
 
122
 
 
123
TransactionLog::TransactionEntries &TransactionLogIndex::getTransactionEntries()
 
124
{
 
125
  return transaction_entries;
 
126
}
 
127
 
 
128
void TransactionLogIndex::addEntry(const TransactionLogEntry &entry,
 
129
                                   const message::Transaction &transaction,
 
130
                                   uint32_t checksum)
 
131
{
 
132
  pthread_mutex_lock(&index_lock);
 
133
  if (entries.empty())
 
134
  {
 
135
    /* First entry...set the minimums */
 
136
    min_transaction_id= transaction.transaction_context().transaction_id();
 
137
    min_end_timestamp= transaction.transaction_context().end_timestamp();
 
138
  }
 
139
  num_log_entries++;
 
140
  num_transaction_entries++;
 
141
  max_transaction_id= transaction.transaction_context().transaction_id();
 
142
  max_end_timestamp= transaction.transaction_context().end_timestamp();
 
143
  entries.push_back(entry);
 
144
  transaction_entries.push_back(TransactionLogTransactionEntry(entry.getOffset(),
 
145
                                                               transaction,
 
146
                                                               checksum));
 
147
  pthread_mutex_unlock(&index_lock);
 
148
}