1
0
Fork 0

Adding edge key into edge index

This commit is contained in:
Simon Grätzer 2017-06-01 16:07:39 +02:00
parent 2006a53342
commit 3e8c16d1a7
4 changed files with 37 additions and 23 deletions

View File

@ -387,6 +387,7 @@ RocksDBEdgeIndex::RocksDBEdgeIndex(TRI_idx_iid_t iid,
!ServerState::instance()->isCoordinator() /*useCache*/ !ServerState::instance()->isCoordinator() /*useCache*/
), ),
_directionAttr(attr), _directionAttr(attr),
_isFromIndex(attr == StaticStrings::FromString),
_estimator(nullptr) { _estimator(nullptr) {
if (!ServerState::instance()->isCoordinator()) { if (!ServerState::instance()->isCoordinator()) {
// We activate the estimator only on DBServers // We activate the estimator only on DBServers
@ -450,12 +451,16 @@ int RocksDBEdgeIndex::insert(transaction::Methods* trx,
TRI_ASSERT(fromTo.isString()); TRI_ASSERT(fromTo.isString());
auto fromToRef = StringRef(fromTo); auto fromToRef = StringRef(fromTo);
RocksDBKey key = RocksDBKey::EdgeIndexValue(_objectId, fromToRef, revisionId); RocksDBKey key = RocksDBKey::EdgeIndexValue(_objectId, fromToRef, revisionId);
VPackSlice toFrom = _isFromIndex ? doc.get(StaticStrings::ToString) : doc.get(StaticStrings::FromString);
TRI_ASSERT(toFrom.isString());
RocksDBValue value = RocksDBValue::EdgeIndexValue(StringRef(toFrom));
// blacklist key in cache // blacklist key in cache
blackListKey(fromToRef); blackListKey(fromToRef);
// acquire rocksdb transaction // acquire rocksdb transaction
RocksDBMethods* mthd = rocksutils::toRocksMethods(trx); RocksDBMethods* mthd = rocksutils::toRocksMethods(trx);
Result r = mthd->Put(_cf, rocksdb::Slice(key.string()), rocksdb::Slice(), Result r = mthd->Put(_cf, rocksdb::Slice(key.string()), value.string(),
rocksutils::index); rocksutils::index);
if (r.ok()) { if (r.ok()) {
std::hash<StringRef> hasher; std::hash<StringRef> hasher;
@ -480,6 +485,9 @@ int RocksDBEdgeIndex::remove(transaction::Methods* trx,
auto fromToRef = StringRef(fromTo); auto fromToRef = StringRef(fromTo);
TRI_ASSERT(fromTo.isString()); TRI_ASSERT(fromTo.isString());
RocksDBKey key = RocksDBKey::EdgeIndexValue(_objectId, fromToRef, revisionId); RocksDBKey key = RocksDBKey::EdgeIndexValue(_objectId, fromToRef, revisionId);
VPackSlice toFrom = _isFromIndex ? doc.get(StaticStrings::ToString) : doc.get(StaticStrings::FromString);
TRI_ASSERT(toFrom.isString());
RocksDBValue value = RocksDBValue::EdgeIndexValue(StringRef(toFrom));
// blacklist key in cache // blacklist key in cache
blackListKey(fromToRef); blackListKey(fromToRef);

View File

@ -184,6 +184,7 @@ class RocksDBEdgeIndex final : public RocksDBIndex {
arangodb::aql::AstNode const* valNode) const; arangodb::aql::AstNode const* valNode) const;
std::string _directionAttr; std::string _directionAttr;
bool _isFromIndex;
/// @brief A fixed size library to estimate the selectivity of the index. /// @brief A fixed size library to estimate the selectivity of the index.
/// On insertion of a document we have to insert it into the estimator, /// On insertion of a document we have to insert it into the estimator,

View File

@ -45,8 +45,8 @@ RocksDBValue RocksDBValue::PrimaryIndexValue(TRI_voc_rid_t revisionId) {
return RocksDBValue(RocksDBEntryType::PrimaryIndexValue, revisionId); return RocksDBValue(RocksDBEntryType::PrimaryIndexValue, revisionId);
} }
RocksDBValue RocksDBValue::EdgeIndexValue() { RocksDBValue RocksDBValue::EdgeIndexValue(arangodb::StringRef const& vertexId) {
return RocksDBValue(RocksDBEntryType::EdgeIndexValue); return RocksDBValue(RocksDBEntryType::EdgeIndexValue, vertexId);
} }
RocksDBValue RocksDBValue::IndexValue() { RocksDBValue RocksDBValue::IndexValue() {
@ -81,16 +81,8 @@ TRI_voc_rid_t RocksDBValue::revisionId(std::string const& s) {
return revisionId(s.data(), s.size()); return revisionId(s.data(), s.size());
} }
StringRef RocksDBValue::primaryKey(RocksDBValue const& value) { StringRef RocksDBValue::vertexId(rocksdb::Slice const& s) {
return primaryKey(value._buffer.data(), value._buffer.size()); return vertexId(s.data(), s.size());
}
StringRef RocksDBValue::primaryKey(rocksdb::Slice const& slice) {
return primaryKey(slice.data(), slice.size());
}
StringRef RocksDBValue::primaryKey(std::string const& s) {
return primaryKey(s.data(), s.size());
} }
VPackSlice RocksDBValue::data(RocksDBValue const& value) { VPackSlice RocksDBValue::data(RocksDBValue const& value) {
@ -141,12 +133,26 @@ RocksDBValue::RocksDBValue(RocksDBEntryType type, VPackSlice const& data)
} }
} }
RocksDBValue::RocksDBValue(RocksDBEntryType type, StringRef const& data)
: _type(type), _buffer() {
switch (_type) {
case RocksDBEntryType::EdgeIndexValue: {
_buffer.reserve(static_cast<size_t>(data.size()));
_buffer.append(data.data(), data.size());
break;
}
default:
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
}
}
TRI_voc_rid_t RocksDBValue::revisionId(char const* data, uint64_t size) { TRI_voc_rid_t RocksDBValue::revisionId(char const* data, uint64_t size) {
TRI_ASSERT(data != nullptr && size >= sizeof(uint64_t)); TRI_ASSERT(data != nullptr && size >= sizeof(uint64_t));
return uint64FromPersistent(data); return uint64FromPersistent(data);
} }
StringRef RocksDBValue::primaryKey(char const* data, size_t size) { StringRef RocksDBValue::vertexId(char const* data, size_t size) {
TRI_ASSERT(data != nullptr); TRI_ASSERT(data != nullptr);
TRI_ASSERT(size >= sizeof(char)); TRI_ASSERT(size >= sizeof(char));
return StringRef(data, size); return StringRef(data, size);

View File

@ -49,7 +49,7 @@ class RocksDBValue {
static RocksDBValue Collection(VPackSlice const& data); static RocksDBValue Collection(VPackSlice const& data);
static RocksDBValue Document(VPackSlice const& data); static RocksDBValue Document(VPackSlice const& data);
static RocksDBValue PrimaryIndexValue(TRI_voc_rid_t revisionId); static RocksDBValue PrimaryIndexValue(TRI_voc_rid_t revisionId);
static RocksDBValue EdgeIndexValue(); static RocksDBValue EdgeIndexValue(arangodb::StringRef const& vertexId);
static RocksDBValue IndexValue(); static RocksDBValue IndexValue();
static RocksDBValue UniqueIndexValue(TRI_voc_rid_t revisionId); static RocksDBValue UniqueIndexValue(TRI_voc_rid_t revisionId);
static RocksDBValue View(VPackSlice const& data); static RocksDBValue View(VPackSlice const& data);
@ -72,14 +72,12 @@ class RocksDBValue {
static TRI_voc_rid_t revisionId(std::string const&); static TRI_voc_rid_t revisionId(std::string const&);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief Extracts the primary key (`_key`) from a value /// @brief Extracts the vertex _to or _from ID (`_key`) from a value
/// ///
/// May be called only on UniqueIndexValue values. Other types will throw. /// May be called only on EdgeIndexValue values. Other types will throw.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
static StringRef primaryKey(RocksDBValue const&); static StringRef vertexId(rocksdb::Slice const&);
static StringRef primaryKey(rocksdb::Slice const&);
static StringRef primaryKey(std::string const&);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief Extracts the VelocyPack data from a value /// @brief Extracts the VelocyPack data from a value
/// ///
@ -111,11 +109,12 @@ class RocksDBValue {
explicit RocksDBValue(RocksDBEntryType type); explicit RocksDBValue(RocksDBEntryType type);
RocksDBValue(RocksDBEntryType type, uint64_t data); RocksDBValue(RocksDBEntryType type, uint64_t data);
RocksDBValue(RocksDBEntryType type, VPackSlice const& data); RocksDBValue(RocksDBEntryType type, VPackSlice const& data);
RocksDBValue(RocksDBEntryType type, arangodb::StringRef const& data);
private: private:
static RocksDBEntryType type(char const* data, size_t size); static RocksDBEntryType type(char const* data, size_t size);
static TRI_voc_rid_t revisionId(char const* data, uint64_t size); static TRI_voc_rid_t revisionId(char const* data, uint64_t size);
static StringRef primaryKey(char const* data, size_t size); static StringRef vertexId(char const* data, size_t size);
static VPackSlice data(char const* data, size_t size); static VPackSlice data(char const* data, size_t size);
private: private: