Zero  0.1.0
restart.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2014, Hewlett-Packard Development Company, LP
3  */
4 
5 /*<std-header orig-src='shore' incl-file-exclusion='RESTART_H'>
6 
7  $Id: restart.h,v 1.27 2010/07/01 00:08:22 nhall Exp $
8 
9  SHORE -- Scalable Heterogeneous Object REpository
10 
11  Copyright (c) 1994-99 Computer Sciences Department, University of
12  Wisconsin -- Madison
13  All Rights Reserved.
14 
15  Permission to use, copy, modify and distribute this software and its
16  documentation is hereby granted, provided that both the copyright
17  notice and this permission notice appear in all copies of the
18  software, derivative works or modified versions, and any portions
19  thereof, and that both notices appear in supporting documentation.
20 
21  THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
22  OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
23  "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
24  FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
25 
26  This software was developed with support by the Advanced Research
27  Project Agency, ARPA order number 018 (formerly 8230), monitored by
28  the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
29  Further funding for this work was provided by DARPA through
30  Rome Research Laboratory Contract No. F30602-97-2-0247.
31 
32  */
33 
34 #ifndef __RESTART_H
35 #define __RESTART_H
36 
37 #include "w_defines.h"
38 #include "w_heap.h"
39 
40 #include "worker_thread.h"
41 #include "sm_base.h"
42 #include "chkpt.h"
43 #include "lock.h" // Lock re-acquisition
44 #include "logarchive_scanner.h"
45 
46 #include <map>
47 
48 // Child thread created by restart_m for concurrent recovery operation
49 // It is to carry out the REDO and UNDO phases while the system is
50 // opened for user transactions
52 public:
53  restart_thread_t(const sm_options& options);
54 
55  virtual void do_work();
56 
57  void log_analysis();
58 
59  void redo_log_pass();
60 
61  void redo_page_pass();
62 
63  void undo_pass();
64 
66  return &chkpt;
67  }
68 
70  return logAnalysisFinished;
71  }
72 
74 
76 
78 
79  // Methods used in nodb mode and with write elision
80  void add_dirty_page(PageID pid, lsn_t lsn);
81 
82  void notify_archived_lsn(lsn_t lsn);
83 
84  void notify_cleaned_lsn(lsn_t lsn);
85 
86  bool isInstant() {
87  return instantRestart;
88  }
89 
90 private:
91  bool log_based;
92 
94 
95  bool no_db_mode;
96 
98 
99  bool take_chkpt;
100 
101  // System state object, updated by log analysis
103 
105 
106  void clear_chkpt();
107 
109 
110  // TEMP: decoupled cleaner
112 
113 public:
114 
120  static void dump_page_lsn_chain(std::ostream& o, const PageID& pid, const lsn_t& max_lsn);
121 
122 private:
123 
124  void _redo_log_with_pid(
125  logrec_t& r,
126  PageID page_updated,
127  bool& redone);
128 };
129 
130 /*
131  * A log-record iterator that encapsulates a log archive scan and a recovery
132  * log scan. It reads from the former until it runs out, after which it reads
133  * from the latter, which is collected by following the per-page chain in the
134  * recovery log.
135  */
136 class SprIterator {
137 public:
138 
139  SprIterator();
140 
141  ~SprIterator();
142 
143  void open(PageID pid, lsn_t firstLSN, lsn_t lastLSN,
144  bool prioritizeArchive = true);
145 
146  bool next(logrec_t*& lr);
147 
148  void apply(fixable_page_h& page);
149 
150 private:
151 
152  char* buffer;
153 
155 
156  std::vector<uint32_t> lr_offsets;
157 
158  std::vector<uint32_t>::const_reverse_iterator lr_iter;
159 
161 
163 
164  unsigned replayed_count;
165 };
166 
167 // CS: documentation code copied from old log_spr.h
253 #endif // __RESTART_H
virtual void do_work()
Definition: restart.cpp:388
char * buffer
Definition: restart.h:152
void notify_cleaned_lsn(lsn_t lsn)
Definition: restart.cpp:671
chkpt_t chkpt
Definition: restart.h:102
Definition: worker_thread.h:12
std::vector< uint32_t > lr_offsets
Definition: restart.h:156
void _redo_log_with_pid(logrec_t &r, PageID page_updated, bool &redone)
Definition: restart.cpp:198
std::vector< uint32_t >::const_reverse_iterator lr_iter
Definition: restart.h:158
void notify_archived_lsn(lsn_t lsn)
Definition: restart.cpp:656
void log_analysis()
Definition: restart.cpp:94
lsn_t get_dirty_page_emlsn(PageID pid) const
Definition: restart.cpp:640
void checkpoint_dirty_pages(chkpt_t &chkpt) const
Definition: restart.cpp:685
size_t buffer_capacity
Definition: restart.h:154
restart_thread_t(const sm_options &options)
Definition: restart.cpp:74
bool take_chkpt
Definition: restart.h:99
PageID get_dirty_page_count() const
Definition: restart.cpp:680
Definition: restart.h:51
Definition: chkpt.h:156
lsn_t clean_lsn
Definition: restart.h:111
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
bool isInstant()
Definition: restart.h:86
void add_dirty_page(PageID pid, lsn_t lsn)
Definition: restart.cpp:650
Definition: logarchive_scanner.h:42
bool log_based
Definition: restart.h:91
void undo_pass()
Definition: restart.cpp:244
static void dump_page_lsn_chain(std::ostream &o, const PageID &pid, const lsn_t &max_lsn)
Pretty-prints the content of log file to the given stream in a way we can easily debug single-page re...
Definition: restart.cpp:448
ArchiveScan archive_scan
Definition: restart.h:160
Represents a transactional log record.
Definition: logrec.h:143
bool instantRestart
Definition: restart.h:93
uint32_t PageID
Definition: basics.h:45
bool write_elision
Definition: restart.h:97
bool hasLogAnalysisFinished()
Definition: restart.h:69
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
Handle class for pages that may be fixed (i.e., paged in by the main buffer manager, zero::buffer_pool::BufferPool)
Definition: fixable_page_h.h:26
unsigned replayed_count
Definition: restart.h:164
srwlock_t chkpt_mutex
Definition: restart.h:108
void clear_chkpt()
Definition: restart.cpp:694
Definition: restart.h:136
chkpt_t * get_chkpt()
Definition: restart.h:65
bool no_db_mode
Definition: restart.h:95
lsn_t last_lsn
Definition: restart.h:162
bool logAnalysisFinished
Definition: restart.h:104
void redo_log_pass()
Definition: restart.cpp:156
Shore read-write lock:: many-reader/one-writer spin lock.
Definition: latches.h:350
void redo_page_pass()
Definition: restart.cpp:224