Zero  0.1.0
log_carray.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2014, Hewlett-Packard Development Company, LP
3  */
4 /*
5  Shore-MT -- Multi-threaded port of the SHORE storage manager
6 
7  Copyright (c) 2010-2014
8  Data Intensive Applications and Systems Labaratory (DIAS)
9  Ecole Polytechnique Federale de Lausanne
10 
11  All Rights Reserved.
12 
13  Permission to use, copy, modify and distribute this software and
14  its documentation is hereby granted, provided that both the
15  copyright notice and this permission notice appear in all copies of
16  the software, derivative works or modified versions, and any
17  portions thereof, and that both notices appear in supporting
18  documentation.
19 
20  This code is distributed in the hope that it will be useful, but
21  WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
23  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
24  RESULTING FROM THE USE OF THIS SOFTWARE.
25 */
26 #ifndef __LOG_CARRAY_H
27 #define __LOG_CARRAY_H
28 
85 #include <cstdint>
86 #include <boost/static_assert.hpp>
87 #include "w_base.h"
88 #include "w_error.h"
89 #include "mcs_lock.h"
90 #include "lsn.h"
91 
102 const bool CARRAY_RELEASE_DELEGATION = false;
103 
116 typedef int64_t carray_status_t;
117 
122 typedef uint32_t carray_slotid_t;
123 
131 struct CArraySlot {
138  mcs_lock::qnode me2; // +16 -> 16
139 
140 // Logging information. Also useful as padding for cacheline (64 byte).
142  lsn_t lsn; // +8 -> 24
144  int64_t old_end; // +8 -> 32
146  int64_t start_pos; // +8 -> 40
148  int64_t pos; // +8 -> 48
150  int64_t new_end; // +8 -> 56
152  int64_t new_base; // +8 -> 64
153 
160  carray_status_t count; // +8 -> 72
161 
167  mcs_lock::qnode me; // +16 -> 88
171  mcs_lock::qnode* pred2; // +8 -> 96
175  w_error_codes error; // +sizeof(w_error_codes)
176 
178  char padding[32 - sizeof(w_error_codes)]; // +32-sizeof(w_error_codes) -> 128
179 
184  CArraySlot volatile* vthis() {
185  return this;
186  }
187 
189  const CArraySlot volatile* vthis() const {
190  return this;
191  }
192 };
193 // Doesn't compile in old Debian.
194 //BOOST_STATIC_ASSERT_MSG((sizeof(CArraySlot) % CACHELINE_SIZE) == 0,
195 // "size of CArraySlot must be aligned to CACHELINE_SIZE for better performance");
196 
204 public:
206  ConsolidationArray(int active_slot_count);
207 
209 
211  enum Constants {
213  ALL_SLOT_COUNT = 256,
214 
216  DEFAULT_ACTIVE_SLOT_COUNT = 3,
217 
221  SLOT_AVAILABLE = 0,
226  SLOT_UNUSED = -1,
231  SLOT_PENDING = -2,
237  SLOT_FINISHED = -4,
238  };
239 
243  static carray_status_t join_carray_status(carray_status_t current_status, int32_t size) {
244  w_assert1(size >= 0);
245  w_assert1(current_status >= 0);
246  const carray_status_t THREAD_INCREMENT = 1L << 32;
247  return current_status + size + THREAD_INCREMENT;
248  }
249 
253  static int32_t extract_carray_log_size(carray_status_t current_status) {
254  w_assert1(current_status >= 0);
255  // bug fixed: lower 32-bit is the size
256  //const carray_status_t THREAD_MASK = 0xFFFF;
257  const carray_status_t THREAD_MASK = 0xFFFFFFFF;
258  return current_status & THREAD_MASK;
259  }
260 
267  CArraySlot* join_slot(int32_t size, carray_status_t& status);
268 
273  void join_expose(CArraySlot* slot);
274 
282  CArraySlot* grab_delegated_expose(CArraySlot* slot);
283 
288  void wait_for_leader(CArraySlot* slot);
289 
296  bool wait_for_expose(CArraySlot* slot);
297 
305  void replace_active_slot(CArraySlot* slot);
306 
307 private:
308  int _indexof(const CArraySlot* slot) const;
309 
315  int32_t _slot_mark;
316 
318  const int32_t _active_slot_count;
319 
321  CArraySlot _all_slots[ALL_SLOT_COUNT];
322 
325 
326  // paddings to make sure mcs_lock are in different cacheline char _padding[CACHELINE_SIZE]; /** @endcond */
332 };
333 
334 inline int ConsolidationArray::_indexof(const CArraySlot* info) const {
335  return info - _all_slots;
336 }
337 
338 #endif // __LOG_CARRAY_H
uint32_t carray_slotid_t
Definition: log_carray.h:122
static carray_status_t join_carray_status(carray_status_t current_status, int32_t size)
Definition: log_carray.h:243
int64_t old_end
Definition: log_carray.h:144
mcs_lock::qnode me2
The secondary queue lock used to delegate buffer-release. Lock head is ConsolidationArray::_expose_lo...
Definition: log_carray.h:138
int32_t _slot_mark
Definition: log_carray.h:315
const bool CARRAY_RELEASE_DELEGATION
Definition: log_carray.h:102
One slot in ConsolidationArray.
Definition: log_carray.h:131
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
const CArraySlot volatile * vthis() const
Definition: log_carray.h:189
static int32_t extract_carray_log_size(carray_status_t current_status)
Definition: log_carray.h:253
w_error_codes
Enum of error codes defined in w_error_xmacro.h.
Definition: w_error.h:43
int64_t carray_status_t
An integer to represents the status of one C-Array slot.
Definition: log_carray.h:116
mcs_lock _expose_lock
Lock to protect threads releasing their log buffer.
Definition: log_carray.h:331
w_error_codes error
Definition: log_carray.h:175
int64_t pos
Definition: log_carray.h:148
int64_t new_end
Definition: log_carray.h:150
mcs_lock::qnode me
Definition: log_carray.h:167
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
carray_status_t count
The current status of this slot.
Definition: log_carray.h:160
int64_t start_pos
Definition: log_carray.h:146
Constants
Definition: log_carray.h:211
int64_t new_base
Definition: log_carray.h:152
int _indexof(const CArraySlot *slot) const
Definition: log_carray.h:334
mcs_lock::qnode * pred2
Definition: log_carray.h:171
CArraySlot ** _active_slots
Definition: log_carray.h:324
lsn_t lsn
Definition: log_carray.h:142
An MCS queuing spinlock.
Definition: mcs_lock.h:61
The implementation class of Consolidation Array.
Definition: log_carray.h:203
Definition: mcs_lock.h:64
CArraySlot volatile * vthis()
Definition: log_carray.h:184
char padding[32 - sizeof(w_error_codes)]
Definition: log_carray.h:178
const int32_t _active_slot_count
Definition: log_carray.h:318