]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/geo_db.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
12 #include "rocksdb/utilities/stackable_db.h"
13 #include "rocksdb/status.h"
18 // Configurable options needed for setting up a Geo database
21 // Backup info and error messages will be written to info_log
26 explicit GeoDBOptions(Logger
* _info_log
= nullptr):info_log(_info_log
) { }
30 // A position in the earth's geoid
37 explicit GeoPosition(double la
= 0, double lo
= 0) :
38 latitude(la
), longitude(lo
) {
43 // Description of an object on the Geoid. It is located by a GPS location,
44 // and is identified by the id. The value associated with this object is
45 // an opaque string 'value'. Different objects identified by unique id's
46 // can have the same gps-location associated with them.
56 GeoObject(const GeoPosition
& pos
, const std::string
& i
,
57 const std::string
& val
) :
58 position(pos
), id(i
), value(val
) {
64 GeoIterator() = default;
65 virtual ~GeoIterator() {}
66 virtual void Next() = 0;
67 virtual bool Valid() const = 0;
68 virtual const GeoObject
& geo_object() = 0;
69 virtual Status
status() const = 0;
73 // Stack your DB with GeoDB to be able to get geo-spatial support
75 class GeoDB
: public StackableDB
{
77 // GeoDBOptions have to be the same as the ones used in a previous
78 // incarnation of the DB
80 // GeoDB owns the pointer `DB* db` now. You should not delete it or
81 // use it after the invocation of GeoDB
82 // GeoDB(DB* db, const GeoDBOptions& options) : StackableDB(db) {}
83 GeoDB(DB
* db
, const GeoDBOptions
& /*options*/) : StackableDB(db
) {}
86 // Insert a new object into the location database. The object is
87 // uniquely identified by the id. If an object with the same id already
88 // exists in the db, then the old one is overwritten by the new
89 // object being inserted here.
90 virtual Status
Insert(const GeoObject
& object
) = 0;
92 // Retrieve the value of the object located at the specified GPS
93 // location and is identified by the 'id'.
94 virtual Status
GetByPosition(const GeoPosition
& pos
,
95 const Slice
& id
, std::string
* value
) = 0;
97 // Retrieve the value of the object identified by the 'id'. This method
98 // could be potentially slower than GetByPosition
99 virtual Status
GetById(const Slice
& id
, GeoObject
* object
) = 0;
101 // Delete the specified object
102 virtual Status
Remove(const Slice
& id
) = 0;
104 // Returns an iterator for the items within a circular radius from the
105 // specified gps location. If 'number_of_values' is specified,
106 // then the iterator is capped to that number of objects.
107 // The radius is specified in 'meters'.
108 virtual GeoIterator
* SearchRadial(const GeoPosition
& pos
,
110 int number_of_values
= INT_MAX
) = 0;
113 } // namespace rocksdb
114 #endif // ROCKSDB_LITE