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() {
|
||||
_state.lock();
|
||||
if (!_state.isSet(State::Flag::shutdown) &&
|
||||
!_state.isSet(State::Flag::shuttingDown)) {
|
||||
if (!_state.isSet(State::Flag::shutdown, State::Flag::shuttingDown)) {
|
||||
_state.toggleFlag(State::Flag::shuttingDown);
|
||||
}
|
||||
_state.unlock();
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
using namespace arangodb::cache;
|
||||
|
||||
Finding::Finding() : _value(nullptr) {}
|
||||
|
||||
Finding::Finding(CachedValue* v) : _value(v) {
|
||||
if (_value != nullptr) {
|
||||
_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) {
|
||||
if (_value != nullptr) {
|
||||
_value->release();
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace cache {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
class Finding {
|
||||
public:
|
||||
Finding();
|
||||
explicit Finding(CachedValue* v);
|
||||
Finding(Finding const& other);
|
||||
Finding(Finding&& other);
|
||||
|
@ -53,6 +54,12 @@ class Finding {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
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.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -64,7 +64,7 @@ class FrequencyBuffer {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Initialize with the given capacity.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
FrequencyBuffer(uint64_t capacity)
|
||||
explicit FrequencyBuffer(uint64_t capacity)
|
||||
: _current(0),
|
||||
_capacity(0),
|
||||
_mask(0),
|
||||
|
@ -91,7 +91,7 @@ class FrequencyBuffer {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Reports the memory usage in bytes.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
uint64_t memoryUsage() {
|
||||
uint64_t memoryUsage() const {
|
||||
return ((_capacity * sizeof(T)) + sizeof(FrequencyBuffer<T>) +
|
||||
sizeof(std::vector<T>));
|
||||
}
|
||||
|
|
|
@ -447,14 +447,14 @@ void Manager::reportAccess(std::shared_ptr<Cache> cache) {
|
|||
void Manager::reportHitStat(Stat stat) {
|
||||
switch (stat) {
|
||||
case Stat::findHit: {
|
||||
_findHits++;
|
||||
++_findHits;
|
||||
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
||||
_findStats->insertRecord(static_cast<uint8_t>(Stat::findHit));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Stat::findMiss: {
|
||||
_findMisses++;
|
||||
++_findMisses;
|
||||
if (_enableWindowedStats && _findStats.get() != nullptr) {
|
||||
_findStats->insertRecord(static_cast<uint8_t>(Stat::findMiss));
|
||||
}
|
||||
|
@ -466,14 +466,12 @@ void Manager::reportHitStat(Stat stat) {
|
|||
|
||||
bool Manager::isOperational() const {
|
||||
TRI_ASSERT(_state.isLocked());
|
||||
return (!_state.isSet(State::Flag::shutdown) &&
|
||||
!_state.isSet(State::Flag::shuttingDown));
|
||||
return !_state.isSet(State::Flag::shutdown, State::Flag::shuttingDown);
|
||||
}
|
||||
|
||||
bool Manager::globalProcessRunning() const {
|
||||
TRI_ASSERT(_state.isLocked());
|
||||
return (_state.isSet(State::Flag::rebalancing) ||
|
||||
_state.isSet(State::Flag::resizing));
|
||||
return _state.isSet(State::Flag::rebalancing, State::Flag::resizing);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
TRI_ASSERT(isLocked());
|
||||
_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.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
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.
|
||||
|
|
|
@ -39,13 +39,11 @@
|
|||
#include <chrono>
|
||||
#include <list>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace arangodb::cache;
|
||||
|
||||
Finding TransactionalCache::find(void const* key, uint32_t keySize) {
|
||||
TRI_ASSERT(key != nullptr);
|
||||
Finding result(nullptr);
|
||||
Finding result;
|
||||
uint32_t hash = hashKey(key, keySize);
|
||||
|
||||
bool ok;
|
||||
|
@ -54,7 +52,7 @@ Finding TransactionalCache::find(void const* key, uint32_t keySize) {
|
|||
std::tie(ok, bucket, source) = getBucket(hash, Cache::triesFast);
|
||||
|
||||
if (ok) {
|
||||
result.reset(bucket->find(hash, key, keySize));
|
||||
result.set(bucket->find(hash, key, keySize));
|
||||
recordStat(result.found() ? Stat::findHit : Stat::findMiss);
|
||||
bucket->unlock();
|
||||
endOperation();
|
||||
|
|
Loading…
Reference in New Issue