Zero  0.1.0
partition.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2013, Hewlett-Packard Development Company, LP
3  */
4 
5 
6 /* -*- mode:C++; c-basic-offset:4 -*-
7  Shore-MT -- Multi-threaded port of the SHORE storage manager
8 
9  Copyright (c) 2007-2009
10  Data Intensive Applications and Systems Labaratory (DIAS)
11  Ecole Polytechnique Federale de Lausanne
12 
13  All Rights Reserved.
14 
15  Permission to use, copy, modify and distribute this software and
16  its documentation is hereby granted, provided that both the
17  copyright notice and this permission notice appear in all copies of
18  the software, derivative works or modified versions, and any
19  portions thereof, and that both notices appear in supporting
20  documentation.
21 
22  This code is distributed in the hope that it will be useful, but
23  WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
25  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
26  RESULTING FROM THE USE OF THIS SOFTWARE.
27 */
28 
29 /*<std-header orig-src='shore' incl-file-exclusion='SRV_LOG_H'>
30 
31  $Id: partition.h,v 1.6 2010/08/23 14:28:18 nhall Exp $
32 
33 SHORE -- Scalable Heterogeneous Object REpository
34 
35 Copyright (c) 1994-99 Computer Sciences Department, University of
36  Wisconsin -- Madison
37 All Rights Reserved.
38 
39 Permission to use, copy, modify and distribute this software and its
40 documentation is hereby granted, provided that both the copyright
41 notice and this permission notice appear in all copies of the
42 software, derivative works or modified versions, and any portions
43 thereof, and that both notices appear in supporting documentation.
44 
45 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
46 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
47 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
48 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 
50 This software was developed with support by the Advanced Research
51 Project Agency, ARPA order number 018 (formerly 8230), monitored by
52 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
53 Further funding for this work was provided by DARPA through
54 Rome Research Laboratory Contract No. F30602-97-2-0247.
55 
56 */
57 
58 #ifndef __PARTITION_H
59 #define __PARTITION_H
60 
61 #include "w_defines.h"
62 
63 #include "sm_base.h" // for partition_number_t (CS TODO)
64 #include "logrec.h"
65 #include <mutex>
66 
67 class log_storage; // forward
68 
69 class partition_t {
70 public:
72 
73  enum {
74  XFERSIZE = 8192
75  };
76  enum {
78  };
79 
80  partition_t(log_storage*, partition_number_t);
81 
82  virtual ~partition_t() {}
83 
84  partition_number_t num() const {
85  return _num;
86  }
87 
89 
91 
93 
95 
96  rc_t read(logrec_t*& r, lsn_t& ll, lsn_t* prev_lsn = nullptr);
97 
98  void release_read();
99 
100  size_t read_block(void* buf, size_t count, off_t offset);
101 
102  rc_t flush(lsn_t lsn, const char* const buf, long start1, long end1,
103  long start2, long end2);
104 
105  bool is_open_for_read() const {
106  return (_fhdl_rd != invalid_fhdl);
107  }
108 
109  bool is_open_for_append() const {
110  return (_fhdl_app != invalid_fhdl);
111  }
112 
113  size_t get_size(bool must_be_skip = true);
114 
115  void set_size(size_t size) {
116  _size = size;
117  }
118 
119  rc_t prime_buffer(char* buffer, lsn_t lsn, size_t& prime_offset);
120 
121  void destroy();
122 
123 private:
124  partition_number_t _num;
125 
127 
128  long _size;
129 
130  int _fhdl_rd;
131 
133 
134  static int _artificial_flush_delay; // in microseconds
135  char* _readbuf;
136 
138 
140 
141  void fsync_delayed(int fd);
142 
143  rc_t scan_for_size(bool must_be_skip);
144 
145  // Serialize (non-mmap) read calls, which use the same buffer
146  mutex _read_mutex;
147 };
148 
149 #endif // __PARTITION_H
void fsync_delayed(int fd)
Definition: partition.cpp:401
partition_t(log_storage *, partition_number_t)
Definition: partition.cpp:82
rc_t open_for_read()
Definition: partition.cpp:376
Definition: partition.h:74
rc_t close_for_read()
Definition: partition.cpp:449
rc_t prime_buffer(char *buffer, lsn_t lsn, size_t &prime_offset)
Definition: partition.cpp:242
char * _readbuf
Definition: partition.h:135
mutex _read_mutex
Definition: partition.h:146
size_t read_block(void *buf, size_t count, off_t offset)
Definition: partition.cpp:362
partition_number_t _num
Definition: partition.h:124
void release_read()
Definition: partition.cpp:370
Definition: partition.h:69
Represents a transactional log record.
Definition: logrec.h:143
log_storage * _owner
Definition: partition.h:126
static int _artificial_flush_delay
Definition: partition.h:134
rc_t close_for_append()
Definition: partition.cpp:440
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
virtual ~partition_t()
Definition: partition.h:82
Definition: log_storage.h:84
partition_number_t num() const
Definition: partition.h:84
size_t get_size(bool must_be_skip=true)
Definition: partition.cpp:463
long _size
Definition: partition.h:128
Return code for most functions and methods.
Definition: w_rc.h:87
rc_t scan_for_size(bool must_be_skip)
Definition: partition.cpp:472
bool is_open_for_append() const
Definition: partition.h:109
size_t _max_partition_size
Definition: partition.h:137
void set_size(size_t size)
Definition: partition.h:115
rc_t open_for_append()
Definition: partition.cpp:106
Definition: partition.h:77
char * _mmap_buffer
Definition: partition.h:139
void destroy()
Definition: partition.cpp:543
smlevel_0::partition_number_t partition_number_t
Definition: log_storage.h:72
rc_t flush(lsn_t lsn, const char *const buf, long start1, long end1, long start2, long end2)
Definition: partition.cpp:158
bool is_open_for_read() const
Definition: partition.h:105
smlevel_0::partition_number_t partition_number_t
Definition: partition.h:71
int _fhdl_rd
Definition: partition.h:130
rc_t read(logrec_t *&r, lsn_t &ll, lsn_t *prev_lsn=nullptr)
Definition: partition.cpp:286
int _fhdl_app
Definition: partition.h:132