Zero  0.1.0
log_storage.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2014, Hewlett-Packard Development Company, LP
3  */
4 
5 /* -*- mode:C++; c-basic-offset:4 -*-
6  Shore-MT -- Multi-threaded port of the SHORE storage manager
7 
8  Copyright (c) 2007-2009
9  Data Intensive Applications and Systems Labaratory (DIAS)
10  Ecole Polytechnique Federale de Lausanne
11 
12  All Rights Reserved.
13 
14  Permission to use, copy, modify and distribute this software and
15  its documentation is hereby granted, provided that both the
16  copyright notice and this permission notice appear in all copies of
17  the software, derivative works or modified versions, and any
18  portions thereof, and that both notices appear in supporting
19  documentation.
20 
21  This code is distributed in the hope that it will be useful, but
22  WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
24  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
25  RESULTING FROM THE USE OF THIS SOFTWARE.
26 */
27 
28 /*<std-header orig-src='shore' incl-file-exclusion='SRV_LOG_H'>
29 
30  $Id: log_core.h,v 1.11 2010/09/21 14:26:19 nhall Exp $
31 
32 SHORE -- Scalable Heterogeneous Object REpository
33 
34 Copyright (c) 1994-99 Computer Sciences Department, University of
35  Wisconsin -- Madison
36 All Rights Reserved.
37 
38 Permission to use, copy, modify and distribute this software and its
39 documentation is hereby granted, provided that both the copyright
40 notice and this permission notice appear in all copies of the
41 software, derivative works or modified versions, and any portions
42 thereof, and that both notices appear in supporting documentation.
43 
44 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
45 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
46 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
47 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 
49 This software was developed with support by the Advanced Research
50 Project Agency, ARPA order number 018 (formerly 8230), monitored by
51 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
52 Further funding for this work was provided by DARPA through
53 Rome Research Laboratory Contract No. F30602-97-2-0247.
54 
55 */
56 
57 #ifndef __LOG_STORAGE_H
58 #define __LOG_STORAGE_H
59 
60 #include "w_defines.h"
61 
62 #include "sm_options.h"
63 #include "partition.h"
64 #include <map>
65 #include <vector>
66 #include <memory>
67 #include <mutex>
68 #include <condition_variable>
69 
70 #include "logdef_gen.h"
71 
73 
74 typedef std::map<partition_number_t, shared_ptr<partition_t>> partition_map_t;
75 
76 #define BOOST_FILESYSTEM_NO_DEPRECATED
77 
78 #include <boost/filesystem.hpp>
79 
80 namespace fs = boost::filesystem;
81 
83 
84 class log_storage {
85 
86  // use friend mechanism until better interface is implemented
87  friend class partition_t;
88  friend class partition_recycler_t;
89 
90 public:
91  log_storage(const sm_options&);
92 
93  virtual ~log_storage();
94 
95  shared_ptr<partition_t> get_partition_for_flush(lsn_t start_lsn,
96  long start1, long end1, long start2, long end2);
97 
98  shared_ptr<partition_t> curr_partition() const;
99 
100  shared_ptr<partition_t> get_partition(partition_number_t n) const;
101 
102  void list_partitions(std::vector<partition_number_t>& vec) const;
103 
104  // used by partition_t
106  return _skip_log;
107  }
108 
109  off_t get_partition_size() const {
110  return _partition_size;
111  }
112 
113  size_t get_byte_distance(lsn_t a, lsn_t b) const;
114 
115  string make_log_name(partition_number_t pnum) const;
116 
117  fs::path make_log_path(partition_number_t pnum) const;
118 
119  fs::path make_chkpt_path(lsn_t lsn) const;
120 
121  void add_checkpoint(lsn_t lsn);
122 
123  void wakeup_recycler(bool chkpt_only = false);
124 
125  unsigned delete_old_partitions(bool chkpt_only = false, partition_number_t older_than = 0);
126 
127 private:
128  shared_ptr<partition_t> create_partition(partition_number_t pnum);
129 
130  fs::path _logpath;
131 
133 
135 
136  shared_ptr<partition_t> _curr_partition;
137 
138  vector<lsn_t> _checkpoints;
139 
141 
142  unsigned _max_partitions;
143 
145 
146  // forbid copy
147  log_storage(const log_storage&);
148 
150 
152 
153  // Latch to protect access to partition map
155 
156  unique_ptr<partition_recycler_t> _recycler_thread;
157 
158 public:
159  enum {
161  };
162 
163  static const string log_prefix;
164 
165  static const string log_regex;
166 
167  static const string chkpt_prefix;
168 
169  static const string chkpt_regex;
170 };
171 
172 #endif // __LOG_STORAGE_H
fs::path _logpath
Definition: log_storage.h:130
shared_ptr< partition_t > _curr_partition
Definition: log_storage.h:136
void list_partitions(std::vector< partition_number_t > &vec) const
Definition: log_storage.cpp:473
Definition: log_storage.h:160
fs::path make_chkpt_path(lsn_t lsn) const
Definition: log_storage.cpp:493
static const string chkpt_regex
Definition: log_storage.h:169
partition_map_t _partitions
Definition: log_storage.h:134
unsigned _max_partitions
Definition: log_storage.h:142
Definition: partition.h:74
std::map< partition_number_t, shared_ptr< partition_t > > partition_map_t
Definition: log_storage.h:74
shared_ptr< partition_t > curr_partition() const
Definition: log_storage.cpp:468
off_t get_partition_size() const
Definition: log_storage.h:109
skip_log * get_skip_log()
Definition: log_storage.h:105
skip_log * _skip_log
Definition: log_storage.h:140
mcs_rwlock _partition_map_latch
Definition: log_storage.h:154
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
log_storage & operator=(const log_storage &)
shared_ptr< partition_t > create_partition(partition_number_t pnum)
Definition: log_storage.cpp:331
Definition: partition.h:69
void add_checkpoint(lsn_t lsn)
Definition: log_storage.cpp:395
size_t get_byte_distance(lsn_t a, lsn_t b) const
Definition: log_storage.cpp:548
shared_ptr< partition_t > get_partition_for_flush(lsn_t start_lsn, long start1, long end1, long start2, long end2)
Definition: log_storage.cpp:193
unique_ptr< partition_recycler_t > _recycler_thread
Definition: log_storage.h:156
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
bool chkpt_only
Definition: log_storage.cpp:59
log_storage(const sm_options &)
Definition: log_storage.cpp:74
Definition: log_storage.h:84
fs::path make_log_path(partition_number_t pnum) const
Definition: log_storage.cpp:489
vector< lsn_t > _checkpoints
Definition: log_storage.h:138
string make_log_name(partition_number_t pnum) const
Definition: log_storage.cpp:485
static const string chkpt_prefix
Definition: log_storage.h:167
static const string log_prefix
Definition: log_storage.h:163
off_t _partition_size
Definition: log_storage.h:132
void wakeup_recycler(bool chkpt_only=false)
Definition: log_storage.cpp:383
smlevel_0::partition_number_t partition_number_t
Definition: log_storage.h:72
shared_ptr< partition_t > get_partition(partition_number_t n) const
Definition: log_storage.cpp:218
bool _delete_old_partitions
Definition: log_storage.h:144
Definition: log_storage.cpp:31
unsigned delete_old_partitions(bool chkpt_only=false, partition_number_t older_than=0)
Definition: log_storage.cpp:400
static const string log_regex
Definition: log_storage.h:165
virtual ~log_storage()
Definition: log_storage.cpp:170
void try_delete(partition_number_t)
Definition: log_storage.cpp:497
Definition: logdef_gen.h:52
Shore read-write lock:: many-reader/one-writer spin lock.
Definition: latches.h:350