From e6919fc6c22bafc25dc6618f212bf4c6b45c61b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Gra=CC=88tzer?= Date: Mon, 3 Apr 2017 17:28:13 +0200 Subject: [PATCH] Fixed comparator --- arangod/RocksDBEngine/RocksDBKeyBounds.cpp | 50 ++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/arangod/RocksDBEngine/RocksDBKeyBounds.cpp b/arangod/RocksDBEngine/RocksDBKeyBounds.cpp index 6ba9596bdd..58e5962217 100644 --- a/arangod/RocksDBEngine/RocksDBKeyBounds.cpp +++ b/arangod/RocksDBEngine/RocksDBKeyBounds.cpp @@ -27,6 +27,8 @@ #include "RocksDBEngine/RocksDBCommon.h" #include "RocksDBEngine/RocksDBTypes.h" +#include "Logger/Logger.h" + using namespace arangodb; using namespace arangodb::rocksutils; using namespace arangodb::velocypack; @@ -135,12 +137,53 @@ RocksDBKeyBounds::RocksDBKeyBounds(RocksDBEntryType type) RocksDBKeyBounds::RocksDBKeyBounds(RocksDBEntryType type, uint64_t first) : _type(type), _startBuffer(), _endBuffer() { switch (_type) { + case RocksDBEntryType::IndexValue: + case RocksDBEntryType::UniqueIndexValue: { + // Unique VPack index values are stored as follows: + // 7 + 8-byte object ID of index + VPack array with index value(s) .... + // prefix is the same for non-unique indexes + // static slices with an array with one entry + VPackSlice min("\x02\x03\x1e");// [minSlice] + VPackSlice max("\x02\x03\x1f");// [maxSlice] + + size_t length = sizeof(char) + sizeof(uint64_t) + min.byteSize(); + _startBuffer.reserve(length); + _startBuffer.push_back(static_cast(_type)); + uint64ToPersistent(_startBuffer, first); + // append common prefix + _endBuffer.clear(); + _endBuffer.append(_startBuffer); + + // construct min max + _startBuffer.append((char*)(min.begin()), min.byteSize()); + _endBuffer.append((char*)(max.begin()), max.byteSize()); + break; + } + case RocksDBEntryType::Collection: - case RocksDBEntryType::Document: + case RocksDBEntryType::Document:{ + // Collections are stored as follows: + // Key: 1 + 8-byte ArangoDB database ID + 8-byte ArangoDB collection ID + // + // Documents are stored as follows: + // Key: 3 + 8-byte object ID of collection + 8-byte document revision ID + size_t length = sizeof(char) + sizeof(uint64_t) * 2; + _startBuffer.reserve(length); + _startBuffer.push_back(static_cast(_type)); + uint64ToPersistent(_startBuffer, first); + // append common prefix + _endBuffer.clear(); + _endBuffer.append(_startBuffer); + + // construct min max + uint64ToPersistent(_startBuffer, 0); + uint64ToPersistent(_endBuffer, UINT64_MAX); + break; + } + + case RocksDBEntryType::PrimaryIndexValue: case RocksDBEntryType::EdgeIndexValue: - case RocksDBEntryType::IndexValue: - case RocksDBEntryType::UniqueIndexValue: case RocksDBEntryType::View: { size_t length = sizeof(char) + sizeof(uint64_t); _startBuffer.reserve(length); @@ -150,7 +193,6 @@ RocksDBKeyBounds::RocksDBKeyBounds(RocksDBEntryType type, uint64_t first) _endBuffer.clear(); _endBuffer.append(_startBuffer); nextPrefix(_endBuffer); - break; }