1
0
Fork 0

Added geo index CRUD functionality

This commit is contained in:
Simon Grätzer 2017-05-08 14:49:58 +02:00
parent a610d81e3d
commit 9098776589
4 changed files with 97 additions and 52 deletions

View File

@ -29,8 +29,8 @@
#include "Basics/StringRef.h"
#include "Basics/VelocyPackHelper.h"
#include "Logger/Logger.h"
#include "StorageEngine/TransactionState.h"
#include "RocksDBEngine/RocksDBToken.h"
#include "StorageEngine/TransactionState.h"
using namespace arangodb;
@ -384,7 +384,7 @@ bool RocksDBGeoIndex::matchesDefinition(VPackSlice const& info) const {
return true;
}
int RocksDBGeoIndex::insert(transaction::Methods *, TRI_voc_rid_t revisionId,
int RocksDBGeoIndex::insert(transaction::Methods*, TRI_voc_rid_t revisionId,
VPackSlice const& doc, bool isRollback) {
double latitude;
double longitude;
@ -523,7 +523,6 @@ int RocksDBGeoIndex::removeRaw(rocksdb::WriteBatch*, TRI_voc_rid_t revisionId,
return this->remove(nullptr, revisionId, doc, false);
}
int RocksDBGeoIndex::unload() {
// create a new, empty index
auto empty = GeoIndex_new(_objectId);

View File

@ -188,7 +188,7 @@ class RocksDBGeoIndex final : public RocksDBIndex {
/// @brief the actual geo index
GeoIdx* _geoIndex;
};
}
} // namespace arangodb
namespace std {
template <>
@ -200,6 +200,6 @@ class default_delete<GeoCoordinates> {
}
}
};
}
} // namespace std
#endif

View File

