Turi Create  4.0
turi::fileio::file_handle_pool Class Reference

#include <core/storage/fileio/file_handle_pool.hpp>

Public Member Functions

std::shared_ptr< file_ownership_handleregister_file (const std::string &file_name)
 
bool mark_file_for_delete (std::string file_name)
 
bool unmark_file_for_delete (std::string file_name)
 

Static Public Member Functions

static file_handle_poolget_instance ()
 

Detailed Description

A global file lifespan manager that manages life time for non temporary files that are currently in use by any SArray(including the array index file and the segment files).

Permanent files used by SArray can be removed when user saves a SArray to a directory where there is already a SArray saved there. In case there is some SArray actively referencing the files in the directory, we will delay deletion of those files until nobody is referencing those files. new files will be created under the directory to save the new SArray and the directory index will correctly point to the new files.

A file_handle object is created for each file that is in use by SArray. All SArrays referencing those files keep a shared pointer to the file handle object. On reading from a directory, SAray registers the files with global file_handle_pool, When SArray is out of scope, the corresponding ref to the file_handle is removed. Once all ref of a given file_handle goes away, the files may or may not be deleted depend on whether or not the files are overwritten.

The pool itself keeps a weak pointer to the file_handle object so the files can be deleted when all SArrays referencing the file are gone.

Definition at line 38 of file file_handle_pool.hpp.

Member Function Documentation

◆ get_instance()

static file_handle_pool& turi::fileio::file_handle_pool::get_instance ( )
static

Singleton retriever

◆ mark_file_for_delete()

bool turi::fileio::file_handle_pool::mark_file_for_delete ( std::string  file_name)

Try to mark the file for deletion, returns success if the mark is done successfuly, other wise, the global file pool doesn't know about the file, caller is responsible for deleting the files The marked files will be deleted when all users are out of scope

Parameters
file_nameThe name of the file to be marked for deletion

◆ register_file()

std::shared_ptr<file_ownership_handle> turi::fileio::file_handle_pool::register_file ( const std::string &  file_name)

Register with file pool that a file is in use. Returns a file_ownership_handle to the caller that can do auto deletion of the file if it goes out of scope.

Parameters
file_nameThe name of the file to be registered

Returns a shared pointer to the newly created file_ownership_handle

◆ unmark_file_for_delete()

bool turi::fileio::file_handle_pool::unmark_file_for_delete ( std::string  file_name)

Unmarks a previously marked file for deletion. Returns true if the file was previously marked for deletion. False otherwise.


The documentation for this class was generated from the following file: