1
0
Fork 0

Changed RocksDBValue API slightly.

This commit is contained in:
Dan Larkin 2017-03-28 11:42:52 -04:00
parent 6a39e962bd
commit 3ec6934eb5
5 changed files with 51 additions and 41 deletions

View File

@ -21,6 +21,7 @@
/// @author Jan-Christoph Uhde
////////////////////////////////////////////////////////////////////////////////
#include "RocksDBCollection.h"
#include "Aql/PlanCache.h"
#include "Basics/Result.h"
#include "Basics/StaticStrings.h"
@ -29,16 +30,14 @@
#include "Indexes/Index.h"
#include "Indexes/IndexIterator.h"
#include "RestServer/DatabaseFeature.h"
#include "RocksDBCollection.h"
#include "RocksDBEngine/RocksDBCommon.h"
#include "RocksDBEngine/RocksDBEngine.h"
#include "RocksDBEngine/RocksDBKey.h"
#include "RocksDBEngine/RocksDBPrimaryMockIndex.h"
#include "RocksDBEngine/RocksDBToken.h"
#include "RocksDBEngine/RocksDBValue.h"
#include "RocksDBEngine/RocksDBTransactionState.h"
#include "RocksDBEngine/RocksDBValue.h"
#include "StorageEngine/EngineSelectorFeature.h"
#include "StorageEngine/TransactionState.h"
#include "StorageEngine/StorageEngine.h"
#include "StorageEngine/TransactionState.h"
#include "Transaction/Helpers.h"
@ -55,7 +54,7 @@ using namespace arangodb;
using namespace arangodb::rocksutils;
static std::string const Empty;
rocksdb::TransactionDB* db() {
StorageEngine* engine = EngineSelectorFeature::ENGINE;
return static_cast<RocksDBEngine*>(engine)->db();
@ -307,7 +306,9 @@ std::unique_ptr<IndexIterator> RocksDBCollection::getAllIterator(
std::unique_ptr<IndexIterator> RocksDBCollection::getAnyIterator(
transaction::Methods* trx, ManagedDocumentResult* mdr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_NOT_IMPLEMENTED, "this engine does not provide an any iterator");
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_NOT_IMPLEMENTED,
"this engine does not provide an any iterator");
}
void RocksDBCollection::invokeOnAllElements(
@ -662,7 +663,7 @@ int RocksDBCollection::insertDocument(arangodb::transaction::Methods* trx,
RocksDBValue value(RocksDBValue::Document(doc));
rocksdb::WriteBatch writeBatch;
writeBatch.Put(key.string(), value.value());
writeBatch.Put(key.string(), *value.string());
auto indexes = _indexes;
size_t const n = indexes.size();
@ -793,14 +794,19 @@ int RocksDBCollection::updateDocument(transaction::Methods* trx,
}
Result RocksDBCollection::lookupDocumentToken(transaction::Methods* trx,
arangodb::StringRef key, RocksDBToken &outToken) {
arangodb::StringRef key,
RocksDBToken& outToken) {
// TODO fix as soon as we got a real primary index
outToken = primaryIndex()->lookupKey(trx, key);
return outToken.revisionId() > 0 ? Result() : Result(TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
return outToken.revisionId() > 0
? Result()
: Result(TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
}
void RocksDBCollection::lookupRevisionVPack(TRI_voc_rid_t revisionId, transaction::Methods* trx,arangodb::ManagedDocumentResult& result){
auto key = RocksDBKey::Document(_objectId,revisionId);
void RocksDBCollection::lookupRevisionVPack(
TRI_voc_rid_t revisionId, transaction::Methods* trx,
arangodb::ManagedDocumentResult& result) {
auto key = RocksDBKey::Document(_objectId, revisionId);
std::string value;
TRI_ASSERT(value.data());
auto* state = toRocksTransactionState(trx);

View File

@ -356,7 +356,7 @@ int RocksDBEngine::writeCreateDatabaseMarker(TRI_voc_tick_t id,
auto value = RocksDBValue::Database(slice);
rocksdb::WriteOptions options; // TODO: check which options would make sense
rocksdb::Status res = _db->Put(options, key.string(), value.value());
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
if (res.ok()) {
return TRI_ERROR_NO_ERROR;
}
@ -370,7 +370,7 @@ int RocksDBEngine::writeCreateCollectionMarker(TRI_voc_tick_t databaseId,
auto value = RocksDBValue::Collection(slice);
rocksdb::WriteOptions options; // TODO: check which options would make sense
rocksdb::Status res = _db->Put(options, key.string(), value.value());
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
if (res.ok()) {
return TRI_ERROR_NO_ERROR;
}
@ -473,7 +473,7 @@ void RocksDBEngine::createIndex(TRI_vocbase_t* vocbase,
auto value = RocksDBValue::Index(data);
rocksdb::WriteOptions options; // TODO: check which options would make sense
rocksdb::Status res = _db->Put(options, key.string(), value.value());
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
if (!res.ok()) {
// TODO: need translation for RocksDB errors
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);

View File

@ -24,13 +24,12 @@
#include "RocksDBTypes.h"
using namespace arangodb;
namespace {
static RocksDBEntryType database = arangodb::RocksDBEntryType::Database;
static rocksdb::Slice Database(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
&database),
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&database),
1);
static RocksDBEntryType collection = RocksDBEntryType::Collection;
@ -41,17 +40,24 @@ static rocksdb::Slice Collection(
static RocksDBEntryType index = RocksDBEntryType::Index;
static rocksdb::Slice Index(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&index),
1);
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&index), 1);
static RocksDBEntryType document = RocksDBEntryType::Document;
static rocksdb::Slice Document(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
&document),
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&document),
1);
static RocksDBEntryType primaryIndexValue = RocksDBEntryType::PrimaryIndexValue;
static rocksdb::Slice PrimaryIndexValue(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
&primaryIndexValue),
1);
static RocksDBEntryType edgeIndexValue = RocksDBEntryType::EdgeIndexValue;
static rocksdb::Slice EdgeIndexValue(reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&edgeIndexValue), 1);
static rocksdb::Slice EdgeIndexValue(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
&edgeIndexValue),
1);
static RocksDBEntryType indexValue = RocksDBEntryType::IndexValue;
static rocksdb::Slice IndexValue(
@ -67,9 +73,7 @@ static rocksdb::Slice UniqueIndexValue(
static RocksDBEntryType view = RocksDBEntryType::View;
static rocksdb::Slice View(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&view),
1);
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&view), 1);
}
rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
@ -80,6 +84,8 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
return Collection;
case RocksDBEntryType::Database:
return Database;
case RocksDBEntryType::PrimaryIndexValue:
return PrimaryIndexValue;
case RocksDBEntryType::EdgeIndexValue:
return EdgeIndexValue;
case RocksDBEntryType::Index:
@ -92,5 +98,5 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
return View;
}
return Document; //avoids warning - errorslice instead ?!
return Document; // avoids warning - errorslice instead ?!
}

