Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
store.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_STORE_H
19 #define PLASMA_STORE_H
20 
21 #include <deque>
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 #include <unordered_set>
26 #include <vector>
27 
28 #include "plasma/common.h"
29 #include "plasma/events.h"
30 #include "plasma/eviction_policy.h"
31 #include "plasma/plasma.h"
32 #include "plasma/protocol.h"
33 
34 namespace plasma {
35 
36 using flatbuf::ObjectInfoT;
37 using flatbuf::PlasmaError;
38 
39 struct GetRequest;
40 
44  std::deque<std::unique_ptr<uint8_t[]>> object_notifications;
45 };
46 
48 struct Client {
49  explicit Client(int fd);
50 
52  int fd;
53 
55  std::unordered_set<ObjectID> object_ids;
56 
60 };
61 
62 class PlasmaStore {
63  public:
64  using NotificationMap = std::unordered_map<int, NotificationQueue>;
65 
66  // TODO: PascalCase PlasmaStore methods.
67  PlasmaStore(EventLoop* loop, int64_t system_memory, std::string directory,
68  bool hugetlbfs_enabled);
69 
70  ~PlasmaStore();
71 
74 
96  PlasmaError CreateObject(const ObjectID& object_id, int64_t data_size,
97  int64_t metadata_size, int device_num, Client* client,
98  PlasmaObject* result);
99 
107  int AbortObject(const ObjectID& object_id, Client* client);
108 
116  PlasmaError DeleteObject(ObjectID& object_id);
117 
122  void DeleteObjects(const std::vector<ObjectID>& object_ids);
123 
135  void ProcessGetRequest(Client* client, const std::vector<ObjectID>& object_ids,
136  int64_t timeout_ms);
137 
144  void SealObject(const ObjectID& object_id, unsigned char digest[]);
145 
151  ObjectStatus ContainsObject(const ObjectID& object_id);
152 
157  void ReleaseObject(const ObjectID& object_id, Client* client);
158 
162  void SubscribeToUpdates(Client* client);
163 
167  void ConnectClient(int listener_sock);
168 
172  void DisconnectClient(int client_fd);
173 
174  NotificationMap::iterator SendNotifications(NotificationMap::iterator it);
175 
176  Status ProcessMessage(Client* client);
177 
178  private:
179  void PushNotification(ObjectInfoT* object_notification);
180 
181  void PushNotification(ObjectInfoT* object_notification, int client_fd);
182 
183  void AddToClientObjectIds(const ObjectID& object_id, ObjectTableEntry* entry,
184  Client* client);
185 
189  void RemoveGetRequest(GetRequest* get_request);
190 
194  void RemoveGetRequestsForClient(Client* client);
195 
196  void ReturnFromGet(GetRequest* get_req);
197 
198  void UpdateObjectGetRequests(const ObjectID& object_id);
199 
200  int RemoveFromClientObjectIds(const ObjectID& object_id, ObjectTableEntry* entry,
201  Client* client);
202 
204  EventLoop* loop_;
207  PlasmaStoreInfo store_info_;
209  EvictionPolicy eviction_policy_;
212  std::vector<uint8_t> input_buffer_;
215  std::unordered_map<ObjectID, std::vector<GetRequest*>> object_get_requests_;
221  NotificationMap pending_notifications_;
222 
223  std::unordered_map<int, std::unique_ptr<Client>> connected_clients_;
224 
225  std::unordered_set<ObjectID> deletion_cache_;
226 #ifdef PLASMA_GPU
228 #endif
229 };
230 
231 } // namespace plasma
232 
233 #endif // PLASMA_STORE_H
void DisconnectClient(int client_fd)
Disconnect a client from the PlasmaStore.
The plasma store information that is exposed to the eviction policy.
Definition: plasma.h:104
void SealObject(const ObjectID &object_id, unsigned char digest[])
Seal an object.
void ProcessGetRequest(Client *client, const std::vector< ObjectID > &object_ids, int64_t timeout_ms)
Process a get request from a client.
PlasmaError DeleteObject(ObjectID &object_id)
Delete an specific object by object_id that have been created in the hash table.
Definition: common.h:47
PlasmaStore(EventLoop *loop, int64_t system_memory, std::string directory, bool hugetlbfs_enabled)
int notification_fd
The file descriptor used to push notifications to client.
Definition: store.h:59
PlasmaError CreateObject(const ObjectID &object_id, int64_t data_size, int64_t metadata_size, int device_num, Client *client, PlasmaObject *result)
Create a new object.
void ReleaseObject(const ObjectID &object_id, Client *client)
Record the fact that a particular client is no longer using an object.
Definition: status.h:95
ObjectStatus
Definition: plasma.h:96
std::unordered_set< ObjectID > object_ids
Object ids that are used by this client.
Definition: store.h:55
Definition: cuda_context.h:35
Definition: plasma.h:75
NotificationMap::iterator SendNotifications(NotificationMap::iterator it)
int AbortObject(const ObjectID &object_id, Client *client)
Abort a created but unsealed object.
std::unordered_map< int, NotificationQueue > NotificationMap
Definition: store.h:64
int fd
The file descriptor used to communicate with the client.
Definition: store.h:52
void ConnectClient(int listener_sock)
Connect a new client to the PlasmaStore.
Definition: store.h:62
Definition: store.h:41
Contains all information that is associated with a Plasma store client.
Definition: store.h:48
std::deque< std::unique_ptr< uint8_t[]> > object_notifications
The object notifications for clients.
Definition: store.h:44
Definition: events.h:42
void SubscribeToUpdates(Client *client)
Subscribe a file descriptor to updates about new sealed objects.
Definition: client.h:35
Status ProcessMessage(Client *client)
ObjectStatus ContainsObject(const ObjectID &object_id)
Check if the plasma store contains an object:
const PlasmaStoreInfo * GetPlasmaStoreInfo()
Get a const pointer to the internal PlasmaStoreInfo object.
The eviction policy.
Definition: eviction_policy.h:59
void DeleteObjects(const std::vector< ObjectID > &object_ids)
Delete objects that have been created in the hash table.
This type is used by the Plasma store.
Definition: common.h:102