1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# cython: profile=False
# distutils: language = c++
# cython: language_level = 3
from libcpp cimport bool as c_bool, nullptr
from libcpp.memory cimport shared_ptr, unique_ptr, make_shared
from libcpp.string cimport string as c_string
from libcpp.vector cimport vector as c_vector
from libcpp.unordered_map cimport unordered_map
from libc.stdint cimport int64_t, uint8_t, uintptr_t
from cython.operator cimport dereference as deref, preincrement as inc
from cpython.pycapsule cimport *
from collections.abc import Sequence
import random
import socket
import warnings
import pyarrow
from pyarrow.lib cimport (Buffer, NativeFile, _Weakrefable,
check_status, pyarrow_wrap_buffer)
from pyarrow.lib import ArrowException, frombytes
from pyarrow.includes.libarrow cimport (CBuffer, CMutableBuffer,
CFixedSizeBufferWriter, CStatus)
from pyarrow.includes.libplasma cimport *
PLASMA_WAIT_TIMEOUT = 2 ** 30
cdef extern from "plasma/common.h" nogil:
cdef cppclass CCudaIpcPlaceholder" plasma::internal::CudaIpcPlaceholder":
pass
cdef cppclass CUniqueID" plasma::UniqueID":
@staticmethod
CUniqueID from_binary(const c_string& binary)
@staticmethod
CUniqueID from_random()
c_bool operator==(const CUniqueID& rhs) const
c_string hex() const
c_string binary() const
@staticmethod
int64_t size()
cdef enum CObjectState" plasma::ObjectState":
PLASMA_CREATED" plasma::ObjectState::PLASMA_CREATED"
PLASMA_SEALED" plasma::ObjectState::PLASMA_SEALED"
cdef struct CObjectTableEntry" plasma::ObjectTableEntry":
int fd
int device_num
int64_t map_size
ptrdiff_t offset
uint8_t* pointer
int64_t data_size
int64_t metadata_size
int ref_count
int64_t create_time
int64_t construct_duration
CObjectState state
shared_ptr[CCudaIpcPlaceholder] ipc_handle
ctypedef unordered_map[CUniqueID, unique_ptr[CObjectTableEntry]] \
CObjectTable" plasma::ObjectTable"
cdef extern from "plasma/common.h":
cdef int64_t kDigestSize" plasma::kDigestSize"
cdef extern from "plasma/client.h" nogil:
cdef cppclass CPlasmaClient" plasma::PlasmaClient":
CPlasmaClient()
CStatus Connect(const c_string& store_socket_name,
const c_string& manager_socket_name,
int release_delay, int num_retries)
CStatus Create(const CUniqueID& object_id,
int64_t data_size, const uint8_t* metadata, int64_t
metadata_size, const shared_ptr[CBuffer]* data)
CStatus CreateAndSeal(const CUniqueID& object_id,
const c_string& data, const c_string& metadata)
CStatus Get(const c_vector[CUniqueID] object_ids, int64_t timeout_ms,
c_vector[CObjectBuffer]* object_buffers)
CStatus Seal(const CUniqueID& object_id)
CStatus Evict(int64_t num_bytes, int64_t& num_bytes_evicted)
CStatus Hash(const CUniqueID& object_id, uint8_t* digest)
CStatus Release(const CUniqueID& object_id)
CStatus Contains(const CUniqueID& object_id, c_bool* has_object)
CStatus List(CObjectTable* objects)
CStatus Subscribe(int* fd)
CStatus DecodeNotifications(const uint8_t* buffer,
c_vector[CUniqueID]* object_ids,
c_vector[int64_t]* data_sizes,
c_vector[int64_t]* metadata_sizes)
CStatus GetNotification(int fd, CUniqueID* object_id,
int64_t* data_size, int64_t* metadata_size)
CStatus Disconnect()
CStatus Delete(const c_vector[CUniqueID] object_ids)
CStatus SetClientOptions(const c_string& client_name,
int64_t limit_output_memory)
c_string DebugString()
int64_t store_capacity()
cdef extern from "plasma/client.h" nogil:
cdef struct CObjectBuffer" plasma::ObjectBuffer":
shared_ptr[CBuffer] data
shared_ptr[CBuffer] metadata
def make_object_id(object_id):
return ObjectID(object_id)
cdef class ObjectID(_Weakrefable):
"""
An ObjectID represents a string of bytes used to identify Plasma objects.
"""
cdef:
CUniqueID data
def __cinit__(self, object_id):
if (not isinstance(object_id, bytes) or
len(object_id) != CUniqueID.size()):
raise ValueError("Object ID must by 20 bytes,"
" is " + str(object_id))
self.data = CUniqueID.from_binary(object_id)
def __eq__(self, other):
try:
return self.data == (<ObjectID?>other).data
except TypeError:
return False
def __hash__(self):
return hash(self.data.binary())
def __repr__(self):
return "ObjectID(" + self.data.hex().decode() + ")"
def __reduce__(self):
return (make_object_id, (self.data.binary(),))
def binary(self):
"""
Return the binary representation of this ObjectID.
Returns
-------
bytes
Binary representation of the ObjectID.
"""
return self.data.binary()
@staticmethod
def from_random():
"""
Returns a randomly generated ObjectID.
Returns
-------
ObjectID
A randomly generated ObjectID.
"""
random_id = bytes(bytearray(
random.getrandbits(8) for _ in range(CUniqueID.size())))
return ObjectID(random_id)
cdef class ObjectNotAvailable(_Weakrefable):
"""
Placeholder for an object that was not available within the given timeout.
"""
pass
cdef class PlasmaBuffer(Buffer):
"""
This is the type returned by calls to get with a PlasmaClient.
We define our own class instead of directly returning a buffer object so
that we can add a custom destructor which notifies Plasma that the object
is no longer being used, so the memory in the Plasma store backing the
object can potentially be freed.
Attributes
----------
object_id : ObjectID
The ID of the object in the buffer.
client : PlasmaClient
The PlasmaClient that we use to communicate with the store and manager.
"""
cdef:
ObjectID object_id
PlasmaClient client
@staticmethod
cdef PlasmaBuffer create(ObjectID object_id, PlasmaClient client,
const shared_ptr[CBuffer]& buffer):
cdef PlasmaBuffer self = PlasmaBuffer.__new__(PlasmaBuffer)
self.object_id = object_id
self.client = client
self.init(buffer)
return self
def __init__(self):
raise TypeError("Do not call PlasmaBuffer's constructor directly, use "
"`PlasmaClient.create` instead.")
def __dealloc__(self):
"""
Notify Plasma that the object is no longer needed.
If the plasma client has been shut down, then don't do anything.
"""
self.client._release(self.object_id)
class PlasmaObjectNotFound(ArrowException):
pass
class PlasmaStoreFull(ArrowException):
pass
class PlasmaObjectExists(ArrowException):
pass
cdef int plasma_check_status(const CStatus& status) nogil except -1:
if status.ok():
return 0
with gil:
message = frombytes(status.message())
if IsPlasmaObjectExists(status):
raise PlasmaObjectExists(message)
elif IsPlasmaObjectNotFound(status):
raise PlasmaObjectNotFound(message)
elif IsPlasmaStoreFull(status):
raise PlasmaStoreFull(message)
return check_status(status)
def get_socket_from_fd(fileno, family, type):
import socket
return socket.socket(fileno=fileno, family=family, type=type)
cdef class PlasmaClient(_Weakrefable):
"""
The PlasmaClient is used to interface with a plasma store and manager.
The PlasmaClient can ask the PlasmaStore to allocate a new buffer, seal a
buffer, and get a buffer. Buffers are referred to by object IDs, which are
strings.
"""
cdef:
shared_ptr[CPlasmaClient] client
int notification_fd
c_string store_socket_name
def __cinit__(self):
self.client.reset(new CPlasmaClient())
self.notification_fd = -1
self.store_socket_name = b""
cdef _get_object_buffers(self, object_ids, int64_t timeout_ms,
c_vector[CObjectBuffer]* result):
cdef:
c_vector[CUniqueID] ids
ObjectID object_id
for object_id in object_ids:
ids.push_back(object_id.data)
with nogil:
plasma_check_status(self.client.get().Get(ids, timeout_ms, result))
# XXX C++ API should instead expose some kind of CreateAuto()
cdef _make_mutable_plasma_buffer(self, ObjectID object_id, uint8_t* data,
int64_t size):
cdef shared_ptr[CBuffer] buffer
buffer.reset(new CMutableBuffer(data, size))
return PlasmaBuffer.create(object_id, self, buffer)
@property
def store_socket_name(self):
return self.store_socket_name.decode()
def create(self, ObjectID object_id, int64_t data_size,
c_string metadata=b""):
"""
Create a new buffer in the PlasmaStore for a particular object ID.
The returned buffer is mutable until seal is called.
Parameters
----------
object_id : ObjectID
The object ID used to identify an object.
size : int
The size in bytes of the created buffer.
metadata : bytes
An optional string of bytes encoding whatever metadata the user
wishes to encode.
Raises
------
PlasmaObjectExists
This exception is raised if the object could not be created because
there already is an object with the same ID in the plasma store.
PlasmaStoreFull: This exception is raised if the object could
not be created because the plasma store is unable to evict
enough objects to create room for it.
"""
cdef shared_ptr[CBuffer] data
with nogil:
plasma_check_status(
self.client.get().Create(object_id.data, data_size,
<uint8_t*>(metadata.data()),
metadata.size(), &data))
return self._make_mutable_plasma_buffer(object_id,
data.get().mutable_data(),
data_size)
def create_and_seal(self, ObjectID object_id, c_string data,
c_string metadata=b""):
"""
Store a new object in the PlasmaStore for a particular object ID.
Parameters
----------
object_id : ObjectID
The object ID used to identify an object.
data : bytes
The object to store.
metadata : bytes
An optional string of bytes encoding whatever metadata the user
wishes to encode.
Raises
------
PlasmaObjectExists
This exception is raised if the object could not be created because
there already is an object with the same ID in the plasma store.
PlasmaStoreFull: This exception is raised if the object could
not be created because the plasma store is unable to evict
enough objects to create room for it.
"""
with nogil:
plasma_check_status(
self.client.get().CreateAndSeal(object_id.data, data,
metadata))
def get_buffers(self, object_ids, timeout_ms=-1, with_meta=False):
"""
Returns data buffer from the PlasmaStore based on object ID.
If the object has not been sealed yet, this call will block. The
retrieved buffer is immutable.
Parameters
----------
object_ids : list
A list of ObjectIDs used to identify some objects.
timeout_ms : int
The number of milliseconds that the get call should block before
timing out and returning. Pass -1 if the call should block and 0
if the call should return immediately.
with_meta : bool
Returns
-------
list
If with_meta=False, this is a list of PlasmaBuffers for the data
associated with the object_ids and None if the object was not
available. If with_meta=True, this is a list of tuples of
PlasmaBuffer and metadata bytes.
"""
cdef c_vector[CObjectBuffer] object_buffers
self._get_object_buffers(object_ids, timeout_ms, &object_buffers)
result = []
for i in range(object_buffers.size()):
if object_buffers[i].data.get() != nullptr:
data = pyarrow_wrap_buffer(object_buffers[i].data)
else:
data = None
if not with_meta:
result.append(data)
else:
if object_buffers[i].metadata.get() != nullptr:
size = object_buffers[i].metadata.get().size()
metadata = object_buffers[i].metadata.get().data()[:size]
else:
metadata = None
result.append((metadata, data))
return result
def get_metadata(self, object_ids, timeout_ms=-1):
"""
Returns metadata buffer from the PlasmaStore based on object ID.
If the object has not been sealed yet, this call will block. The
retrieved buffer is immutable.
Parameters
----------
object_ids : list
A list of ObjectIDs used to identify some objects.
timeout_ms : int
The number of milliseconds that the get call should block before
timing out and returning. Pass -1 if the call should block and 0
if the call should return immediately.
Returns
-------
list
List of PlasmaBuffers for the metadata associated with the
object_ids and None if the object was not available.
"""
cdef c_vector[CObjectBuffer] object_buffers
self._get_object_buffers(object_ids, timeout_ms, &object_buffers)
result = []
for i in range(object_buffers.size()):
if object_buffers[i].metadata.get() != nullptr:
result.append(pyarrow_wrap_buffer(object_buffers[i].metadata))
else:
result.append(None)
return result
def put_raw_buffer(self, object value, ObjectID object_id=None,
c_string metadata=b"", int memcopy_threads=6):
"""
Store Python buffer into the object store.
Parameters
----------
value : Python object that implements the buffer protocol
A Python buffer object to store.
object_id : ObjectID, default None
If this is provided, the specified object ID will be used to refer
to the object.
metadata : bytes
An optional string of bytes encoding whatever metadata the user
wishes to encode.
memcopy_threads : int, default 6
The number of threads to use to write the serialized object into
the object store for large objects.
Returns
-------
The object ID associated to the Python buffer object.
"""
cdef ObjectID target_id = (object_id if object_id
else ObjectID.from_random())
cdef Buffer arrow_buffer = pyarrow.py_buffer(value)
write_buffer = self.create(target_id, len(value), metadata)
stream = pyarrow.FixedSizeBufferWriter(write_buffer)
stream.set_memcopy_threads(memcopy_threads)
stream.write(arrow_buffer)
self.seal(target_id)
return target_id
def put(self, object value, ObjectID object_id=None, int memcopy_threads=6,
serialization_context=None):
"""
Store a Python value into the object store.
Parameters
----------
value : object
A Python object to store.
object_id : ObjectID, default None
If this is provided, the specified object ID will be used to refer
to the object.
memcopy_threads : int, default 6
The number of threads to use to write the serialized object into
the object store for large objects.
serialization_context : pyarrow.SerializationContext, default None
Custom serialization and deserialization context.
Returns
-------
The object ID associated to the Python object.
"""
cdef ObjectID target_id = (object_id if object_id
else ObjectID.from_random())
if serialization_context is not None:
warnings.warn(
"'serialization_context' is deprecated and will be removed "
"in a future version.",
FutureWarning, stacklevel=2
)
serialized = pyarrow.lib._serialize(value, serialization_context)
buffer = self.create(target_id, serialized.total_bytes)
stream = pyarrow.FixedSizeBufferWriter(buffer)
stream.set_memcopy_threads(memcopy_threads)
serialized.write_to(stream)
self.seal(target_id)
return target_id
def get(self, object_ids, int timeout_ms=-1, serialization_context=None):
"""
Get one or more Python values from the object store.
Parameters
----------
object_ids : list or ObjectID
Object ID or list of object IDs associated to the values we get
from the store.
timeout_ms : int, default -1
The number of milliseconds that the get call should block before
timing out and returning. Pass -1 if the call should block and 0
if the call should return immediately.
serialization_context : pyarrow.SerializationContext, default None
Custom serialization and deserialization context.
Returns
-------
list or object
Python value or list of Python values for the data associated with
the object_ids and ObjectNotAvailable if the object was not
available.
"""
if serialization_context is not None:
warnings.warn(
"'serialization_context' is deprecated and will be removed "
"in a future version.",
FutureWarning, stacklevel=2
)
if isinstance(object_ids, Sequence):
results = []
buffers = self.get_buffers(object_ids, timeout_ms)
for i in range(len(object_ids)):
# buffers[i] is None if this object was not available within
# the timeout
if buffers[i]:
val = pyarrow.lib._deserialize(buffers[i],
serialization_context)
results.append(val)
else:
results.append(ObjectNotAvailable)
return results
else:
return self.get([object_ids], timeout_ms, serialization_context)[0]
def seal(self, ObjectID object_id):
"""
Seal the buffer in the PlasmaStore for a particular object ID.
Once a buffer has been sealed, the buffer is immutable and can only be
accessed through get.
Parameters
----------
object_id : ObjectID
A string used to identify an object.
"""
with nogil:
plasma_check_status(self.client.get().Seal(object_id.data))
def _release(self, ObjectID object_id):
"""
Notify Plasma that the object is no longer needed.
Parameters
----------
object_id : ObjectID
A string used to identify an object.
"""
with nogil:
plasma_check_status(self.client.get().Release(object_id.data))
def contains(self, ObjectID object_id):
"""
Check if the object is present and sealed in the PlasmaStore.
Parameters
----------
object_id : ObjectID
A string used to identify an object.
"""
cdef c_bool is_contained
with nogil:
plasma_check_status(self.client.get().Contains(object_id.data,
&is_contained))
return is_contained
def hash(self, ObjectID object_id):
"""
Compute the checksum of an object in the object store.
Parameters
----------
object_id : ObjectID
A string used to identify an object.
Returns
-------
bytes
A digest string object's hash. If the object isn't in the object
store, the string will have length zero.
"""
cdef c_vector[uint8_t] digest = c_vector[uint8_t](kDigestSize)
with nogil:
plasma_check_status(self.client.get().Hash(object_id.data,
digest.data()))
return bytes(digest[:])
def evict(self, int64_t num_bytes):
"""
Evict some objects until to recover some bytes.
Recover at least num_bytes bytes if possible.
Parameters
----------
num_bytes : int
The number of bytes to attempt to recover.
"""
cdef int64_t num_bytes_evicted = -1
with nogil:
plasma_check_status(
self.client.get().Evict(num_bytes, num_bytes_evicted))
return num_bytes_evicted
def subscribe(self):
"""Subscribe to notifications about sealed objects."""
with nogil:
plasma_check_status(
self.client.get().Subscribe(&self.notification_fd))
def get_notification_socket(self):
"""
Get the notification socket.
"""
return get_socket_from_fd(self.notification_fd,
family=socket.AF_UNIX,
type=socket.SOCK_STREAM)
def decode_notifications(self, const uint8_t* buf):
"""
Get the notification from the buffer.
Returns
-------
[ObjectID]
The list of object IDs in the notification message.
c_vector[int64_t]
The data sizes of the objects in the notification message.
c_vector[int64_t]
The metadata sizes of the objects in the notification message.
"""
cdef c_vector[CUniqueID] ids
cdef c_vector[int64_t] data_sizes
cdef c_vector[int64_t] metadata_sizes
with nogil:
status = self.client.get().DecodeNotifications(buf,
&ids,
&data_sizes,
&metadata_sizes)
plasma_check_status(status)
object_ids = []
for object_id in ids:
object_ids.append(ObjectID(object_id.binary()))
return object_ids, data_sizes, metadata_sizes
def get_next_notification(self):
"""
Get the next notification from the notification socket.
Returns
-------
ObjectID
The object ID of the object that was stored.
int
The data size of the object that was stored.
int
The metadata size of the object that was stored.
"""
cdef ObjectID object_id = ObjectID(CUniqueID.size() * b"\0")
cdef int64_t data_size
cdef int64_t metadata_size
with nogil:
status = self.client.get().GetNotification(self.notification_fd,
&object_id.data,
&data_size,
&metadata_size)
plasma_check_status(status)
return object_id, data_size, metadata_size
def to_capsule(self):
return PyCapsule_New(<void *>self.client.get(), "plasma", NULL)
def disconnect(self):
"""
Disconnect this client from the Plasma store.
"""
with nogil:
plasma_check_status(self.client.get().Disconnect())
def delete(self, object_ids):
"""
Delete the objects with the given IDs from other object store.
Parameters
----------
object_ids : list
A list of strings used to identify the objects.
"""
cdef c_vector[CUniqueID] ids
cdef ObjectID object_id
for object_id in object_ids:
ids.push_back(object_id.data)
with nogil:
plasma_check_status(self.client.get().Delete(ids))
def set_client_options(self, client_name, int64_t limit_output_memory):
cdef c_string name
name = client_name.encode()
with nogil:
plasma_check_status(
self.client.get().SetClientOptions(name, limit_output_memory))
def debug_string(self):
cdef c_string result
with nogil:
result = self.client.get().DebugString()
return result.decode()
def list(self):
"""
Experimental: List the objects in the store.
Returns
-------
dict
Dictionary from ObjectIDs to an "info" dictionary describing the
object. The "info" dictionary has the following entries:
data_size
size of the object in bytes
metadata_size
size of the object metadata in bytes
ref_count
Number of clients referencing the object buffer
create_time
Unix timestamp of the creation of the object
construct_duration
Time the creation of the object took in seconds
state
"created" if the object is still being created and
"sealed" if it is already sealed
"""
cdef CObjectTable objects
with nogil:
plasma_check_status(self.client.get().List(&objects))
result = dict()
cdef ObjectID object_id
cdef CObjectTableEntry entry
it = objects.begin()
while it != objects.end():
object_id = ObjectID(deref(it).first.binary())
entry = deref(deref(it).second)
if entry.state == CObjectState.PLASMA_CREATED:
state = "created"
else:
state = "sealed"
result[object_id] = {
"data_size": entry.data_size,
"metadata_size": entry.metadata_size,
"ref_count": entry.ref_count,
"create_time": entry.create_time,
"construct_duration": entry.construct_duration,
"state": state
}
inc(it)
return result
def store_capacity(self):
"""
Get the memory capacity of the store.
Returns
-------
int
The memory capacity of the store in bytes.
"""
return self.client.get().store_capacity()
def connect(store_socket_name, int num_retries=-1):
"""
Return a new PlasmaClient that is connected a plasma store and
optionally a manager.
Parameters
----------
store_socket_name : str
Name of the socket the plasma store is listening at.
num_retries : int, default -1
Number of times to try to connect to plasma store. Default value of -1
uses the default (50)
"""
cdef PlasmaClient result = PlasmaClient()
cdef int deprecated_release_delay = 0
result.store_socket_name = store_socket_name.encode()
with nogil:
plasma_check_status(
result.client.get().Connect(result.store_socket_name, b"",
deprecated_release_delay, num_retries))
return result
|