mirror of https://gitee.com/bigwinds/arangodb
implement basic operations for settings
This commit is contained in:
parent
507054de99
commit
b7bf8a8983
|
@ -26,17 +26,17 @@
|
|||
#include "Basics/ReadLocker.h"
|
||||
#include "Basics/WriteLocker.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "RocksDBEngine/RocksDBCommon.h"
|
||||
#include "RocksDBEngine/RocksDBKey.h"
|
||||
#include "RocksDBEngine/RocksDBKeyBounds.h"
|
||||
#include "RocksDBEngine/RocksDBValue.h"
|
||||
|
||||
#include "RocksDBEngine/RocksDBCommon.h"
|
||||
|
||||
#include <rocksdb/utilities/transaction_db.h>
|
||||
#include <rocksdb/utilities/write_batch_with_index.h>
|
||||
#include <rocksdb/write_batch.h>
|
||||
|
||||
#include <velocypack/Iterator.h>
|
||||
#include <velocypack/Slice.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
using namespace arangodb;
|
||||
|
@ -68,6 +68,8 @@ void RocksDBCounterManager::CMValue::serialize(VPackBuilder& b) const {
|
|||
/// will load counts from the db and scan the WAL
|
||||
RocksDBCounterManager::RocksDBCounterManager(rocksdb::DB* db)
|
||||
: _db(db) {
|
||||
readSettings();
|
||||
|
||||
readCounterValues();
|
||||
if (_counters.size() > 0) {
|
||||
if (parseRocksWAL()) {
|
||||
|
@ -148,6 +150,8 @@ Result RocksDBCounterManager::sync() {
|
|||
return Result();
|
||||
}
|
||||
|
||||
writeSettings();
|
||||
|
||||
std::unordered_map<uint64_t, CMValue> copy;
|
||||
{ // block all updates
|
||||
WRITE_LOCKER(guard, _rwLock);
|
||||
|
@ -197,6 +201,39 @@ Result RocksDBCounterManager::sync() {
|
|||
return rocksutils::convertStatus(s);
|
||||
}
|
||||
|
||||
void RocksDBCounterManager::readSettings() {
|
||||
#if 0
|
||||
RocksDBKey key = RocksDBKey::SettingsValue();
|
||||
|
||||
std::string result;
|
||||
rocksdb::Status status = _db->Get(rocksdb::ReadOptions(), key.string(), &result);
|
||||
if (status.ok()) {
|
||||
// key may not be there...
|
||||
VPackSlice slice = VPackSlice(result.data());
|
||||
TRI_ASSERT(slice.isObject());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void RocksDBCounterManager::writeSettings() {
|
||||
#if 0
|
||||
RocksDBKey key = RocksDBKey::SettingsValue();
|
||||
|
||||
VPackBuilder builder;
|
||||
builder.openObject();
|
||||
builder.close();
|
||||
|
||||
VPackSlice slice = builder.slice();
|
||||
rocksdb::Slice value(slice.startAs<char>(), slice.byteSize());
|
||||
|
||||
rocksdb::Status status = _db->Put(rocksdb::WriteOptions(), key.string(), value);
|
||||
|
||||
if (status.ok()) {
|
||||
// TODO
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Parse counter values from rocksdb
|
||||
void RocksDBCounterManager::readCounterValues() {
|
||||
WRITE_LOCKER(guard, _rwLock);
|
||||
|
|
|
@ -100,6 +100,9 @@ class RocksDBCounterManager {
|
|||
};
|
||||
|
||||
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
void readCounterValues();
|
||||
bool parseRocksWAL();
|
||||
|
||||
|
|
|
@ -85,6 +85,10 @@ RocksDBKey RocksDBKey::CounterValue(uint64_t objectId) {
|
|||
return RocksDBKey(RocksDBEntryType::CounterValue, objectId);
|
||||
}
|
||||
|
||||
RocksDBKey RocksDBKey::SettingsValue() {
|
||||
return RocksDBKey(RocksDBEntryType::SettingsValue);
|
||||
}
|
||||
|
||||
RocksDBEntryType RocksDBKey::type(RocksDBKey const& key) {
|
||||
return type(key._buffer.data(), key._buffer.size());
|
||||
}
|
||||
|
@ -156,6 +160,19 @@ VPackSlice RocksDBKey::indexedVPack(rocksdb::Slice const& slice) {
|
|||
|
||||
std::string const& RocksDBKey::string() const { return _buffer; }
|
||||
|
||||
RocksDBKey::RocksDBKey(RocksDBEntryType type)
|
||||
: _type(type), _buffer() {
|
||||
switch (_type) {
|
||||
case RocksDBEntryType::SettingsValue: {
|
||||
_buffer.push_back(static_cast<char>(_type));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
|
||||
}
|
||||
}
|
||||
|
||||
RocksDBKey::RocksDBKey(RocksDBEntryType type, uint64_t first)
|
||||
: _type(type), _buffer() {
|
||||
switch (_type) {
|
||||
|
|
|
@ -109,6 +109,11 @@ class RocksDBKey {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
static RocksDBKey View(TRI_voc_tick_t databaseId, TRI_voc_cid_t viewId);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Create a fully-specified key for a settings value
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
static RocksDBKey SettingsValue();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Create a fully-specified key for a counter value
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -129,7 +134,7 @@ class RocksDBKey {
|
|||
/// May be called on any valid key (in our keyspace)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
static uint64_t counterObjectId(rocksdb::Slice const&);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Extracts the databaseId from a key
|
||||
///
|
||||
|
@ -198,6 +203,7 @@ class RocksDBKey {
|
|||
std::string const& string() const;
|
||||
|
||||
private:
|
||||
explicit RocksDBKey(RocksDBEntryType type);
|
||||
RocksDBKey(RocksDBEntryType type, uint64_t first);
|
||||
RocksDBKey(RocksDBEntryType type, uint64_t first, uint64_t second);
|
||||
RocksDBKey(RocksDBEntryType type, uint64_t first, VPackSlice const& slice);
|
||||
|
|
|
@ -106,14 +106,13 @@ RocksDBKeyBounds::RocksDBKeyBounds(RocksDBEntryType type)
|
|||
_startBuffer.reserve(length);
|
||||
_startBuffer.push_back(static_cast<char>(_type));
|
||||
|
||||
_endBuffer.clear();
|
||||
_endBuffer.append(_startBuffer);
|
||||
nextPrefix(_endBuffer);
|
||||
|
||||
break;
|
||||
}
|
||||
case RocksDBEntryType::CounterValue: {
|
||||
size_t length = sizeof(char);
|
||||
size_t length = sizeof(char) + sizeof(uint64_t);
|
||||
_startBuffer.reserve(length);
|
||||
_startBuffer.push_back(static_cast<char>(_type));
|
||||
uint64ToPersistent(_startBuffer, 0);
|
||||
|
|
|
@ -74,6 +74,10 @@ static rocksdb::Slice UniqueIndexValue(
|
|||
static RocksDBEntryType view = RocksDBEntryType::View;
|
||||
static rocksdb::Slice View(
|
||||
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&view), 1);
|
||||
|
||||
static RocksDBEntryType settingsValue = RocksDBEntryType::SettingsValue;
|
||||
static rocksdb::Slice SettingsValue(
|
||||
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&settingsValue), 1);
|
||||
}
|
||||
|
||||
rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
|
||||
|
@ -96,6 +100,8 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
|
|||
return UniqueIndexValue;
|
||||
case RocksDBEntryType::View:
|
||||
return View;
|
||||
case RocksDBEntryType::SettingsValue:
|
||||
return SettingsValue;
|
||||
}
|
||||
|
||||
return Document; // avoids warning - errorslice instead ?!
|
||||
|
|
|
@ -40,7 +40,8 @@ enum class RocksDBEntryType : char {
|
|||
EdgeIndexValue = '5',
|
||||
IndexValue = '6',
|
||||
UniqueIndexValue = '7',
|
||||
View = '8'
|
||||
View = '8',
|
||||
SettingsValue = '9'
|
||||
};
|
||||
|
||||
rocksdb::Slice const& rocksDBSlice(RocksDBEntryType const& type);
|
||||
|
|
Loading…
Reference in New Issue