]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/plasma/plasma.h
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
27 #include <unistd.h> // pid_t
31 #include <unordered_map>
32 #include <unordered_set>
35 #include "plasma/compat.h"
37 #include "arrow/status.h"
38 #include "arrow/util/logging.h"
39 #include "arrow/util/macros.h"
40 #include "plasma/common.h"
43 using arrow::cuda::CudaIpcMemHandle
;
50 } // namespace flatbuf
52 #define HANDLE_SIGPIPE(s, fd_) \
56 if (errno == EPIPE || errno == EBADF || errno == ECONNRESET) { \
58 << "Received SIGPIPE, BAD FILE DESCRIPTOR, or ECONNRESET when " \
59 "sending a message to client on fd " \
62 "The client on the other end may have hung up."; \
69 /// Allocation granularity used in plasma for object allocation.
70 constexpr int64_t kBlockSize
= 64;
72 /// Contains all information that is associated with a Plasma store client.
74 explicit Client(int fd
);
76 /// The file descriptor used to communicate with the client.
79 /// Object ids that are used by this client.
80 std::unordered_set
<ObjectID
> object_ids
;
82 /// File descriptors that are used by this client.
83 std::unordered_set
<int> used_fds
;
85 /// The file descriptor used to push notifications to client. This is only valid
86 /// if client subscribes to plasma store. -1 indicates invalid.
89 std::string name
= "anonymous_client";
92 // TODO(pcm): Replace this by the flatbuffers message PlasmaObjectSpec.
95 // IPC handle for Cuda.
96 std::shared_ptr
<CudaIpcMemHandle
> ipc_handle
;
98 /// The file descriptor of the memory mapped file in the store. It is used as
99 /// a unique identifier of the file in the client to look up the corresponding
100 /// file descriptor on the client's side.
102 /// The offset in bytes in the memory mapped file of the data.
103 ptrdiff_t data_offset
;
104 /// The offset in bytes in the memory mapped file of the metadata.
105 ptrdiff_t metadata_offset
;
106 /// The size in bytes of the data.
108 /// The size in bytes of the metadata.
109 int64_t metadata_size
;
110 /// Device number object is on.
113 bool operator==(const PlasmaObject
& other
) const {
116 (ipc_handle
== other
.ipc_handle
) &&
118 (store_fd
== other
.store_fd
) && (data_offset
== other
.data_offset
) &&
119 (metadata_offset
== other
.metadata_offset
) && (data_size
== other
.data_size
) &&
120 (metadata_size
== other
.metadata_size
) && (device_num
== other
.device_num
));
124 enum class ObjectStatus
: int {
125 /// The object was not found.
126 OBJECT_NOT_FOUND
= 0,
127 /// The object was found.
131 /// The plasma store information that is exposed to the eviction policy.
132 struct PlasmaStoreInfo
{
133 /// Objects that are in the Plasma store.
135 /// Boolean flag indicating whether to start the object store with hugepages
136 /// support enabled. Huge pages are substantially larger than normal memory
137 /// pages (e.g. 2MB or 1GB instead of 4KB) and using them can reduce
138 /// bookkeeping overhead from the OS.
139 bool hugepages_enabled
;
140 /// A (platform-dependent) directory where to create the memory-backed file.
141 std::string directory
;
144 /// Get an entry from the object table and return NULL if the object_id
147 /// \param store_info The PlasmaStoreInfo that contains the object table.
148 /// \param object_id The object_id of the entry we are looking for.
149 /// \return The entry associated with the object_id or NULL if the object_id
151 ObjectTableEntry
* GetObjectTableEntry(PlasmaStoreInfo
* store_info
,
152 const ObjectID
& object_id
);
154 /// Print a warning if the status is less than zero. This should be used to check
155 /// the success of messages sent to plasma clients. We print a warning instead of
156 /// failing because the plasma clients are allowed to die. This is used to handle
157 /// situations where the store writes to a client file descriptor, and the client
158 /// may already have disconnected. If we have processed the disconnection and
159 /// closed the file descriptor, we should get a BAD FILE DESCRIPTOR error. If we
160 /// have not, then we should get a SIGPIPE. If we write to a TCP socket that
161 /// isn't connected yet, then we should get an ECONNRESET.
163 /// \param status The status to check. If it is less less than zero, we will
165 /// \param client_sock The client socket. This is just used to print some extra
167 /// \return The errno set.
168 int WarnIfSigpipe(int status
, int client_sock
);
170 std::unique_ptr
<uint8_t[]> CreateObjectInfoBuffer(flatbuf::ObjectInfoT
* object_info
);
172 std::unique_ptr
<uint8_t[]> CreatePlasmaNotificationBuffer(
173 std::vector
<flatbuf::ObjectInfoT
>& object_info
);
175 } // namespace plasma