1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
8
* Jay Pipes <joinfu@sun.com>
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.
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.
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
28
* Defines the implementation of a simple index into a transaction log.
31
#include <drizzled/server_includes.h>
32
#include <drizzled/message/transaction.pb.h>
34
#include "transaction_log_index.h"
39
using namespace drizzled;
41
TransactionLogIndex *transaction_log_index= NULL; /* The singleton transaction log index */
43
TransactionLogIndex::TransactionLogIndex(TransactionLog &in_log) :
52
min_transaction_id(0),
53
max_transaction_id(0),
56
(void) pthread_mutex_init(&index_lock, NULL);
60
TransactionLogIndex::~TransactionLogIndex()
63
transaction_entries.clear();
64
pthread_mutex_destroy(&index_lock);
67
void TransactionLogIndex::open()
72
bool TransactionLogIndex::hasError() const
77
void TransactionLogIndex::clearError()
80
error_message.clear();
83
const std::string &TransactionLogIndex::getErrorMessage() const
88
uint64_t TransactionLogIndex::getMinEndTimestamp() const
90
return min_end_timestamp;
93
uint64_t TransactionLogIndex::getMaxEndTimestamp() const
95
return max_end_timestamp;
98
uint64_t TransactionLogIndex::getMinTransactionId() const
100
return min_transaction_id;
103
uint64_t TransactionLogIndex::getMaxTransactionId() const
105
return max_transaction_id;
108
uint64_t TransactionLogIndex::getNumLogEntries() const
110
return num_log_entries;
113
uint64_t TransactionLogIndex::getNumTransactionEntries() const
115
return num_transaction_entries;
118
TransactionLog::Entries &TransactionLogIndex::getEntries()
123
TransactionLog::TransactionEntries &TransactionLogIndex::getTransactionEntries()
125
return transaction_entries;
128
void TransactionLogIndex::addEntry(const TransactionLogEntry &entry,
129
const message::Transaction &transaction,
132
pthread_mutex_lock(&index_lock);
135
/* First entry...set the minimums */
136
min_transaction_id= transaction.transaction_context().transaction_id();
137
min_end_timestamp= transaction.transaction_context().end_timestamp();
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(),
147
pthread_mutex_unlock(&index_lock);