View File

@ -66,6 +66,10 @@ RocksDBValue RocksDBValue::View(VPackSlice const& data) {
return RocksDBValue(RocksDBEntryType::View, data);
}
RocksDBValue RocksDBValue::Empty(RocksDBEntryType type) {
return RocksDBValue(type);
}
TRI_voc_rid_t RocksDBValue::revisionId(RocksDBValue const& value) {
return revisionId(value._buffer.data(), value._buffer.size());
}
@ -102,19 +106,9 @@ VPackSlice RocksDBValue::data(std::string const& s) {
return data(s.data(), s.size());
}
std::string const& RocksDBValue::value() const { return _buffer; }
std::string* RocksDBValue::string() { return &_buffer; }
RocksDBValue::RocksDBValue(RocksDBEntryType type) : _type(type), _buffer() {
switch (_type) {
case RocksDBEntryType::EdgeIndexValue:
case RocksDBEntryType::IndexValue: {
break;
}
default:
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}
}
RocksDBValue::RocksDBValue(RocksDBEntryType type) : _type(type), _buffer() {}
RocksDBValue::RocksDBValue(RocksDBEntryType type, uint64_t data)
: _type(type), _buffer() {

View File

@ -38,8 +38,6 @@ namespace arangodb {
class RocksDBValue {
public:
RocksDBValue() = delete;
//----------------------------------------------------------------------------
// SECTION Constructors
// Each of these simply specifies the correct type and copies the input
@ -56,6 +54,11 @@ class RocksDBValue {
static RocksDBValue UniqueIndexValue(std::string const& primaryKey);
static RocksDBValue View(VPackSlice const& data);
//////////////////////////////////////////////////////////////////////////////
/// @brief Used to construct an empty value of the given type for retrieval
//////////////////////////////////////////////////////////////////////////////
static RocksDBValue Empty(RocksDBEntryType type);
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief Extracts the revisionId from a value
@ -90,9 +93,10 @@ class RocksDBValue {
//////////////////////////////////////////////////////////////////////////////
/// @brief Returns a reference to the underlying string buffer.
//////////////////////////////////////////////////////////////////////////////
std::string const& value() const;
std::string* string();
private:
RocksDBValue();
RocksDBValue(RocksDBEntryType type);
RocksDBValue(RocksDBEntryType type, uint64_t data);
RocksDBValue(RocksDBEntryType type, std::string const& data);