Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
client.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_CLIENT_H
19 #define PLASMA_CLIENT_H
20 
21 #include <stdbool.h>
22 #include <time.h>
23 
24 #include <deque>
25 #include <memory>
26 #include <string>
27 #include <unordered_map>
28 
29 #include "arrow/buffer.h"
30 #include "arrow/status.h"
31 #include "arrow/util/visibility.h"
32 #include "plasma/common.h"
33 
34 using arrow::Status;
35 using arrow::Buffer;
36 
37 namespace plasma {
38 
39 #define PLASMA_DEFAULT_RELEASE_DELAY 64
40 
41 // Use 100MB as an overestimate of the L3 cache size.
42 constexpr int64_t kL3CacheSizeBytes = 100000000;
43 
45 struct ObjectBuffer {
47  std::shared_ptr<Buffer> data;
49  int64_t data_size;
51  std::shared_ptr<Buffer> metadata;
53  int64_t metadata_size;
56 };
57 
63  size_t release_delay;
64 };
65 
68  uint8_t* pointer;
70  size_t length;
73  int count;
74 };
75 
76 struct ObjectInUseEntry;
77 struct ObjectRequest;
78 struct PlasmaObject;
79 
80 class ARROW_EXPORT PlasmaClient {
81  public:
82  PlasmaClient();
83 
84  ~PlasmaClient();
85 
98  Status Connect(const std::string& store_socket_name,
99  const std::string& manager_socket_name, int release_delay,
100  int num_retries = -1);
101 
117  Status Create(const ObjectID& object_id, int64_t data_size, uint8_t* metadata,
118  int64_t metadata_size, std::shared_ptr<Buffer>* data);
134  Status Get(const ObjectID* object_ids, int64_t num_objects, int64_t timeout_ms,
135  ObjectBuffer* object_buffers);
136 
145  Status Release(const ObjectID& object_id);
146 
157  Status Contains(const ObjectID& object_id, bool* has_object);
158 
166  Status Abort(const ObjectID& object_id);
167 
174  Status Seal(const ObjectID& object_id);
175 
185  Status Delete(const ObjectID& object_id);
186 
194  Status Evict(int64_t num_bytes, int64_t& num_bytes_evicted);
195 
202  Status Hash(const ObjectID& object_id, uint8_t* digest);
203 
212  Status Subscribe(int* fd);
213 
221  Status GetNotification(int fd, ObjectID* object_id, int64_t* data_size,
222  int64_t* metadata_size);
223 
228  Status Disconnect();
229 
255  Status Fetch(int num_object_ids, const ObjectID* object_ids);
256 
288  Status Wait(int64_t num_object_requests, ObjectRequest* object_requests,
289  int num_ready_objects, int64_t timeout_ms, int* num_objects_ready);
290 
297  Status Transfer(const char* addr, int port, const ObjectID& object_id);
298 
315  Status Info(const ObjectID& object_id, int* object_status);
316 
321  int get_manager_fd() const;
322 
323  private:
328  Status UnmapObject(const ObjectID& object_id);
329 
332  Status FlushReleaseHistory();
333 
334  Status PerformRelease(const ObjectID& object_id);
335 
336  uint8_t* lookup_or_mmap(int fd, int store_fd_val, int64_t map_size);
337 
338  uint8_t* lookup_mmapped_file(int store_fd_val);
339 
340  void increment_object_count(const ObjectID& object_id, PlasmaObject* object,
341  bool is_sealed);
342 
344  int store_conn_;
346  int manager_conn_;
350  std::unordered_map<int, ClientMmapTableEntry> mmap_table_;
353  std::unordered_map<ObjectID, std::unique_ptr<ObjectInUseEntry>, UniqueIDHasher>
354  objects_in_use_;
360  std::deque<ObjectID> release_history_;
364  int64_t in_use_object_bytes_;
366  PlasmaClientConfig config_;
370  int64_t store_capacity_;
371 };
372 
373 } // namespace plasma
374 
375 #endif // PLASMA_CLIENT_H
Object buffer data structure.
Definition: client.h:45
Definition: client.h:66
Object request data structure. Used for Wait.
Definition: common.h:71
Definition: common.h:38
Definition: status.h:106
int64_t metadata_size
The metadata size in bytes.
Definition: client.h:53
Definition: plasma.h:78
int device_num
The device number.
Definition: client.h:55
std::shared_ptr< Buffer > data
The data buffer.
Definition: client.h:47
Configuration options for the plasma client.
Definition: client.h:59
uint8_t * pointer
The result of mmap for this file descriptor.
Definition: client.h:68
size_t length
The length of the memory-mapped file.
Definition: client.h:70
std::shared_ptr< Buffer > metadata
The metadata buffer.
Definition: client.h:51
Definition: client.h:37
Definition: common.h:54
int64_t data_size
The size in bytes of the data object.
Definition: client.h:49
object_status
Definition: plasma.h:98
Immutable API for a chunk of bytes which may or may not be owned by the class instance.
Definition: buffer.h:48
Definition: client.h:80
int count
The number of objects in this memory-mapped file that are currently being used by the client...
Definition: client.h:73
size_t release_delay
Number of release calls we wait until the object is actually released.
Definition: client.h:63
constexpr int64_t kL3CacheSizeBytes
Definition: client.h:42