mirror of
https://github.com/wassname/ray.git
synced 2026-07-04 23:54:56 +08:00
Basic reference counting & pinning (#6554)
This commit is contained in:
+4
-13
@@ -242,7 +242,7 @@ class Worker:
|
||||
"""
|
||||
self.mode = mode
|
||||
|
||||
def put_object(self, value, object_id=None):
|
||||
def put_object(self, value, object_id=None, pin_object=True):
|
||||
"""Put value in the local object store with object id `objectid`.
|
||||
|
||||
This assumes that the value for `objectid` has not yet been placed in
|
||||
@@ -256,6 +256,7 @@ class Worker:
|
||||
value: The value to put in the object store.
|
||||
object_id (object_id.ObjectID): The object ID of the value to be
|
||||
put. If None, one will be generated.
|
||||
pin_object: If set, the object will be pinned at the raylet.
|
||||
|
||||
Returns:
|
||||
object_id.ObjectID: The object ID the object was put under.
|
||||
@@ -276,7 +277,7 @@ class Worker:
|
||||
|
||||
serialized_value = self.get_serialization_context().serialize(value)
|
||||
return self.core_worker.put_serialized_object(
|
||||
serialized_value, object_id=object_id)
|
||||
serialized_value, object_id=object_id, pin_object=pin_object)
|
||||
|
||||
def deserialize_objects(self,
|
||||
data_metadata_pairs,
|
||||
@@ -1519,7 +1520,7 @@ def put(value, weakref=False):
|
||||
object_id = worker.local_mode_manager.put_object(value)
|
||||
else:
|
||||
try:
|
||||
object_id = worker.put_object(value)
|
||||
object_id = worker.put_object(value, pin_object=not weakref)
|
||||
except ObjectStoreFullError:
|
||||
logger.info(
|
||||
"Put failed since the value was either too large or the "
|
||||
@@ -1528,16 +1529,6 @@ def put(value, weakref=False):
|
||||
"ray.put(value, weakref=True) to allow object data to "
|
||||
"be evicted early.")
|
||||
raise
|
||||
# Pin the object buffer with the returned id. This avoids put returns
|
||||
# from getting evicted out from under the id.
|
||||
# TODO(edoakes): we should be able to avoid this extra IPC by holding
|
||||
# a reference to the buffer created when putting the object, but the
|
||||
# buffer returned by the plasma store create method doesn't prevent
|
||||
# the object from being evicted.
|
||||
if not weakref and not worker.mode == LOCAL_MODE:
|
||||
object_id.set_buffer_ref(
|
||||
worker.core_worker.get_objects([object_id],
|
||||
worker.current_task_id))
|
||||
return object_id
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user