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, Inc.
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 the background worker thread
29
* which maintains summary information about transaction log.
33
* The general process that the background worker (collector) thread goes through
36
* a) At thread start, we first check to see if there is an index
37
* file for the transaction log that has previously been written
38
* by the collector thread. If there is, we read in the index and
39
* use that information to construct our in-memory index.
41
* b) If no index is around, we read the transaction log and create
42
* an in-memory index. This in-memory index is sync'd to disk
43
* every once in a while. We don't care about crashes and the state
44
* of the index written to disk, since the transaction log file is
45
* the main stable state of the transaction log, not the index.
47
* c) Periodically, the collector thread queries the transaction
48
* log's current offset. If this offset is greater than the last
49
* offset in the collector's index, it reads a segment of the transaction
50
* log, building the index for the transactions it finds.
52
* d) When querying the INFORMATION_SCHEMA, or the replication system
53
* needs an exact read of the index, the collector thread is signalled
54
* via a pthread_cond_broadcast() call and the collector thread reads
55
* the transaction log up until the last log offset of the transaction log,
56
* building the index as it reads the log file.
60
#include <drizzled/gettext.h>
61
#include <drizzled/errmsg_print.h>
62
#include <drizzled/definitions.h>
65
#include "transaction_log.h"
66
#include "background_worker.h"
68
bool initTransactionLogBackgroundWorker()
72
if ((error= pthread_create(&thread, NULL, collectTransactionLogStats, 0)))
74
drizzled::sql_perror("Unable to create background worker thread.");
80
void *collectTransactionLogStats(void *)
82
/* Check to see if there is an index file on disk */
84
/* No index file. Create one on disk and in memory. */
86
/* Read in the index file. */
88
/* Enter collection loop */
90
/* Ask for the transaction log's latest written timestamp */
92
/* Does our index have a smaller timestamp? */