mirror of https://gitee.com/bigwinds/arangodb
minor enhancements for the cache
This commit is contained in:
parent
52ba50e281
commit
ac6c5a79d7
|
@ -279,8 +279,7 @@ std::shared_ptr<Table> Cache::table() { return _table; }
|
||||||
|
|
||||||
void Cache::beginShutdown() {
|
void Cache::beginShutdown() {
|
||||||
_state.lock();
|
_state.lock();
|
||||||
if (!_state.isSet(State::Flag::shutdown) &&
|
if (!_state.isSet(State::Flag::shutdown, State::Flag::shuttingDown)) {
|
||||||
!_state.isSet(State::Flag::shuttingDown)) {
|
|
||||||
_state.toggleFlag(State::Flag::shuttingDown);
|
_state.toggleFlag(State::Flag::shuttingDown);
|
||||||
}
|
}
|
||||||
_state.unlock();
|
_state.unlock();
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
using namespace arangodb::cache;
|
using namespace arangodb::cache;
|
||||||
|
|
||||||
|
Finding::Finding() : _value(nullptr) {}
|
||||||
|
|
||||||
Finding::Finding(CachedValue* v) : _value(v) {
|
Finding::Finding(CachedValue* v) : _value(v) {
|
||||||
if (_value != nullptr) {
|
if (_value != nullptr) {
|
||||||
_value->lease();
|
_value->lease();
|
||||||
|
@ -88,6 +90,14 @@ void Finding::release() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Finding::set(CachedValue* v) {
|
||||||
|
TRI_ASSERT(_value == nullptr);
|
||||||
|
_value = v;
|
||||||
|
if (v != nullptr) {
|
||||||
|
_value->lease();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Finding::reset(CachedValue* v) {
|
void Finding::reset(CachedValue* v) {
|
||||||
if (_value != nullptr) {
|
if (_value != nullptr) {
|
||||||
_value->release();
|
_value->release();
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace cache {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
class Finding {
|
class Finding {
|
||||||
public:
|
public:
|
||||||
|
Finding();
|
||||||
explicit Finding(CachedValue* v);
|
explicit Finding(CachedValue* v);
|
||||||
Finding(Finding const& other);
|
Finding(Finding const& other);
|
||||||
Finding(Finding&& other);
|
Finding(Finding&& other);
|
||||||
|
@ -53,6 +54,12 @@ class Finding {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
void reset(CachedValue* v);
|
void reset(CachedValue* v);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief Sets the underlying CachedValue pointer. Assumes that the Finding
|
||||||
|
/// is currently empty
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
void set(CachedValue* v);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Specifies whether the value was found. If not, value is nullptr.
|
/// @brief Specifies whether the value was found. If not, value is nullptr.
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -64,7 +64,7 @@ class FrequencyBuffer {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Initialize with the given capacity.
|
/// @brief Initialize with the given capacity.
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
FrequencyBuffer(uint64_t capacity)
|
explicit FrequencyBuffer(uint64_t capacity)
|
||||||
: _current(0),
|
: _current(0),
|
||||||
_capacity(0),
|
_capacity(0),
|
||||||
_mask(0),
|
_mask(0),
|
||||||
|
@ -91,7 +91,7 @@ class FrequencyBuffer {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Reports the memory usage in bytes.
|
/// @brief Reports the memory usage in bytes.
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
uint64_t memoryUsage() {
|
uint64_t memoryUsage() const {
|
||||||
return ((_capacity * sizeof(T)) + sizeof(FrequencyBuffer<T>) +
|
return ((_capacity * sizeof(T)) + sizeof(FrequencyBuffer<T>) +
|
||||||
sizeof(std::vector<T>));
|
sizeof(std::vector<T>));
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,14 +447,14 @@ void Manager::reportAccess(std::shared_ptr<Cache> cache) {
|
||||||
void Manager::reportHitStat(Stat stat) {
|
void Manager::reportHitStat(Stat stat) {
|
||||||
switch (stat) {
|
switch (stat) {
|
||||||
case Stat::findHit: {
|
case Stat::findHit: {
|
||||||
_findHits++;
|
++_findHits;
|
||||||
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
||||||
_findStats->insertRecord(static_cast<uint8_t>(Stat::findHit));
|
_findStats->insertRecord(static_cast<uint8_t>(Stat::findHit));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Stat::findMiss: {
|
case Stat::findMiss: {
|
||||||
_findMisses++;
|
++_findMisses;
|
||||||
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
||||||
_findStats->insertRecord(static_cast<uint8_t>(Stat::findMiss));
|
_findStats->insertRecord(static_cast<uint8_t>(Stat::findMiss));
|
||||||
}
|
}
|
||||||
|
@ -466,14 +466,12 @@ void Manager::reportHitStat(Stat stat) {
|
||||||
|
|
||||||
bool Manager::isOperational() const {
|
bool Manager::isOperational() const {
|
||||||
TRI_ASSERT(_state.isLocked());
|
TRI_ASSERT(_state.isLocked());
|
||||||
return (!_state.isSet(State::Flag::shutdown) &&
|
return !_state.isSet(State::Flag::shutdown, State::Flag::shuttingDown);
|
||||||
!_state.isSet(State::Flag::shuttingDown));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::globalProcessRunning() const {
|
bool Manager::globalProcessRunning() const {
|
||||||
TRI_ASSERT(_state.isLocked());
|
TRI_ASSERT(_state.isLocked());
|
||||||
return (_state.isSet(State::Flag::rebalancing) ||
|
return _state.isSet(State::Flag::rebalancing, State::Flag::resizing);
|
||||||
_state.isSet(State::Flag::resizing));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::io_service* Manager::ioService() { return _ioService; }
|
boost::asio::io_service* Manager::ioService() { return _ioService; }
|
||||||
|
|
|
@ -74,6 +74,11 @@ bool State::isSet(State::Flag flag) const {
|
||||||
return ((_state.load() & static_cast<uint32_t>(flag)) > 0);
|
return ((_state.load() & static_cast<uint32_t>(flag)) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool State::isSet(State::Flag flag1, State::Flag flag2) const {
|
||||||
|
TRI_ASSERT(isLocked());
|
||||||
|
return ((_state.load() & (static_cast<uint32_t>(flag1) | static_cast<uint32_t>(flag2))) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
void State::toggleFlag(State::Flag flag) {
|
void State::toggleFlag(State::Flag flag) {
|
||||||
TRI_ASSERT(isLocked());
|
TRI_ASSERT(isLocked());
|
||||||
_state ^= static_cast<uint32_t>(flag);
|
_state ^= static_cast<uint32_t>(flag);
|
||||||
|
|
|
@ -107,6 +107,7 @@ struct State {
|
||||||
/// @brief Checks whether the given flag is set. Requires state to be locked.
|
/// @brief Checks whether the given flag is set. Requires state to be locked.
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
bool isSet(State::Flag flag) const;
|
bool isSet(State::Flag flag) const;
|
||||||
|
bool isSet(State::Flag flag1, State::Flag flag2) const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Toggles the given flag. Requires state to be locked.
|
/// @brief Toggles the given flag. Requires state to be locked.
|
||||||
|
|
|
@ -39,13 +39,11 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace arangodb::cache;
|
using namespace arangodb::cache;
|
||||||
|
|
||||||
Finding TransactionalCache::find(void const* key, uint32_t keySize) {
|
Finding TransactionalCache::find(void const* key, uint32_t keySize) {
|
||||||
TRI_ASSERT(key != nullptr);
|
TRI_ASSERT(key != nullptr);
|
||||||
Finding result(nullptr);
|
Finding result;
|
||||||
uint32_t hash = hashKey(key, keySize);
|
uint32_t hash = hashKey(key, keySize);
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -54,7 +52,7 @@ Finding TransactionalCache::find(void const* key, uint32_t keySize) {
|
||||||
std::tie(ok, bucket, source) = getBucket(hash, Cache::triesFast);
|
std::tie(ok, bucket, source) = getBucket(hash, Cache::triesFast);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
result.reset(bucket->find(hash, key, keySize));
|
result.set(bucket->find(hash, key, keySize));
|
||||||
recordStat(result.found() ? Stat::findHit : Stat::findMiss);
|
recordStat(result.found() ? Stat::findHit : Stat::findMiss);
|
||||||
bucket->unlock();
|
bucket->unlock();
|
||||||
endOperation();
|
endOperation();
|
||||||
|
|
Loading…
Reference in New Issue