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
25 // TODO(pcm): Convert getopt and sscanf in the store to use more idiomatic C++
26 // and get rid of the next three lines:
27 #ifndef __STDC_FORMAT_MACROS
28 #define __STDC_FORMAT_MACROS
30 #include <unordered_map>
32 #include "plasma/compat.h"
34 #include "arrow/status.h"
36 #include "arrow/gpu/cuda_api.h"
41 enum class ObjectLocation
: int32_t { Local
, Remote
, NotFound
};
43 enum class PlasmaErrorCode
: int8_t {
44 PlasmaObjectExists
= 1,
45 PlasmaObjectNotFound
= 2,
47 PlasmaObjectAlreadySealed
= 4,
50 ARROW_EXPORT
arrow::Status
MakePlasmaError(PlasmaErrorCode code
, std::string message
);
51 /// Return true iff the status indicates an already existing Plasma object.
52 ARROW_EXPORT
bool IsPlasmaObjectExists(const arrow::Status
& status
);
53 /// Return true iff the status indicates a nonexistent Plasma object.
54 ARROW_EXPORT
bool IsPlasmaObjectNotFound(const arrow::Status
& status
);
55 /// Return true iff the status indicates an already sealed Plasma object.
56 ARROW_EXPORT
bool IsPlasmaObjectAlreadySealed(const arrow::Status
& status
);
57 /// Return true iff the status indicates the Plasma store reached its capacity limit.
58 ARROW_EXPORT
bool IsPlasmaStoreFull(const arrow::Status
& status
);
60 constexpr int64_t kUniqueIDSize
= 20;
62 class ARROW_EXPORT UniqueID
{
64 static UniqueID
from_binary(const std::string
& binary
);
65 bool operator==(const UniqueID
& rhs
) const;
66 const uint8_t* data() const;
67 uint8_t* mutable_data();
68 std::string
binary() const;
69 std::string
hex() const;
71 static int64_t size() { return kUniqueIDSize
; }
74 uint8_t id_
[kUniqueIDSize
];
77 static_assert(std::is_pod
<UniqueID
>::value
, "UniqueID must be plain old data");
79 typedef UniqueID ObjectID
;
81 /// Size of object hash digests.
82 constexpr int64_t kDigestSize
= sizeof(uint64_t);
84 enum class ObjectState
: int {
85 /// Object was created but not sealed in the local Plasma Store.
87 /// Object is sealed and stored in the local Plasma Store.
89 /// Object is evicted to external store.
95 struct CudaIpcPlaceholder
{};
97 } // namespace internal
99 /// This type is used by the Plasma store. It is here because it is exposed to
100 /// the eviction policy.
101 struct ObjectTableEntry
{
106 /// Memory mapped file containing the object.
110 /// Size of the underlying map.
112 /// Offset from the base of the mmap.
114 /// Pointer to the object data. Needed to free the object.
116 /// Size of the object in bytes.
118 /// Size of the object metadata in bytes.
119 int64_t metadata_size
;
120 /// Number of clients currently using this object.
122 /// Unix epoch of when this object was created.
124 /// How long creation of this object took.
125 int64_t construct_duration
;
127 /// The state of the object, e.g., whether it is open or sealed.
129 /// The digest of the object. Used to see if two objects are the same.
130 unsigned char digest
[kDigestSize
];
133 /// IPC GPU handle to share with clients.
134 std::shared_ptr
<::arrow::cuda::CudaIpcMemHandle
> ipc_handle
;
136 std::shared_ptr
<internal::CudaIpcPlaceholder
> ipc_handle
;
140 /// Mapping from ObjectIDs to information about the object.
141 typedef std::unordered_map
<ObjectID
, std::unique_ptr
<ObjectTableEntry
>> ObjectTable
;
143 /// Globally accessible reference to plasma store configuration.
144 /// TODO(pcm): This can be avoided with some refactoring of existing code
145 /// by making it possible to pass a context object through dlmalloc.
146 struct PlasmaStoreInfo
;
147 extern const PlasmaStoreInfo
* plasma_config
;
148 } // namespace plasma
152 struct hash
<::plasma::UniqueID
> {
153 size_t operator()(const ::plasma::UniqueID
& id
) const { return id
.hash(); }