@ -746,21 +746,70 @@ int SlotRead(GeoIx * gix, int slot, GeoCoordinate * gc /*out param*/)
{
//gc GeoCoordinate, element in point array of real geo index
memcpy(gc,gix->gxc+slot,sizeof(GeoCoordinate));
return 0;
rocksdb::TransactionDB *db = rocksutils::globalRocksDB();
RocksDBKey key = RocksDBKey::GeoIndexValue(gix->objectId, true, slot);
RocksDBValue val = RocksDBValue::Empty(RocksDBEntryType::GeoIndexValue);
rocksdb::ReadOptions opts;
rocksdb::Status s = db->Get(opts, key.string(), val.buffer());
if (!s.ok()) {
arangodb::Result r = rocksutils::convertStatus(s, rocksutils::index);
THROW_ARANGO_EXCEPTION_MESSAGE(r.errorNumber(), r.errorMessage());
}
VpackToCoord(val.slice(), gc);
return 0;
}
void SlotWrite(GeoIx * gix,int slot, GeoCoordinate * gc)
{
memcpy(gix->gxc+slot,gc,sizeof(GeoCoordinate));
rocksdb::TransactionDB *db = rocksutils::globalRocksDB();
VPackBuilder serialized = CoordToVpack(gc);
RocksDBKey key = RocksDBKey::GeoIndexValue(gix->objectId, true, slot);
RocksDBValue val = RocksDBValue::Empty(RocksDBEntryType::GeoIndexValue);
rocksdb::WriteOptions opts;
rocksdb::Status s = db->Put(opts, key.string(), val.string());
if (!s.ok()) {
arangodb::Result r = rocksutils::convertStatus(s, rocksutils::index);
THROW_ARANGO_EXCEPTION_MESSAGE(r.errorNumber(), r.errorMessage());
}
}
int PotRead(GeoIx * gix, int pot, GeoPot * gp)
{
memcpy(gp,gix->ypots+pot,sizeof(GeoPot));
return 0;
rocksdb::TransactionDB *db = rocksutils::globalRocksDB();
RocksDBKey key = RocksDBKey::GeoIndexValue(gix->objectId, false, pot);
RocksDBValue val = RocksDBValue::Empty(RocksDBEntryType::GeoIndexValue);
rocksdb::ReadOptions opts;
rocksdb::Status s = db->Get(opts, key.string(), val.buffer());
if (!s.ok()) {
arangodb::Result r = rocksutils::convertStatus(s, rocksutils::index);
THROW_ARANGO_EXCEPTION_MESSAGE(r.errorNumber(), r.errorMessage());
}
VpackToPot(val.slice(), gp);
return 0;
}
void PotWrite(GeoIx * gix,int pot, GeoPot * gp)
{
void PotWrite(GeoIx * gix, int pot, GeoPot * gp) {
memcpy(gix->ypots+pot,gp,sizeof(GeoPot));
rocksdb::TransactionDB *db = rocksutils::globalRocksDB();
VPackBuilder serialized = PotToVpack(gp);
RocksDBKey key = RocksDBKey::GeoIndexValue(gix->objectId, false, pot);
RocksDBValue val = RocksDBValue::Document(serialized.slice());
rocksdb::WriteOptions opts;
rocksdb::Status s = db->Put(opts, key.string(), val.string());
if (!s.ok()) {
arangodb::Result r = rocksutils::convertStatus(s, rocksutils::index);
THROW_ARANGO_EXCEPTION_MESSAGE(r.errorNumber(), r.errorMessage());
}
}
/* =================================================== */

View File

@ -21,7 +21,6 @@
/// @author Jan Christoph Uhde
////////////////////////////////////////////////////////////////////////////////
// MUST BE ONLY INCLUDED IN RocksDBGeoIndexImpl.cpp after struct definitions!
// IT CAN NOT BE USED IN OTHER
// This file has only been added to keep Richards code clean. So it is easier
@ -36,85 +35,83 @@
#include <RocksDBEngine/RocksDBEngine.h>
#include <RocksDBEngine/RocksDBKey.h>
#include <velocypack/Iterator.h>
#include <velocypack/Builder.h>
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
namespace arangodb { namespace rocksdbengine {
namespace arangodb {
namespace rocksdbengine {
VPackBuilder CoordToVpack(GeoCoordinate* coord){
VPackBuilder CoordToVpack(GeoCoordinate* coord) {
VPackBuilder rv{};
rv.openArray();
rv.add(VPackValue(coord->latitude)); //double
rv.add(VPackValue(coord->longitude)); //double
rv.add(VPackValue(coord->data)); //uint64_t
rv.add(VPackValue(coord->latitude)); // double
rv.add(VPackValue(coord->longitude)); // double
rv.add(VPackValue(coord->data)); // uint64_t
rv.close();
return rv;
}
GeoCoordinate VpackToCoord(VPackSlice const& slice){
void VpackToCoord(VPackSlice const& slice, GeoCoordinate* gc) {
TRI_ASSERT(slice.isArray() && slice.length() == 3);
return GeoCoordinate{slice.at(0).getDouble()
,slice.at(1).getDouble()
,slice.at(2).getUInt()
};
gc->latitude = slice.at(0).getDouble();
gc->longitude = slice.at(1).getDouble();
gc->data = slice.at(2).getUInt();
}
VPackBuilder PotToVpack(GeoPot* pot){
VPackBuilder PotToVpack(GeoPot* pot) {
VPackBuilder rv{};
rv.openArray(); // open
rv.add(VPackValue(pot->LorLeaf)); // int
rv.add(VPackValue(pot->RorPoints)); // int
rv.add(VPackValue(pot->middle)); // GeoString
rv.openArray(); // open
rv.add(VPackValue(pot->LorLeaf)); // int
rv.add(VPackValue(pot->RorPoints)); // int
rv.add(VPackValue(pot->middle)); // GeoString
{
rv.openArray(); // array GeoFix //uint 16/32
for(std::size_t i = 0; i < GeoIndexFIXEDPOINTS; i++){
rv.add(VPackValue(pot->maxdist[i])); //unit 16/32
rv.openArray(); // array GeoFix //uint 16/32
for (std::size_t i = 0; i < GeoIndexFIXEDPOINTS; i++) {
rv.add(VPackValue(pot->maxdist[i])); // unit 16/32
}
rv.close(); // close array
rv.close(); // close array
}
rv.add(VPackValue(pot->start)); // GeoString
rv.add(VPackValue(pot->end)); // GeoString
rv.add(VPackValue(pot->level)); // int
rv.add(VPackValue(pot->start)); // GeoString
rv.add(VPackValue(pot->end)); // GeoString
rv.add(VPackValue(pot->level)); // int
{
rv.openArray(); // arrray of int
for(std::size_t i = 0; i < GeoIndexPOTSIZE; i++){
rv.openArray(); // arrray of int
for (std::size_t i = 0; i < GeoIndexPOTSIZE; i++) {
rv.add(VPackValue(pot->points[i])); // int
}
rv.close(); // close array
rv.close(); // close array
}
rv.close(); // close
rv.close(); // close
return rv;
}
GeoPot VpackToPot(VPackSlice const& slice){
GeoPot rv{};
void VpackToPot(VPackSlice const& slice, GeoPot* rv) {
TRI_ASSERT(slice.isArray());
rv.LorLeaf = (int) slice.at(0).getInt(); // int
rv.RorPoints = (int) slice.at(1).getInt(); // int
rv.middle = slice.at(2).getUInt(); // GeoString
rv->LorLeaf = (int)slice.at(0).getInt(); // int
rv->RorPoints = (int)slice.at(1).getInt(); // int
rv->middle = slice.at(2).getUInt(); // GeoString
{
auto maxdistSlice = slice.at(3);
TRI_ASSERT(maxdistSlice.isArray());
TRI_ASSERT(maxdistSlice.length() == GeoIndexFIXEDPOINTS);
for(std::size_t i = 0; i < GeoIndexFIXEDPOINTS; i++){
rv.maxdist[i] = (int) maxdistSlice.at(i).getUInt(); //unit 16/33
for (std::size_t i = 0; i < GeoIndexFIXEDPOINTS; i++) {
rv->maxdist[i] = (int)maxdistSlice.at(i).getUInt(); // unit 16/33
}
}
rv.start = (int) slice.at(4).getUInt(); // GeoString
rv.end = slice.at(5).getUInt(); // GeoString
rv.level = (int) slice.at(6).getInt(); // int
rv->start = (int)slice.at(4).getUInt(); // GeoString
rv->end = slice.at(5).getUInt(); // GeoString
rv->level = (int)slice.at(6).getInt(); // int
{
auto pointsSlice = slice.at(7);
TRI_ASSERT(pointsSlice.isArray());
TRI_ASSERT(pointsSlice.length() == GeoIndexFIXEDPOINTS);
for(std::size_t i = 0; i < GeoIndexPOTSIZE; i++){
rv.points[i] = (int) pointsSlice.at(i).getInt(); //int
for (std::size_t i = 0; i < GeoIndexPOTSIZE; i++) {
rv->points[i] = (int)pointsSlice.at(i).getInt(); // int
}
}
return rv;
}
}}
} // namespace rocksdbengine
} // namespace arangodb
#endif