Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
plasma.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_PLASMA_H
19 #define PLASMA_PLASMA_H
20 
21 #include <errno.h>
22 #include <inttypes.h>
23 #include <stdbool.h>
24 #include <stddef.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h> // pid_t
29 
30 #include <memory>
31 #include <string>
32 #include <unordered_map>
33 #include <unordered_set>
34 
35 #include "plasma/compat.h"
36 
37 #include "arrow/status.h"
38 #include "arrow/util/logging.h"
39 #include "arrow/util/macros.h"
40 #include "plasma/common.h"
41 #include "plasma/common_generated.h"
42 
43 #ifdef PLASMA_GPU
44 #include "arrow/gpu/cuda_api.h"
45 
47 #endif
48 
49 namespace plasma {
50 
51 #define HANDLE_SIGPIPE(s, fd_) \
52  do { \
53  Status _s = (s); \
54  if (!_s.ok()) { \
55  if (errno == EPIPE || errno == EBADF || errno == ECONNRESET) { \
56  ARROW_LOG(WARNING) \
57  << "Received SIGPIPE, BAD FILE DESCRIPTOR, or ECONNRESET when " \
58  "sending a message to client on fd " \
59  << fd_ \
60  << ". " \
61  "The client on the other end may have hung up."; \
62  } else { \
63  return _s; \
64  } \
65  } \
66  } while (0);
67 
69 constexpr int64_t kBlockSize = 64;
70 
71 struct Client;
72 
74 typedef std::unordered_map<ObjectID, ObjectRequest, UniqueIDHasher> ObjectRequestMap;
75 
76 // TODO(pcm): Replace this by the flatbuffers message PlasmaObjectSpec.
77 struct PlasmaObject {
78 #ifdef PLASMA_GPU
79  // IPC handle for Cuda.
80  std::shared_ptr<CudaIpcMemHandle> ipc_handle;
81 #endif
82  int store_fd;
87  ptrdiff_t data_offset;
89  ptrdiff_t metadata_offset;
91  int64_t data_size;
93  int64_t metadata_size;
96 };
97 
103 };
104 
110 };
111 
116 
118 
122  ObjectInfoT info;
124  int fd;
128  int64_t map_size;
130  ptrdiff_t offset;
132  uint8_t* pointer;
133 #ifdef PLASMA_GPU
134  std::shared_ptr<CudaIpcMemHandle> ipc_handle;
136 #endif
137  int ref_count;
139 
143  unsigned char digest[kDigestSize];
144 };
145 
149  std::unordered_map<ObjectID, std::unique_ptr<ObjectTableEntry>, UniqueIDHasher> objects;
159  std::string directory;
160 };
161 
170  const ObjectID& object_id);
171 
186 int warn_if_sigpipe(int status, int client_sock);
187 
188 std::unique_ptr<uint8_t[]> create_object_info_buffer(ObjectInfoT* object_info);
189 
190 } // namespace plasma
191 
192 #endif // PLASMA_PLASMA_H
int64_t data_size
The size in bytes of the data.
Definition: plasma.h:91
int store_fd
The file descriptor of the memory mapped file in the store.
Definition: plasma.h:85
~ObjectTableEntry()
The plasma store information that is exposed to the eviction policy.
Definition: plasma.h:147
std::unordered_map< ObjectID, ObjectRequest, UniqueIDHasher > ObjectRequestMap
Mapping from object IDs to type and status of the request.
Definition: plasma.h:71
object_state state
The state of the object, e.g., whether it is open or sealed.
Definition: plasma.h:141
Object was created but not sealed in the local Plasma Store.
Definition: plasma.h:100
int warn_if_sigpipe(int status, int client_sock)
Print a warning if the status is less than zero.
int64_t memory_capacity
The amount of memory (in bytes) that we allow to be allocated in the store.
Definition: plasma.h:152
The object was found.
Definition: plasma.h:109
int device_num
Device number.
Definition: plasma.h:126
uint8_t * pointer
Pointer to the object data. Needed to free the object.
Definition: plasma.h:132
object_state
Definition: plasma.h:98
Definition: common.h:38
Object is sealed and stored in the local Plasma Store.
Definition: plasma.h:102
ObjectTableEntry()
unsigned char digest[kDigestSize]
The digest of the object. Used to see if two objects are the same.
Definition: plasma.h:143
ptrdiff_t metadata_offset
The offset in bytes in the memory mapped file of the metadata.
Definition: plasma.h:89
int64_t metadata_size
The size in bytes of the metadata.
Definition: plasma.h:93
ObjectInfoT info
Object info like size, creation time and owner.
Definition: plasma.h:122
constexpr int64_t kDigestSize
Size of object hash digests.
Definition: common.h:68
Definition: plasma.h:77
Definition: cuda_memory.h:98
Contains all information that is associated with a Plasma store client.
Definition: store.h:45
int fd
Memory mapped file containing the object.
Definition: plasma.h:124
The object was not found.
Definition: plasma.h:107
int64_t map_size
Size of the underlying map.
Definition: plasma.h:128
int ref_count
Number of clients currently using this object.
Definition: plasma.h:138
Definition: client.h:35
Definition: common.h:54
ObjectID object_id
Object id of this object.
Definition: plasma.h:120
std::unordered_map< ObjectID, std::unique_ptr< ObjectTableEntry >, UniqueIDHasher > objects
Objects that are in the Plasma store.
Definition: plasma.h:149
std::string directory
A (platform-dependent) directory where to create the memory-backed file.
Definition: plasma.h:159
ObjectTableEntry * get_object_table_entry(PlasmaStoreInfo *store_info, const ObjectID &object_id)
Get an entry from the object table and return NULL if the object_id is not present.
ptrdiff_t data_offset
The offset in bytes in the memory mapped file of the data.
Definition: plasma.h:87
object_status
Definition: plasma.h:105
std::unique_ptr< uint8_t[]> create_object_info_buffer(ObjectInfoT *object_info)
ptrdiff_t offset
Offset from the base of the mmap.
Definition: plasma.h:130
bool hugepages_enabled
Boolean flag indicating whether to start the object store with hugepages support enabled.
Definition: plasma.h:157
int device_num
Device number object is on.
Definition: plasma.h:95
constexpr int64_t kBlockSize
Allocation granularity used in plasma for object allocation.
Definition: plasma.h:69
This type is used by the Plasma store.
Definition: plasma.h:114