Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
common.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef PLASMA_COMMON_H
19 #define PLASMA_COMMON_H
20 
21 #include <stddef.h>
22 
23 #include <cstring>
24 #include <memory>
25 #include <string>
26 // TODO(pcm): Convert getopt and sscanf in the store to use more idiomatic C++
27 // and get rid of the next three lines:
28 #ifndef __STDC_FORMAT_MACROS
29 #define __STDC_FORMAT_MACROS
30 #endif
31 #include <unordered_map>
32 
33 #include "plasma/compat.h"
34 
35 #include "arrow/status.h"
36 #include "arrow/util/logging.h"
37 #ifdef PLASMA_GPU
38 #include "arrow/gpu/cuda_api.h"
39 #endif
40 
41 namespace plasma {
42 
43 enum class ObjectLocation : int32_t { Local, Remote, Nonexistent };
44 
45 constexpr int64_t kUniqueIDSize = 20;
46 
47 class ARROW_EXPORT UniqueID {
48  public:
49  static UniqueID from_binary(const std::string& binary);
50  bool operator==(const UniqueID& rhs) const;
51  const uint8_t* data() const;
52  uint8_t* mutable_data();
53  std::string binary() const;
54  std::string hex() const;
55  size_t hash() const;
56  static int64_t size() { return kUniqueIDSize; }
57 
58  private:
59  uint8_t id_[kUniqueIDSize];
60 };
61 
62 static_assert(std::is_pod<UniqueID>::value, "UniqueID must be plain old data");
63 
64 typedef UniqueID ObjectID;
65 
67 constexpr int64_t kDigestSize = sizeof(uint64_t);
68 
69 enum class ObjectRequestType : int {
74 };
75 
77 struct ObjectRequest {
91 };
92 
93 enum class ObjectState : int {
95  PLASMA_CREATED = 1,
98 };
99 
104 
106 
108  int fd;
112  int64_t map_size;
114  ptrdiff_t offset;
116  uint8_t* pointer;
118  int64_t data_size;
120  int64_t metadata_size;
121 #ifdef PLASMA_GPU
122  std::shared_ptr<::arrow::gpu::CudaIpcMemHandle> ipc_handle;
124 #endif
125  int ref_count;
128  int64_t create_time;
131 
135  unsigned char digest[kDigestSize];
136 };
137 
139 typedef std::unordered_map<ObjectID, std::unique_ptr<ObjectTableEntry>> ObjectTable;
140 
144 struct PlasmaStoreInfo;
145 extern const PlasmaStoreInfo* plasma_config;
146 } // namespace plasma
147 
148 namespace std {
149 template <>
150 struct hash<::plasma::UniqueID> {
151  size_t operator()(const ::plasma::UniqueID& id) const { return id.hash(); }
152 };
153 } // namespace std
154 
155 #endif // PLASMA_COMMON_H
int64_t construct_duration
How long creation of this object took.
Definition: common.h:130
ObjectLocation location
Object location.
Definition: common.h:90
~ObjectTableEntry()
The plasma store information that is exposed to the eviction policy.
Definition: plasma.h:104
int device_num
Device number.
Definition: common.h:110
uint8_t * pointer
Pointer to the object data. Needed to free the object.
Definition: common.h:116
Definition: common.h:148
Object request data structure. Used for Wait.
Definition: common.h:77
UniqueID ObjectID
Definition: common.h:62
Definition: common.h:47
ObjectTableEntry()
ObjectID object_id
The ID of the requested object. If ID_NIL request any object.
Definition: common.h:79
unsigned char digest[kDigestSize]
The digest of the object. Used to see if two objects are the same.
Definition: common.h:135
char * binary
Definition: types.h:39
ObjectState
Definition: common.h:93
constexpr int64_t kDigestSize
Size of object hash digests.
Definition: common.h:67
ObjectRequestType type
Request associated to the object.
Definition: common.h:85
ObjectState state
The state of the object, e.g., whether it is open or sealed.
Definition: common.h:133
int fd
Memory mapped file containing the object.
Definition: common.h:108
static int64_t size()
Definition: common.h:56
int64_t map_size
Size of the underlying map.
Definition: common.h:112
int ref_count
Number of clients currently using this object.
Definition: common.h:126
Object was created but not sealed in the local Plasma Store.
size_t operator()(const ::plasma::UniqueID &id) const
Definition: common.h:151
Definition: client.h:35
int64_t metadata_size
Size of the object metadata in bytes.
Definition: common.h:120
ObjectLocation
Definition: common.h:43
Query for object in the local plasma store or in a remote plasma store.
bool operator==(const stl_allocator< T1 > &lhs, const stl_allocator< T2 > &rhs) noexcept
Definition: allocator.h:89
Object is sealed and stored in the local Plasma Store.
int64_t data_size
Size of the object in bytes.
Definition: common.h:118
constexpr int64_t kUniqueIDSize
Definition: common.h:45
std::unordered_map< ObjectID, std::unique_ptr< ObjectTableEntry > > ObjectTable
Mapping from ObjectIDs to information about the object.
Definition: common.h:139
Query for object in the local plasma store.
ptrdiff_t offset
Offset from the base of the mmap.
Definition: common.h:114
ObjectRequestType
Definition: common.h:69
const PlasmaStoreInfo * plasma_config
int64_t create_time
Unix epoch of when this object was created.
Definition: common.h:128
This type is used by the Plasma store.
Definition: common.h:102