libfoedus-core
FOEDUS Core Library
array_log_types.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
19 
20 #include <glog/logging.h>
21 
22 #include <algorithm>
23 #include <memory>
24 #include <ostream>
25 #include <string>
26 #include <utility>
27 
28 #include "foedus/assert_nd.hpp"
29 #include "foedus/engine.hpp"
33 #include "foedus/thread/thread.hpp"
34 
35 namespace foedus {
36 namespace storage {
37 namespace array {
38 
40  reinterpret_cast<CreateLogType*>(this)->apply_storage(engine, storage_id);
41 }
42 
44  reinterpret_cast<CreateLogType*>(this)->assert_valid();
46  ASSERT_ND(header_.get_type() == log::get_log_code<ArrayCreateLogType>());
47 }
48 std::ostream& operator<<(std::ostream& o, const ArrayCreateLogType& v) {
49  o << "<ArrayCreateLog>" << v.metadata_ << "</ArrayCreateLog>";
50  return o;
51 }
52 
53 std::ostream& operator<<(std::ostream& o, const ArrayOverwriteLogType& v) {
54  o << "<ArrayOverwriteLog>"
55  << "<offset_>" << v.offset_ << "</offset_>"
56  << "<payload_offset_>" << v.payload_offset_ << "</payload_offset_>"
57  << "<payload_count_>" << v.payload_count_ << "</payload_count_>";
58  // show first few bytes
59  o << "<data_>";
60  for (uint16_t i = 0; i < std::min<uint16_t>(8, v.payload_count_); ++i) {
61  o << i << ":" << static_cast<int>(v.payload_[i]) << " ";
62  }
63  o << "...</data_>";
64  o << "</ArrayOverwriteLog>";
65  return o;
66 }
67 
68 // just to shutup pesky compiler
69 template <typename T>
70 inline T as(const void *address) {
71  const T* casted = reinterpret_cast<const T*>(address);
72  return *casted;
73 }
74 
75 std::ostream& operator<<(std::ostream& o, const ArrayIncrementLogType& v) {
76  o << "<ArrayIncrementLog>"
77  << "<offset_>" << v.offset_ << "</offset_>"
78  << "<payload_offset_>" << v.payload_offset_ << "</payload_offset_>"
79  << "<type_>";
80  switch (v.get_value_type()) {
81  // 32 bit data types
82  case kI8:
83  o << "int8_t</type><addendum_>" << static_cast<int16_t>(as<int8_t>(v.addendum_));
84  break;
85  case kI16:
86  o << "int16_t</type><addendum_>" << as<int16_t>(v.addendum_);
87  break;
88  case kI32:
89  o << "int32_t</type><addendum_>" << as<int32_t>(v.addendum_);
90  break;
91  case kBool:
92  case kU8:
93  o << "uint8_t</type><addendum_>" << static_cast<uint16_t>(as<uint8_t>(v.addendum_));
94  break;
95  case kU16:
96  o << "uint16_t</type><addendum_>" << as<uint16_t>(v.addendum_);
97  break;
98  case kU32:
99  o << "uint32_t</type><addendum_>" << as<uint32_t>(v.addendum_);
100  break;
101  case kFloat:
102  o << "float</type><addendum_>" << as<float>(v.addendum_);
103  break;
104 
105  // 64 bit data types
106  case kI64:
107  o << "int64_t</type><addendum_>" << as<int64_t>(v.addendum_ + 4);
108  break;
109  case kU64:
110  o << "uint64_t</type><addendum_>" << as<uint64_t>(v.addendum_ + 4);
111  break;
112  case kDouble:
113  o << "double</type><addendum_>" << as<double>(v.addendum_ + 4);
114  break;
115  default:
116  o << "UNKNOWN(" << v.get_value_type() << ")</type><addendum_>";
117  ASSERT_ND(false);
118  break;
119  }
120  o << "</addendum_>";
121  o << "</ArrayIncrementLog>";
122  return o;
123 }
124 
125 } // namespace array
126 } // namespace storage
127 } // namespace foedus
Declares all log types used in this storage type.
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
void apply_storage(Engine *engine, StorageId storage_id)
Log type of array-storage's overwrite operation.
Declares common log types for all (or at least multiple) storage types.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Log type of array-storage's increment operation.
std::ostream & operator<<(std::ostream &o, const ArrayCreateLogType &v)
uint16_t log_length_
Byte size of this log entry including this header itself and everything.
Log type of CREATE ARRAY STORAGE operation.
LogCode get_type() const __attribute__((always_inline))
Convenience method to cast into LogCode.
ValueType get_value_type() const __attribute__((always_inline))
Base type for CREATE STORAGE operation.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
T as(const void *address)