def delete_object(obj): # type: (object) -> bool """ Remove object. Removes a used object from the internal structures and calls the external python library (that calls the bindings-common) in order to request a its corresponding file removal. :param obj: Object to remove. :return: True if success. False otherwise. """ with event_master(DELETE_OBJECT_EVENT): app_id = 0 obj_id = OT.is_tracked(obj) if obj_id is None: # Not being tracked return False else: try: file_name = OT.get_file_name(obj_id) COMPSs.delete_file(app_id, file_name, False) OT.stop_tracking(obj) except KeyError: pass return True
def _clean_objects(): # type: () -> None """ Clean all objects. Clean the objects stored in the global dictionaries: - pending_to_synchronize dict. - _addr2id2obj dict. - obj_id_to_filename dict. - _objs_written_by_mp dict. :return: None """ app_id = 0 for filename in OT_get_all_file_names(): COMPSs.delete_file(app_id, filename, False) OT_clean_object_tracker()
def _clean_objects(hard_stop=False): # type: (bool) -> None """ Clean all objects. Clean the objects stored in the global dictionaries: - pending_to_synchronize dict. - _addr2id2obj dict. - obj_id_to_filename dict. - _objs_written_by_mp dict. :param hard_stop: avoid call to delete_file when the runtime has died. :return: None """ app_id = 0 if not hard_stop: for filename in OT_get_all_file_names(): COMPSs.delete_file(app_id, filename, False) OT_clean_object_tracker()
def delete_file(file_name): # type: (str) -> bool """ Remove a file. Calls the external python library (that calls the bindings-common) in order to request a file removal. :param file_name: File name to remove. :return: True if success. False otherwise. """ app_id = 0 if __debug__: logger.debug("Deleting file %s" % file_name) result = COMPSs.delete_file(app_id, file_name, True) == 'true' if __debug__: if result: logger.debug("File %s successfully deleted." % file_name) else: logger.error("Failed to remove file %s." % file_name) return result
def _synchronize(obj, mode): # type: (object, int) -> object """ Synchronization function. This method retrieves the value of a future object. Calls the runtime in order to wait for the value and returns it when received. :param obj: Object to synchronize. :param mode: Direction of the object to synchronize. :return: The value of the object requested. """ # TODO: Add a boolean to differentiate between files and object on the # COMPSs.open_file call. This change pretends to obtain better traces. # Must be implemented first in the Runtime, then in the bindings common # C API and finally add the boolean here app_id = 0 if is_psco(obj): obj_id = get_id(obj) if not OT_is_pending_to_synchronize(obj_id): return obj else: # file_path is of the form storage://pscoId or # file://sys_path_to_file file_path = COMPSs.open_file(app_id, "".join(("storage://", str(obj_id))), mode) # TODO: Add switch on protocol (first parameter returned currently ignored) _, file_name = file_path.split("://") new_obj = get_by_id(file_name) OT_stop_tracking(obj) return new_obj obj_id = OT_is_tracked(obj) if obj_id is None: # Not being tracked return obj if not OT_is_pending_to_synchronize(obj_id): return obj if __debug__: logger.debug("Synchronizing object %s with mode %s" % (obj_id, mode)) file_name = OT_get_file_name(obj_id) compss_file = COMPSs.open_file(app_id, file_name, mode) # Runtime can return a path or a PSCOId if compss_file.startswith('/'): # If the real filename is null, then return None. The task that # produces the output file may have been ignored or cancelled, so its # result does not exist. real_file_name = compss_file.split('/')[-1] if real_file_name == "null": print("WARNING: Could not retrieve the object " + str(file_name) + " since the task that produces it may have been IGNORED or CANCELLED. Please, check the logs. Returning None.") # noqa: E501 return None new_obj = deserialize_from_file(compss_file) COMPSs.close_file(app_id, file_name, mode) else: new_obj = get_by_id(compss_file) if mode == 'r': OT_update_mapping(obj_id, new_obj) if mode != 'r': COMPSs.delete_file(app_id, OT_get_file_name(obj_id), False) OT_stop_tracking(obj) return new_obj