Go to the documentation of this file.
18 # include <jemalloc/jemalloc.h>
26 #ifndef _ISOC11_SOURCE
27 #if __cplusplus >= 201703L
28 using std::aligned_alloc;
29 #else // __cplusplus < 201703L
30 #error "need a working aligned_alloc(3)"
32 #endif // _ISOC11_SOURCE
34 #endif // USE_JEMALLOC
54 #include <absl/base/macros.h>
55 #include <absl/memory/memory.h>
56 #include <absl/strings/string_view.h>
71 using std::static_pointer_cast;
72 using std::dynamic_pointer_cast;
73 using std::const_pointer_cast;
74 #if __cplusplus >= 201703L
78 template<
class T,
class U>
79 static inline std::shared_ptr<T>
81 return std::shared_ptr<T>(p,
reinterpret_cast<T*
>(p.get()));
93 typedef std::unique_ptr<void, AlignedAllocImpl::FreeMem>
117 template<
size_t alignment,
class T>
125 return (T*) aligned_alloc(alignment, n *
sizeof(T));
155 std::vector<char, AlignedAllocImpl::aligned_allocator<8, char>>;
171 #if (defined(TDB_IN_TEST) && !defined(NDEBUG))
174 #define ASSERT(...) \
176 bool __cond = (CAR(__VA_ARGS__)); \
178 LOG(::taco::kFatal, \
180 STRINGIFY(CAR(__VA_ARGS__)) \
182 IF_NONEMPTY_COMMA(CADR(__VA_ARGS__), ": ") \
187 #elif (!defined(TDB_IN_TEST) && !defined(NDEBUG))
190 #define ASSERT(...) \
192 bool __cond = (CAR(__VA_ARGS__)); \
194 LOG(::taco::kFatal, "%s:" STRINGIFY(__LINE__) \
196 STRINGIFY(CAR(__VA_ARGS__)) \
198 IF_NONEMPTY(CADR(__VA_ARGS__), ": "), \
199 ::taco::StripSourcePath(__FILE__) \
200 IF_NONEMPTY_COMMA(CADR(__VA_ARGS__), ) \
205 #else // assert disabled
230 static_assert(
FieldOffsetBits <= 15,
"page size cannot be larger than 2^15");
269 #define FIELDOFFSET_FORMAT "%hd"
270 #define FIELDID_FORMAT "%hd"
271 #define OID_FORMAT "%u"
272 #define FILEID_FORMAT "%u"
273 #define PAGENUMBER_FORMAT "0x%08X"
274 #define SLOTID_FORMAT "%hu"
275 #define BUFFERID_FORMAT "%lu"
282 constexpr
Oid MaxOid = std::numeric_limits<Oid>::max() - 1;
321 return (((uint64_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64_t) ((ALIGNVAL) - 1)));
324 #define SHORTALIGN(LEN) TYPEALIGN(2, (LEN))
325 #define INTALIGN(LEN) TYPEALIGN(4, (LEN))
326 #define LONGALIGN(LEN) TYPEALIGN(8, (LEN))
327 #define DOUBLEALIGN(LEN) TYPEALIGN(8, (LEN))
328 #define MAXALIGN(LEN) TYPEALIGN(8, (LEN))
329 #define CACHELINEALIGN(LEN) TYPEALIGN(CACHELINE_SIZE, (LEN))
330 #define MAXALIGN_OF 8
335 return (((uint64_t) (LEN)) & ~((uint64_t) ((ALIGNVAL) - 1)));
338 #define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(2, (LEN))
339 #define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(4, (LEN))
340 #define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(8, (LEN))
341 #define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(8, (LEN))
342 #define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(8, (LEN))
343 #define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(CACHELINE_SIZE, (LEN))
345 template<
class T,
class U>
348 if ((left > 0 && (T) right > std::numeric_limits<T>::max() - left) ||
349 (left < 0 && (T) right < left - std::numeric_limits<T>::min())) {
362 #define RETURN_IF(...) \
364 if ((CAR(__VA_ARGS__))) { \
365 return CDR(__VA_ARGS__); \
376 #define FLEXIBLE_ARRAY_MEMBER -1
381 #ifdef ABSL_USES_STD_STRING_VIEW
382 #define cast_as_string(t) t
394 typename std::enable_if<!std::is_same<typename std::decay<T>::type,
395 absl::string_view>::value,
398 return std::forward<T>(t);
402 typename std::enable_if<std::is_same<typename std::decay<T>::type,
403 absl::string_view>::value,
406 return std::string(t.data(), t.size());
409 #endif // ABSL_USES_STD_STRING_VIEW
int16_t FieldOffset
Definition: tdb_base.h:212
std::true_type is_always_equal
Definition: tdb_base.h:143
constexpr SlotId INVALID_SID
The invalid slot ID.
Definition: tdb_base.h:255
constexpr FieldId InvalidFieldId
Definition: tdb_base.h:226
static std::shared_ptr< T > reinterpret_pointer_cast(const std::shared_ptr< U > &p)
Definition: tdb_base.h:80
uint8_t OpType
The operator type, see expr/optypes.h.
Definition: tdb_base.h:288
uint8_t IdxType
The index type, see index/idxtyps.h.
Definition: tdb_base.h:285
Definition: tdb_base.h:118
constexpr FieldId MaxNumRegularFieldId
Definition: tdb_base.h:227
constexpr const size_t PAGE_SIZE
Definition: tdb_base.h:159
constexpr PageNumber INVALID_PID
The invalid page number.
Definition: tdb_base.h:236
unique_malloced_ptr unique_aligned_alloc(size_t alignment, size_t size)
Wraps an aligned_alloced'd memory space in a std::unique_ptr.
Definition: tdb_base.h:101
constexpr FieldOffset MaxFieldOffset
Definition: tdb_base.h:231
constexpr SlotId MinSlotId
The minimum valid slot ID.
Definition: tdb_base.h:260
constexpr int logn_ceil(uint64_t x)
Returns $\lceil log_2(x) \rceil$ for x > 0, or 0 for x = 0.
Definition: misc.h:148
constexpr PageNumber RESERVED_PID
An invalid page number reserved for file manager internal use.
Definition: tdb_base.h:243
Definition: tdb_base.h:86
uint16_t SlotId
Definition: tdb_base.h:223
uint64_t BufferId
Definition: tdb_base.h:215
#define CONFIG_PAGE_SIZE
Definition: config.h:11
constexpr T TYPEALIGN(uint64_t ALIGNVAL, T LEN)
These alignment macros are derived from PostgreSQL.
Definition: tdb_base.h:320
int16_t FieldId
Definition: tdb_base.h:213
std::unique_ptr< void, AlignedAllocImpl::FreeMem > unique_malloced_ptr
Definition: tdb_base.h:94
constexpr bool operator!=(const aligned_allocator &)
Definition: tdb_base.h:139
constexpr T TYPEALIGN_DOWN(uint64_t ALIGNVAL, T LEN)
Definition: tdb_base.h:334
static T * allocate(size_t n)
Definition: tdb_base.h:124
aligned_allocator< alignment, U > other
Definition: tdb_base.h:147
constexpr SlotId MaxSlotId
The maximum valid slot ID.
Definition: tdb_base.h:265
constexpr const size_t CACHELINE_SIZE
Definition: tdb_base.h:158
static void deallocate(T *p, size_t)
Definition: tdb_base.h:129
bool AddWithCheck(T &left, U right)
Definition: tdb_base.h:347
constexpr bool operator==(const aligned_allocator &)
Definition: tdb_base.h:134
std::vector< char, AlignedAllocImpl::aligned_allocator< 8, char > > maxaligned_char_buf
Definition: tdb_base.h:155
constexpr int PageNumberBits
Definition: tdb_base.h:228
uint32_t FileId
The file ID.
Definition: tdb_base.h:222
constexpr Oid MaxOid
The largest valid Oid.
Definition: tdb_base.h:282
constexpr BufferId INVALID_BUFID
Definition: tdb_base.h:267
unique_malloced_ptr wrap_malloc(void *ptr)
Definition: tdb_base.h:106
#define L1_CACHELINE_SIZE
Definition: config.h:8
uint8_t AggType
The aggregation type, see catalog/aggtyp.h.
Definition: tdb_base.h:296
uint32_t Oid
Definition: tdb_base.h:211
Definition: tdb_base.h:85
constexpr Oid InvalidOid
Definition: tdb_base.h:225
ptrdiff_t difference_type
Definition: tdb_base.h:121
void operator()(void *x)
Definition: tdb_base.h:87
std::enable_if<!std::is_same< typename std::decay< T >::type, absl::string_view >::value, T && >::type cast_as_string(T &&t)
This is intended for casting anything that represents a string in C++ to an std::string.
Definition: tdb_base.h:397
constexpr int FieldOffsetBits
Definition: tdb_base.h:229
T value_type
Definition: tdb_base.h:119
size_t size_type
Definition: tdb_base.h:120
unique_malloced_ptr unique_malloc(size_t size)
Definition: tdb_base.h:111
constexpr PageNumber MaxPageNumber
The maximum valid page number.
Definition: tdb_base.h:248
Definition: tdb_base.h:146
uint32_t PageNumber
Definition: tdb_base.h:214