2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// See port_example.h for documentation for the following types/functions.
|
|
|
|
|
2015-02-24 07:05:06 +01:00
|
|
|
#pragma once
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2017-02-06 23:43:55 +01:00
|
|
|
#include <thread>
|
2020-02-20 21:07:53 +01:00
|
|
|
|
2020-03-29 04:05:54 +02:00
|
|
|
#include "rocksdb/options.h"
|
2020-02-20 21:07:53 +01:00
|
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
|
|
|
2015-07-13 21:11:05 +02:00
|
|
|
// size_t printf formatting named in the manner of C99 standard formatting
|
|
|
|
// strings such as PRIu64
|
2015-07-02 01:13:49 +02:00
|
|
|
// in fact, we could use that one
|
|
|
|
#define ROCKSDB_PRIszt "zu"
|
|
|
|
|
2016-01-13 23:51:58 +01:00
|
|
|
#define __declspec(S)
|
|
|
|
|
2015-08-26 01:34:39 +02:00
|
|
|
#define ROCKSDB_NOEXCEPT noexcept
|
2015-08-26 00:17:14 +02:00
|
|
|
|
2022-02-05 02:12:03 +01:00
|
|
|
// thread_local is part of C++11 and later (TODO: clean up this define)
|
|
|
|
#ifndef __thread
|
|
|
|
#define __thread thread_local
|
|
|
|
#endif
|
|
|
|
|
2012-08-27 08:45:35 +02:00
|
|
|
#undef PLATFORM_IS_LITTLE_ENDIAN
|
2012-03-05 19:35:46 +01:00
|
|
|
#if defined(OS_MACOSX)
|
2011-06-29 02:30:50 +02:00
|
|
|
#include <machine/endian.h>
|
2012-08-27 08:45:35 +02:00
|
|
|
#if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER)
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN \
|
|
|
|
(__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
|
|
|
|
#endif
|
2011-06-29 02:30:50 +02:00
|
|
|
#elif defined(OS_SOLARIS)
|
|
|
|
#include <sys/isa_defs.h>
|
|
|
|
#ifdef _LITTLE_ENDIAN
|
2012-08-27 08:45:35 +02:00
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN true
|
2011-06-29 02:30:50 +02:00
|
|
|
#else
|
2012-08-27 08:45:35 +02:00
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN false
|
2011-06-29 02:30:50 +02:00
|
|
|
#endif
|
2017-04-22 05:41:37 +02:00
|
|
|
#include <alloca.h>
|
|
|
|
#elif defined(OS_AIX)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <arpa/nameser_compat.h>
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
|
|
|
|
#include <alloca.h>
|
2015-11-16 21:56:21 +01:00
|
|
|
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
|
|
|
|
defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID)
|
2015-02-27 00:19:17 +01:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
|
2011-06-29 02:30:50 +02:00
|
|
|
#else
|
|
|
|
#include <endian.h>
|
|
|
|
#endif
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <pthread.h>
|
2014-02-08 03:12:30 +01:00
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <stdint.h>
|
2012-06-28 08:41:33 +02:00
|
|
|
#include <string.h>
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-15 01:59:07 +02:00
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
2011-06-29 02:30:50 +02:00
|
|
|
|
2012-08-27 08:45:35 +02:00
|
|
|
#ifndef PLATFORM_IS_LITTLE_ENDIAN
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
|
2011-06-29 02:30:50 +02:00
|
|
|
#endif
|
|
|
|
|
2012-03-05 19:35:46 +01:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
|
2012-08-27 08:45:35 +02:00
|
|
|
defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) ||\
|
2017-04-22 05:41:37 +02:00
|
|
|
defined(OS_ANDROID) || defined(CYGWIN) || defined(OS_AIX)
|
2012-03-05 19:35:46 +01:00
|
|
|
// Use fread/fwrite/fflush on platforms without _unlocked variants
|
2011-06-29 02:30:50 +02:00
|
|
|
#define fread_unlocked fread
|
|
|
|
#define fwrite_unlocked fwrite
|
|
|
|
#define fflush_unlocked fflush
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 19:35:46 +01:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\
|
|
|
|
defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
|
|
|
|
// Use fsync() on platforms without fdatasync()
|
2011-06-29 02:30:50 +02:00
|
|
|
#define fdatasync fsync
|
|
|
|
#endif
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2012-08-27 08:45:35 +02:00
|
|
|
#if defined(OS_ANDROID) && __ANDROID_API__ < 9
|
|
|
|
// fdatasync() was only introduced in API level 9 on Android. Use fsync()
|
2015-12-10 17:54:48 +01:00
|
|
|
// when targeting older platforms.
|
2012-08-27 08:45:35 +02:00
|
|
|
#define fdatasync fsync
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-03-20 20:24:57 +01:00
|
|
|
|
|
|
|
extern const bool kDefaultToAdaptiveMutex;
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
namespace port {
|
|
|
|
|
2015-07-08 01:58:20 +02:00
|
|
|
// For use at db/file_indexer.h kLevelMaxIndex
|
2018-02-09 23:50:09 +01:00
|
|
|
const uint32_t kMaxUint32 = std::numeric_limits<uint32_t>::max();
|
2015-07-11 18:54:33 +02:00
|
|
|
const int kMaxInt32 = std::numeric_limits<int32_t>::max();
|
2019-03-12 21:46:12 +01:00
|
|
|
const int kMinInt32 = std::numeric_limits<int32_t>::min();
|
2015-07-11 18:54:33 +02:00
|
|
|
const uint64_t kMaxUint64 = std::numeric_limits<uint64_t>::max();
|
2016-05-28 01:14:24 +02:00
|
|
|
const int64_t kMaxInt64 = std::numeric_limits<int64_t>::max();
|
2019-03-12 21:46:12 +01:00
|
|
|
const int64_t kMinInt64 = std::numeric_limits<int64_t>::min();
|
2015-09-22 19:34:21 +02:00
|
|
|
const size_t kMaxSizet = std::numeric_limits<size_t>::max();
|
2015-07-08 01:58:20 +02:00
|
|
|
|
2020-02-22 16:59:38 +01:00
|
|
|
constexpr bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN;
|
2012-08-27 08:45:35 +02:00
|
|
|
#undef PLATFORM_IS_LITTLE_ENDIAN
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
class CondVar;
|
|
|
|
|
|
|
|
class Mutex {
|
|
|
|
public:
|
2019-03-20 20:24:57 +01:00
|
|
|
explicit Mutex(bool adaptive = kDefaultToAdaptiveMutex);
|
2019-09-12 03:07:12 +02:00
|
|
|
// No copying
|
|
|
|
Mutex(const Mutex&) = delete;
|
|
|
|
void operator=(const Mutex&) = delete;
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
~Mutex();
|
|
|
|
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
2021-09-25 01:52:30 +02:00
|
|
|
|
|
|
|
bool TryLock();
|
|
|
|
|
2014-04-23 03:38:10 +02:00
|
|
|
// this will assert if the mutex is not locked
|
|
|
|
// it does NOT verify that mutex is held by a calling thread
|
2014-03-26 19:24:52 +01:00
|
|
|
void AssertHeld();
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class CondVar;
|
|
|
|
pthread_mutex_t mu_;
|
2014-03-26 19:24:52 +01:00
|
|
|
#ifndef NDEBUG
|
2020-06-05 00:32:29 +02:00
|
|
|
bool locked_ = false;
|
2014-03-26 19:24:52 +01:00
|
|
|
#endif
|
2011-03-18 23:37:00 +01:00
|
|
|
};
|
|
|
|
|
2012-10-02 06:58:36 +02:00
|
|
|
class RWMutex {
|
|
|
|
public:
|
|
|
|
RWMutex();
|
2019-09-12 03:07:12 +02:00
|
|
|
// No copying allowed
|
|
|
|
RWMutex(const RWMutex&) = delete;
|
|
|
|
void operator=(const RWMutex&) = delete;
|
|
|
|
|
2012-10-02 06:58:36 +02:00
|
|
|
~RWMutex();
|
|
|
|
|
|
|
|
void ReadLock();
|
|
|
|
void WriteLock();
|
2014-06-17 00:41:46 +02:00
|
|
|
void ReadUnlock();
|
|
|
|
void WriteUnlock();
|
2012-10-02 06:58:36 +02:00
|
|
|
void AssertHeld() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
pthread_rwlock_t mu_; // the underlying platform mutex
|
|
|
|
};
|
|
|
|
|
2011-03-18 23:37:00 +01:00
|
|
|
class CondVar {
|
|
|
|
public:
|
|
|
|
explicit CondVar(Mutex* mu);
|
|
|
|
~CondVar();
|
|
|
|
void Wait();
|
2014-07-03 19:22:08 +02:00
|
|
|
// Timed condition wait. Returns true if timeout occurred.
|
|
|
|
bool TimedWait(uint64_t abs_time_us);
|
2011-03-18 23:37:00 +01:00
|
|
|
void Signal();
|
|
|
|
void SignalAll();
|
|
|
|
private:
|
|
|
|
pthread_cond_t cv_;
|
|
|
|
Mutex* mu_;
|
|
|
|
};
|
|
|
|
|
2017-02-06 23:43:55 +01:00
|
|
|
using Thread = std::thread;
|
|
|
|
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-15 01:59:07 +02:00
|
|
|
static inline void AsmVolatilePause() {
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
asm volatile("pause");
|
|
|
|
#elif defined(__aarch64__)
|
2021-03-27 02:12:23 +01:00
|
|
|
asm volatile("yield");
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-15 01:59:07 +02:00
|
|
|
#elif defined(__powerpc64__)
|
|
|
|
asm volatile("or 27,27,27");
|
|
|
|
#endif
|
|
|
|
// it's okay for other platforms to be no-ops
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns -1 if not available on this platform
|
|
|
|
extern int PhysicalCoreID();
|
|
|
|
|
2021-09-07 20:31:12 +02:00
|
|
|
using OnceType = pthread_once_t;
|
2012-08-27 08:45:35 +02:00
|
|
|
#define LEVELDB_ONCE_INIT PTHREAD_ONCE_INIT
|
|
|
|
extern void InitOnce(OnceType* once, void (*initializer)());
|
|
|
|
|
2017-05-09 01:04:19 +02:00
|
|
|
#ifndef CACHE_LINE_SIZE
|
2019-09-17 01:15:18 +02:00
|
|
|
// To test behavior with non-native cache line size, e.g. for
|
|
|
|
// Bloom filters, set TEST_CACHE_LINE_SIZE to the desired test size.
|
|
|
|
// This disables ALIGN_AS to keep it from failing compilation.
|
|
|
|
#ifdef TEST_CACHE_LINE_SIZE
|
|
|
|
#define CACHE_LINE_SIZE TEST_CACHE_LINE_SIZE
|
|
|
|
#define ALIGN_AS(n) /*empty*/
|
|
|
|
#else
|
|
|
|
#if defined(__s390__)
|
2021-12-22 21:56:45 +01:00
|
|
|
#if defined(__GNUC__) && __GNUC__ < 7
|
2021-10-22 19:12:09 +02:00
|
|
|
#define CACHE_LINE_SIZE 64U
|
|
|
|
#else
|
2019-09-17 01:15:18 +02:00
|
|
|
#define CACHE_LINE_SIZE 256U
|
2021-10-22 19:12:09 +02:00
|
|
|
#endif
|
2019-09-17 01:15:18 +02:00
|
|
|
#elif defined(__powerpc__) || defined(__aarch64__)
|
|
|
|
#define CACHE_LINE_SIZE 128U
|
|
|
|
#else
|
|
|
|
#define CACHE_LINE_SIZE 64U
|
|
|
|
#endif
|
|
|
|
#define ALIGN_AS(n) alignas(n)
|
|
|
|
#endif
|
2017-05-09 01:04:19 +02:00
|
|
|
#endif
|
2014-03-28 17:21:20 +01:00
|
|
|
|
2019-09-17 01:15:18 +02:00
|
|
|
static_assert((CACHE_LINE_SIZE & (CACHE_LINE_SIZE - 1)) == 0,
|
|
|
|
"Cache line size must be a power of 2 number of bytes");
|
2017-07-24 19:46:21 +02:00
|
|
|
|
|
|
|
extern void *cacheline_aligned_alloc(size_t size);
|
|
|
|
|
|
|
|
extern void cacheline_aligned_free(void *memblock);
|
|
|
|
|
2014-06-12 19:06:18 +02:00
|
|
|
#define PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
|
|
|
|
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
extern void Crash(const std::string& srcfile, int srcline);
|
2015-09-10 19:49:28 +02:00
|
|
|
|
|
|
|
extern int GetMaxOpenFiles();
|
|
|
|
|
2020-02-22 16:59:38 +01:00
|
|
|
extern const size_t kPageSize;
|
|
|
|
|
2020-03-29 04:05:54 +02:00
|
|
|
using ThreadId = pid_t;
|
|
|
|
|
|
|
|
extern void SetCpuPriority(ThreadId id, CpuPriority priority);
|
|
|
|
|
2021-08-25 02:45:01 +02:00
|
|
|
int64_t GetProcessID();
|
|
|
|
|
Built-in support for generating unique IDs, bug fix (#8708)
Summary:
Env::GenerateUniqueId() works fine on Windows and on POSIX
where /proc/sys/kernel/random/uuid exists. Our other implementation is
flawed and easily produces collision in a new multi-threaded test.
As we rely more heavily on DB session ID uniqueness, this becomes a
serious issue.
This change combines several individually suitable entropy sources
for reliable generation of random unique IDs, with goal of uniqueness
and portability, not cryptographic strength nor maximum speed.
Specifically:
* Moves code for getting UUIDs from the OS to port::GenerateRfcUuid
rather than in Env implementation details. Callers are now told whether
the operation fails or succeeds.
* Adds an internal API GenerateRawUniqueId for generating high-quality
128-bit unique identifiers, by combining entropy from three "tracks":
* Lots of info from default Env like time, process id, and hostname.
* std::random_device
* port::GenerateRfcUuid (when working)
* Built-in implementations of Env::GenerateUniqueId() will now always
produce an RFC 4122 UUID string, either from platform-specific API or
by converting the output of GenerateRawUniqueId.
DB session IDs now use GenerateRawUniqueId while DB IDs (not as
critical) try to use port::GenerateRfcUuid but fall back on
GenerateRawUniqueId with conversion to an RFC 4122 UUID.
GenerateRawUniqueId is declared and defined under env/ rather than util/
or even port/ because of the Env dependency.
Likely follow-up: enhance GenerateRawUniqueId to be faster after the
first call and to guarantee uniqueness within the lifetime of a single
process (imparting the same property onto DB session IDs).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8708
Test Plan:
A new mini-stress test in env_test checks the various public
and internal APIs for uniqueness, including each track of
GenerateRawUniqueId individually. We can't hope to verify anywhere close
to 128 bits of entropy, but it can at least detect flaws as bad as the
old code. Serial execution of the new tests takes about 350 ms on
my machine.
Reviewed By: zhichao-cao, mrambacher
Differential Revision: D30563780
Pulled By: pdillinger
fbshipit-source-id: de4c9ff4b2f581cf784fcedb5f39f16e5185c364
2021-08-31 00:19:39 +02:00
|
|
|
// Uses platform APIs to generate a 36-character RFC-4122 UUID. Returns
|
|
|
|
// true on success or false on failure.
|
|
|
|
bool GenerateRfcUuid(std::string* output);
|
|
|
|
|
2011-06-29 02:30:50 +02:00
|
|
|
} // namespace port
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|