~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/background_worker.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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, Inc.
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 the background worker thread
29
 
 * which maintains summary information about transaction log.
30
 
 *
31
 
 * @details
32
 
 *
33
 
 * The general process that the background worker (collector) thread goes through
34
 
 * is the following:
35
 
 *
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.
40
 
 *
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.
46
 
 *
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.
51
 
 *
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.
57
 
 */
58
 
 
59
 
#include <config.h>
60
 
#include <drizzled/gettext.h>
61
 
#include <drizzled/errmsg_print.h>
62
 
#include <drizzled/definitions.h>
63
 
#include <errno.h>
64
 
 
65
 
#include "transaction_log.h"
66
 
#include "background_worker.h"
67
 
 
68
 
bool initTransactionLogBackgroundWorker()
69
 
{
70
 
  pthread_t thread;
71
 
  int error;
72
 
  if ((error= pthread_create(&thread, NULL, collectTransactionLogStats, 0)))
73
 
  {
74
 
    drizzled::sql_perror("Unable to create background worker thread.");
75
 
    return true;
76
 
  }
77
 
  return false;
78
 
}
79
 
 
80
 
void *collectTransactionLogStats(void *)
81
 
{
82
 
  /* Check to see if there is an index file on disk */
83
 
 
84
 
  /* No index file. Create one on disk and in memory. */
85
 
 
86
 
  /* Read in the index file. */
87
 
 
88
 
  /* Enter collection loop */
89
 
 
90
 
  /* Ask for the transaction log's latest written timestamp */
91
 
 
92
 
  /* Does our index have a smaller timestamp? */
93
 
 
94
 
  pthread_exit(0);
95
 
 
96
 
  return NULL;
97
 
}