0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::db: Split db.cc into db_env.cc and db_port.cc.

This commit is contained in:
Jason Volk 2019-01-23 13:51:17 -08:00
parent ecd158f375
commit 2fd50fc9af
5 changed files with 4576 additions and 4577 deletions

View file

@ -124,6 +124,8 @@ libircd_la_SOURCES = \
demangle.cc \
mods.cc \
fmt.cc \
db_port.cc \
db_env.cc \
db.cc \
net.cc \
http.cc \

4572
ircd/db.cc

File diff suppressed because it is too large Load diff

View file

@ -30,11 +30,39 @@
///
//#define RB_DEBUG_DB_PORT
/// Defined to enable our rocksdb::port implementation which connects to our
/// ircd::ctx threading implementation. This is experimental. Note: at this
/// time this MUST be enabled or rocksdb's will be using posix threading and
/// that will not work with our env.
#define IRCD_DB_PORT
#include <rocksdb/version.h>
#include <rocksdb/status.h>
#include <rocksdb/db.h>
#include <rocksdb/cache.h>
#include <rocksdb/comparator.h>
#include <rocksdb/merge_operator.h>
#include <rocksdb/perf_level.h>
#include <rocksdb/perf_context.h>
#include <rocksdb/iostats_context.h>
#include <rocksdb/listener.h>
#include <rocksdb/statistics.h>
#include <rocksdb/convenience.h>
#include <rocksdb/env.h>
#include <rocksdb/slice_transform.h>
#include <rocksdb/utilities/checkpoint.h>
#include <rocksdb/filter_policy.h>
#include <rocksdb/table.h>
#include <rocksdb/sst_file_manager.h>
#include <rocksdb/sst_dump_tool.h>
#include <rocksdb/compaction_filter.h>
#include <ircd/db/database/comparator.h>
#include <ircd/db/database/prefix_transform.h>
#include <ircd/db/database/compaction_filter.h>
#include <ircd/db/database/mergeop.h>
#include <ircd/db/database/events.h>
#include <ircd/db/database/stats.h>
#include <ircd/db/database/logger.h>
#include <ircd/db/database/column.h>
#include <ircd/db/database/txn.h>
#include <ircd/db/database/cache.h>
#include <ircd/db/database/env.h>
#include <ircd/db/database/env/port.h>
namespace ircd::db
{

4199
ircd/db_env.cc Normal file

File diff suppressed because it is too large Load diff

342
ircd/db_port.cc Normal file
View file

@ -0,0 +1,342 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#include "db.h"
//
// Mutex
//
static_assert
(
sizeof(rocksdb::port::Mutex) <= sizeof(pthread_mutex_t) + 1,
"link-time punning of our structure won't work if the structure is larger "
"than the one rocksdb has assumed space for."
);
rocksdb::port::Mutex::Mutex()
noexcept
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "mutex %lu %p CTOR", ctx::id(), this
};
#endif
}
rocksdb::port::Mutex::Mutex(bool adaptive)
noexcept
:Mutex{}
{
}
rocksdb::port::Mutex::~Mutex()
noexcept
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "mutex %lu %p DTOR", ctx::id(), this
};
#endif
}
void
rocksdb::port::Mutex::Lock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "mutex %lu %p LOCK", ctx::id(), this
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
mu.lock();
}
void
rocksdb::port::Mutex::Unlock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "mutex %lu %p UNLOCK", ctx::id(), this
};
#endif
assert_main_thread();
assert(mu.locked());
const ctx::uninterruptible::nothrow ui;
mu.unlock();
}
void
rocksdb::port::Mutex::AssertHeld()
noexcept
{
if(unlikely(!ctx::current))
return;
assert(mu.locked());
}
//
// RWMutex
//
static_assert
(
sizeof(rocksdb::port::RWMutex) <= sizeof(pthread_rwlock_t),
"link-time punning of our structure won't work if the structure is larger "
"than the one rocksdb has assumed space for."
);
rocksdb::port::RWMutex::RWMutex()
noexcept
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "shared_mutex %lu %p CTOR", ctx::id(), this
};
#endif
}
rocksdb::port::RWMutex::~RWMutex()
noexcept
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "shared_mutex %lu %p DTOR", ctx::id(), this
};
#endif
}
void
rocksdb::port::RWMutex::ReadLock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "shared_mutex %lu %p LOCK SHARED", ctx::id(), this
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
mu.lock_shared();
}
void
rocksdb::port::RWMutex::WriteLock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "shared_mutex %lu %p LOCK", ctx::id(), this
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
mu.lock();
}
void
rocksdb::port::RWMutex::ReadUnlock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "shared_mutex %lu %p UNLOCK SHARED", ctx::id(), this
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
mu.unlock_shared();
}
void
rocksdb::port::RWMutex::WriteUnlock()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "shared_mutex %lu %p UNLOCK", ctx::id(), this
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
mu.unlock();
}
//
// CondVar
//
static_assert
(
sizeof(rocksdb::port::CondVar) <= sizeof(pthread_cond_t) + sizeof(void *),
"link-time punning of our structure won't work if the structure is larger "
"than the one rocksdb has assumed space for."
);
rocksdb::port::CondVar::CondVar(Mutex *mu)
noexcept
:mu{mu}
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "cond %lu %p %p CTOR", ctx::id(), this, mu
};
#endif
}
rocksdb::port::CondVar::~CondVar()
noexcept
{
#ifdef RB_DEBUG_DB_PORT_
if(unlikely(!ctx::current))
return;
log::debug
{
db::log, "cond %lu %p %p DTOR", ctx::id(), this, mu
};
#endif
}
void
rocksdb::port::CondVar::Wait()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "cond %lu %p %p WAIT", ctx::id(), this, mu
};
#endif
assert(mu);
assert_main_thread();
mu->AssertHeld();
const ctx::uninterruptible::nothrow ui;
cv.wait(mu->mu);
}
// Returns true if timeout occurred
bool
rocksdb::port::CondVar::TimedWait(uint64_t abs_time_us)
noexcept
{
assert(ctx::current);
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "cond %lu %p %p WAIT_UNTIL %lu", ctx::id(), this, mu, abs_time_us
};
#endif
assert(mu);
assert_main_thread();
mu->AssertHeld();
const std::chrono::microseconds us(abs_time_us);
const std::chrono::steady_clock::time_point tp(us);
const ctx::uninterruptible::nothrow ui;
return cv.wait_until(mu->mu, tp) == std::cv_status::timeout;
}
void
rocksdb::port::CondVar::Signal()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "cond %lu %p %p NOTIFY", ctx::id(), this, mu
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
cv.notify_one();
}
void
rocksdb::port::CondVar::SignalAll()
noexcept
{
if(unlikely(!ctx::current))
return;
#ifdef RB_DEBUG_DB_PORT
log::debug
{
db::log, "cond %lu %p %p BROADCAST", ctx::id(), this, mu
};
#endif
assert_main_thread();
const ctx::uninterruptible::nothrow ui;
cv.notify_all();
}