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 /// @author Jan-Christoph Uhde
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "RocksDBCollection.h"
#include "Aql/PlanCache.h" #include "Aql/PlanCache.h"
#include "Basics/Result.h" #include "Basics/Result.h"
#include "Basics/StaticStrings.h" #include "Basics/StaticStrings.h"
@ -29,16 +30,14 @@
#include "Indexes/Index.h" #include "Indexes/Index.h"
#include "Indexes/IndexIterator.h" #include "Indexes/IndexIterator.h"
#include "RestServer/DatabaseFeature.h" #include "RestServer/DatabaseFeature.h"
#include "RocksDBCollection.h"
#include "RocksDBEngine/RocksDBCommon.h" #include "RocksDBEngine/RocksDBCommon.h"
#include "RocksDBEngine/RocksDBEngine.h" #include "RocksDBEngine/RocksDBEngine.h"
#include "RocksDBEngine/RocksDBKey.h" #include "RocksDBEngine/RocksDBKey.h"
#include "RocksDBEngine/RocksDBPrimaryMockIndex.h" #include "RocksDBEngine/RocksDBPrimaryMockIndex.h"
#include "RocksDBEngine/RocksDBToken.h" #include "RocksDBEngine/RocksDBToken.h"
#include "RocksDBEngine/RocksDBValue.h"
#include "RocksDBEngine/RocksDBTransactionState.h" #include "RocksDBEngine/RocksDBTransactionState.h"
#include "RocksDBEngine/RocksDBValue.h"
#include "StorageEngine/EngineSelectorFeature.h" #include "StorageEngine/EngineSelectorFeature.h"
#include "StorageEngine/TransactionState.h"
#include "StorageEngine/StorageEngine.h" #include "StorageEngine/StorageEngine.h"
#include "StorageEngine/TransactionState.h" #include "StorageEngine/TransactionState.h"
#include "Transaction/Helpers.h" #include "Transaction/Helpers.h"
@ -307,7 +306,9 @@ std::unique_ptr<IndexIterator> RocksDBCollection::getAllIterator(
std::unique_ptr<IndexIterator> RocksDBCollection::getAnyIterator( std::unique_ptr<IndexIterator> RocksDBCollection::getAnyIterator(
transaction::Methods* trx, ManagedDocumentResult* mdr) { 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( void RocksDBCollection::invokeOnAllElements(
@ -662,7 +663,7 @@ int RocksDBCollection::insertDocument(arangodb::transaction::Methods* trx,
RocksDBValue value(RocksDBValue::Document(doc)); RocksDBValue value(RocksDBValue::Document(doc));
rocksdb::WriteBatch writeBatch; rocksdb::WriteBatch writeBatch;
writeBatch.Put(key.string(), value.value()); writeBatch.Put(key.string(), *value.string());
auto indexes = _indexes; auto indexes = _indexes;
size_t const n = indexes.size(); size_t const n = indexes.size();
@ -793,14 +794,19 @@ int RocksDBCollection::updateDocument(transaction::Methods* trx,
} }
Result RocksDBCollection::lookupDocumentToken(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 // TODO fix as soon as we got a real primary index
outToken = primaryIndex()->lookupKey(trx, key); 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){ void RocksDBCollection::lookupRevisionVPack(
auto key = RocksDBKey::Document(_objectId,revisionId); TRI_voc_rid_t revisionId, transaction::Methods* trx,
arangodb::ManagedDocumentResult& result) {
auto key = RocksDBKey::Document(_objectId, revisionId);
std::string value; std::string value;
TRI_ASSERT(value.data()); TRI_ASSERT(value.data());
auto* state = toRocksTransactionState(trx); auto* state = toRocksTransactionState(trx);

View File

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

View File

@ -29,8 +29,7 @@ namespace {
static RocksDBEntryType database = arangodb::RocksDBEntryType::Database; static RocksDBEntryType database = arangodb::RocksDBEntryType::Database;
static rocksdb::Slice Database( static rocksdb::Slice Database(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>( reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&database),
&database),
1); 1);
static RocksDBEntryType collection = RocksDBEntryType::Collection; static RocksDBEntryType collection = RocksDBEntryType::Collection;
@ -41,17 +40,24 @@ static rocksdb::Slice Collection(
static RocksDBEntryType index = RocksDBEntryType::Index; static RocksDBEntryType index = RocksDBEntryType::Index;
static rocksdb::Slice Index( static rocksdb::Slice Index(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&index), reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&index), 1);
1);
static RocksDBEntryType document = RocksDBEntryType::Document; static RocksDBEntryType document = RocksDBEntryType::Document;
static rocksdb::Slice Document( static rocksdb::Slice 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*>( reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
&document), &primaryIndexValue),
1); 1);
static RocksDBEntryType edgeIndexValue = RocksDBEntryType::EdgeIndexValue; 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 RocksDBEntryType indexValue = RocksDBEntryType::IndexValue;
static rocksdb::Slice IndexValue( static rocksdb::Slice IndexValue(
@ -67,9 +73,7 @@ static rocksdb::Slice UniqueIndexValue(
static RocksDBEntryType view = RocksDBEntryType::View; static RocksDBEntryType view = RocksDBEntryType::View;
static rocksdb::Slice View( static rocksdb::Slice View(
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&view), reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(&view), 1);
1);
} }
rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) { rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
@ -80,6 +84,8 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
return Collection; return Collection;
case RocksDBEntryType::Database: case RocksDBEntryType::Database:
return Database; return Database;
case RocksDBEntryType::PrimaryIndexValue:
return PrimaryIndexValue;
case RocksDBEntryType::EdgeIndexValue: case RocksDBEntryType::EdgeIndexValue:
return EdgeIndexValue; return EdgeIndexValue;
case RocksDBEntryType::Index: case RocksDBEntryType::Index:
@ -92,5 +98,5 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
return View; 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); return RocksDBValue(RocksDBEntryType::View, data);
} }
RocksDBValue RocksDBValue::Empty(RocksDBEntryType type) {
return RocksDBValue(type);
}
TRI_voc_rid_t RocksDBValue::revisionId(RocksDBValue const& value) { TRI_voc_rid_t RocksDBValue::revisionId(RocksDBValue const& value) {
return revisionId(value._buffer.data(), value._buffer.size()); 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()); 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() { 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, uint64_t data) RocksDBValue::RocksDBValue(RocksDBEntryType type, uint64_t data)
: _type(type), _buffer() { : _type(type), _buffer() {

View File

@ -38,8 +38,6 @@ namespace arangodb {
class RocksDBValue { class RocksDBValue {
public: public:
RocksDBValue() = delete;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// SECTION Constructors // SECTION Constructors
// Each of these simply specifies the correct type and copies the input // 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 UniqueIndexValue(std::string const& primaryKey);
static RocksDBValue View(VPackSlice const& data); 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: public:
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief Extracts the revisionId from a value /// @brief Extracts the revisionId from a value
@ -90,9 +93,10 @@ class RocksDBValue {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief Returns a reference to the underlying string buffer. /// @brief Returns a reference to the underlying string buffer.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
std::string const& value() const; std::string* string();
private: private:
RocksDBValue();
RocksDBValue(RocksDBEntryType type); RocksDBValue(RocksDBEntryType type);
RocksDBValue(RocksDBEntryType type, uint64_t data); RocksDBValue(RocksDBEntryType type, uint64_t data);
RocksDBValue(RocksDBEntryType type, std::string const& data); RocksDBValue(RocksDBEntryType type, std::string const& data);