YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/geo_db.h
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#ifndef ROCKSDB_LITE
22
#pragma once
23
#include <string>
24
#include <vector>
25
26
#include "yb/rocksdb/utilities/stackable_db.h"
27
#include "yb/rocksdb/status.h"
28
29
namespace rocksdb {
30
31
//
32
// Configurable options needed for setting up a Geo database
33
//
34
struct GeoDBOptions {
35
  // Backup info and error messages will be written to info_log
36
  // if non-nullptr.
37
  // Default: nullptr
38
  Logger* info_log;
39
40
  explicit GeoDBOptions(Logger* _info_log = nullptr):info_log(_info_log) { }
41
};
42
43
//
44
// A position in the earth's geoid
45
//
46
class GeoPosition {
47
 public:
48
  double latitude;
49
  double longitude;
50
51
  explicit GeoPosition(double la = 0, double lo = 0) :
52
23
    latitude(la), longitude(lo) {
53
23
  }
54
};
55
56
//
57
// Description of an object on the Geoid. It is located by a GPS location,
58
// and is identified by the id. The value associated with this object is
59
// an opaque string 'value'. Different objects identified by unique id's
60
// can have the same gps-location associated with them.
61
//
62
class GeoObject {
63
 public:
64
  GeoPosition position;
65
  std::string id;
66
  std::string value;
67
68
5
  GeoObject() {}
69
70
  GeoObject(const GeoPosition& pos, const std::string& i,
71
            const std::string& val) :
72
4
    position(pos), id(i), value(val) {
73
4
  }
74
};
75
76
class GeoIterator {
77
 public:
78
2
  GeoIterator() = default;
79
2
  virtual ~GeoIterator() {}
80
  virtual void Next() = 0;
81
  virtual bool Valid() const = 0;
82
  virtual const GeoObject& geo_object() = 0;
83
  virtual Status status() const = 0;
84
};
85
86
//
87
// Stack your DB with GeoDB to be able to get geo-spatial support
88
//
89
class GeoDB : public StackableDB {
90
 public:
91
  // GeoDBOptions have to be the same as the ones used in a previous
92
  // incarnation of the DB
93
  //
94
  // GeoDB owns the pointer `DB* db` now. You should not delete it or
95
  // use it after the invocation of GeoDB
96
  // GeoDB(DB* db, const GeoDBOptions& options) : StackableDB(db) {}
97
2
  GeoDB(DB* db, const GeoDBOptions& options) : StackableDB(db) {}
98
2
  virtual ~GeoDB() {}
99
100
  // Insert a new object into the location database. The object is
101
  // uniquely identified by the id. If an object with the same id already
102
  // exists in the db, then the old one is overwritten by the new
103
  // object being inserted here.
104
  virtual Status Insert(const GeoObject& object) = 0;
105
106
  // Retrieve the value of the object located at the specified GPS
107
  // location and is identified by the 'id'.
108
  virtual Status GetByPosition(const GeoPosition& pos,
109
                               const Slice& id, std::string* value) = 0;
110
111
  // Retrieve the value of the object identified by the 'id'. This method
112
  // could be potentially slower than GetByPosition
113
  virtual Status GetById(const Slice& id, GeoObject*  object) = 0;
114
115
  // Delete the specified object
116
  virtual Status Remove(const Slice& id) = 0;
117
118
  // Returns an iterator for the items within a circular radius from the
119
  // specified gps location. If 'number_of_values' is specified,
120
  // then the iterator is capped to that number of objects.
121
  // The radius is specified in 'meters'.
122
  virtual GeoIterator* SearchRadial(const GeoPosition& pos,
123
                                    double radius,
124
                                    int number_of_values = INT_MAX) = 0;
125
};
126
127
}  // namespace rocksdb
128
#endif  // ROCKSDB_LITE