mirror of https://gitee.com/bigwinds/arangodb
Cache workaround to pass upgrade test.
This commit is contained in:
parent
4ca2cf52d3
commit
ae84e8ac84
|
@ -163,6 +163,15 @@ bool Cache::isResizing() {
|
||||||
return resizing;
|
return resizing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Cache::isShutdown() {
|
||||||
|
bool shutdown = false;
|
||||||
|
_state.lock();
|
||||||
|
shutdown = !isOperational();
|
||||||
|
_state.unlock();
|
||||||
|
|
||||||
|
return shutdown;
|
||||||
|
}
|
||||||
|
|
||||||
void Cache::destroy(std::shared_ptr<Cache> cache) {
|
void Cache::destroy(std::shared_ptr<Cache> cache) {
|
||||||
if (cache.get() != nullptr) {
|
if (cache.get() != nullptr) {
|
||||||
cache->shutdown();
|
cache->shutdown();
|
||||||
|
|
|
@ -112,6 +112,11 @@ class Cache : public std::enable_shared_from_this<Cache> {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
bool isResizing();
|
bool isResizing();
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief Check whether the cache has begin the process of shutting down.
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool isShutdown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static constexpr int64_t triesFast = 50;
|
static constexpr int64_t triesFast = 50;
|
||||||
static constexpr int64_t triesSlow = 10000;
|
static constexpr int64_t triesSlow = 10000;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "Cache/State.h"
|
#include "Cache/State.h"
|
||||||
#include "Cache/Table.h"
|
#include "Cache/Table.h"
|
||||||
#include "Cache/TransactionalBucket.h"
|
#include "Cache/TransactionalBucket.h"
|
||||||
|
#include "Logger/Logger.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
|
@ -73,6 +73,14 @@ void RocksDBIndex::createCache() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RocksDBIndex::disableCache() {
|
||||||
|
TRI_ASSERT(_cacheManager != nullptr);
|
||||||
|
TRI_ASSERT(_useCache);
|
||||||
|
TRI_ASSERT(_cache.get() != nullptr);
|
||||||
|
_useCache = false;
|
||||||
|
_cacheManager->destroyCache(_cache);
|
||||||
|
_cache.reset();
|
||||||
|
}
|
||||||
int RocksDBIndex::drop() {
|
int RocksDBIndex::drop() {
|
||||||
// Try to drop the cache as well.
|
// Try to drop the cache as well.
|
||||||
if (_useCache && _cache != nullptr) {
|
if (_useCache && _cache != nullptr) {
|
||||||
|
|
|
@ -48,7 +48,6 @@ class RocksDBIndex : public Index {
|
||||||
arangodb::velocypack::Slice const&);
|
arangodb::velocypack::Slice const&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~RocksDBIndex();
|
~RocksDBIndex();
|
||||||
|
|
||||||
uint64_t objectId() const { return _objectId; }
|
uint64_t objectId() const { return _objectId; }
|
||||||
|
@ -64,13 +63,14 @@ class RocksDBIndex : public Index {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief provides a size hint for the index
|
/// @brief provides a size hint for the index
|
||||||
int sizeHint(transaction::Methods* /*trx*/, size_t /*size*/) override final{
|
int sizeHint(transaction::Methods* /*trx*/, size_t /*size*/) override final {
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
return TRI_ERROR_NO_ERROR;
|
return TRI_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void createCache();
|
void createCache();
|
||||||
|
void disableCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint64_t _objectId;
|
uint64_t _objectId;
|
||||||
|
|
|
@ -178,11 +178,12 @@ bool RocksDBAllIndexIterator::outOfRange() const {
|
||||||
|
|
||||||
uint64_t RocksDBAnyIndexIterator::OFFSET = 0;
|
uint64_t RocksDBAnyIndexIterator::OFFSET = 0;
|
||||||
|
|
||||||
RocksDBAnyIndexIterator::RocksDBAnyIndexIterator(LogicalCollection* collection, transaction::Methods* trx,
|
RocksDBAnyIndexIterator::RocksDBAnyIndexIterator(
|
||||||
ManagedDocumentResult* mmdr, RocksDBPrimaryIndex const* index)
|
LogicalCollection* collection, transaction::Methods* trx,
|
||||||
: IndexIterator(collection, trx, mmdr, index),
|
ManagedDocumentResult* mmdr, RocksDBPrimaryIndex const* index)
|
||||||
_cmp(index->_cmp),
|
: IndexIterator(collection, trx, mmdr, index),
|
||||||
_bounds(RocksDBKeyBounds::PrimaryIndex(index->objectId())) {
|
_cmp(index->_cmp),
|
||||||
|
_bounds(RocksDBKeyBounds::PrimaryIndex(index->objectId())) {
|
||||||
// aquire rocksdb transaction
|
// aquire rocksdb transaction
|
||||||
RocksDBTransactionState* state = rocksutils::toRocksTransactionState(trx);
|
RocksDBTransactionState* state = rocksutils::toRocksTransactionState(trx);
|
||||||
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
rocksdb::Transaction* rtrx = state->rocksTransaction();
|
||||||
|
@ -224,9 +225,7 @@ bool RocksDBAnyIndexIterator::next(TokenCallback const& cb, size_t limit) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RocksDBAnyIndexIterator::reset() {
|
void RocksDBAnyIndexIterator::reset() { _iterator->Seek(_bounds.start()); }
|
||||||
_iterator->Seek(_bounds.start());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RocksDBAnyIndexIterator::outOfRange() const {
|
bool RocksDBAnyIndexIterator::outOfRange() const {
|
||||||
return _cmp->Compare(_iterator->key(), _bounds.end()) > 0;
|
return _cmp->Compare(_iterator->key(), _bounds.end()) > 0;
|
||||||
|
@ -350,9 +349,18 @@ int RocksDBPrimaryIndex::insert(transaction::Methods* trx,
|
||||||
if (_useCache) {
|
if (_useCache) {
|
||||||
// blacklist from cache
|
// blacklist from cache
|
||||||
bool blacklisted = false;
|
bool blacklisted = false;
|
||||||
|
uint64_t attempts = 0;
|
||||||
while (!blacklisted) {
|
while (!blacklisted) {
|
||||||
blacklisted = _cache->blacklist(
|
blacklisted = _cache->blacklist(
|
||||||
key.string().data(), static_cast<uint32_t>(key.string().size()));
|
key.string().data(), static_cast<uint32_t>(key.string().size()));
|
||||||
|
attempts++;
|
||||||
|
if (attempts > 10) {
|
||||||
|
if (_cache->isShutdown()) {
|
||||||
|
disableCache();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
attempts = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,9 +384,18 @@ int RocksDBPrimaryIndex::remove(transaction::Methods* trx,
|
||||||
if (_useCache) {
|
if (_useCache) {
|
||||||
// blacklist from cache
|
// blacklist from cache
|
||||||
bool blacklisted = false;
|
bool blacklisted = false;
|
||||||
|
uint64_t attempts = 0;
|
||||||
while (!blacklisted) {
|
while (!blacklisted) {
|
||||||
blacklisted = _cache->blacklist(
|
blacklisted = _cache->blacklist(
|
||||||
key.string().data(), static_cast<uint32_t>(key.string().size()));
|
key.string().data(), static_cast<uint32_t>(key.string().size()));
|
||||||
|
attempts++;
|
||||||
|
if (attempts > 10) {
|
||||||
|
if (_cache->isShutdown()) {
|
||||||
|
disableCache();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
attempts = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,15 +485,16 @@ IndexIterator* RocksDBPrimaryIndex::allIterator(transaction::Methods* trx,
|
||||||
|
|
||||||
/// @brief request an iterator over all elements in the index in
|
/// @brief request an iterator over all elements in the index in
|
||||||
/// a sequential order.
|
/// a sequential order.
|
||||||
IndexIterator* RocksDBPrimaryIndex::anyIterator(transaction::Methods* trx,
|
IndexIterator* RocksDBPrimaryIndex::anyIterator(
|
||||||
ManagedDocumentResult* mmdr) const {
|
transaction::Methods* trx, ManagedDocumentResult* mmdr) const {
|
||||||
return new RocksDBAnyIndexIterator(_collection, trx, mmdr, this);
|
return new RocksDBAnyIndexIterator(_collection, trx, mmdr, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RocksDBPrimaryIndex::invokeOnAllElements(transaction::Methods* trx,
|
void RocksDBPrimaryIndex::invokeOnAllElements(
|
||||||
std::function<bool(DocumentIdentifierToken const&)> callback) {
|
transaction::Methods* trx,
|
||||||
|
std::function<bool(DocumentIdentifierToken const&)> callback) {
|
||||||
ManagedDocumentResult mmdr;
|
ManagedDocumentResult mmdr;
|
||||||
std::unique_ptr<IndexIterator> cursor (allIterator(trx, &mmdr, false));
|
std::unique_ptr<IndexIterator> cursor(allIterator(trx, &mmdr, false));
|
||||||
bool cnt = true;
|
bool cnt = true;
|
||||||
auto cb = [&](DocumentIdentifierToken token) {
|
auto cb = [&](DocumentIdentifierToken token) {
|
||||||
if (cnt) {
|
if (cnt) {
|
||||||
|
@ -484,11 +502,9 @@ void RocksDBPrimaryIndex::invokeOnAllElements(transaction::Methods* trx,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
while (cursor->next(cb, 1000) && cnt) {
|
while (cursor->next(cb, 1000) && cnt) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief create the iterator, for a single attribute, IN operator
|
/// @brief create the iterator, for a single attribute, IN operator
|
||||||
IndexIterator* RocksDBPrimaryIndex::createInIterator(
|
IndexIterator* RocksDBPrimaryIndex::createInIterator(
|
||||||
transaction::Methods* trx, ManagedDocumentResult* mmdr,
|
transaction::Methods* trx, ManagedDocumentResult* mmdr,
|
||||||
|
|
Loading…
Reference in New Issue