LLVM 22.0.0git
llvm::cas::ondisk Namespace Reference

Classes

class  DatabaseFile
 Encapsulate a database file, which: More...
class  InternalRef
 Standard 8 byte reference inside OnDiskGraphDB. More...
class  InternalRef4B
 Compact 4 byte reference inside OnDiskGraphDB for smaller references. More...
class  InternalRefArrayRef
 Array of internal node references. More...
class  object_refs_iterator
 Iterator for ObjectID. More...
class  ObjectHandle
 Handle for a loaded node object. More...
class  ObjectID
 Reference to a node. More...
class  OnDiskGraphDB
 On-disk CAS nodes database, independent of a particular hashing algorithm. More...
class  OnDiskKeyValueDB
 An on-disk key-value data store with the following properties: More...
class  TableHandle
 Generic handle for a table. More...
class  UnifiedOnDiskCache
 A unified CAS nodes and key-value database, using on-disk storage for both. More...

Typedefs

using object_refs_range = llvm::iterator_range<object_refs_iterator>
using MappedFileRegion = MappedFileRegionArena::RegionT

Functions

Error createTableConfigError (std::errc ErrC, StringRef Path, StringRef TableName, const Twine &Msg)
Error checkTable (StringRef Label, size_t Expected, size_t Observed, StringRef Path, StringRef TrieName)
Expected< std::optional< uint64_t > > getOverriddenMaxMappingSize ()
 Retrieves an overridden maximum mapping size for CAS files, if any, speicified by LLVM_CAS_MAX_MAPPING_SIZE in the environment or set by setMaxMappingSize().
LLVM_ABI_FOR_TEST void setMaxMappingSize (uint64_t Size)
 Set MaxMappingSize for ondisk CAS.
bool useSmallMappingSize (const Twine &Path)
 Whether to use a small file mapping for ondisk databases created in Path.
std::error_code lockFileThreadSafe (int FD, llvm::sys::fs::LockKind Kind)
 Thread-safe alternative to sys::fs::lockFile.
std::error_code unlockFileThreadSafe (int FD)
 Thread-safe alternative to sys::fs::unlockFile.
std::error_code tryLockFileThreadSafe (int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), llvm::sys::fs::LockKind Kind=llvm::sys::fs::LockKind::Exclusive)
 Thread-safe alternative to sys::fs::tryLockFile.
Expected< size_t > preallocateFileTail (int FD, size_t CurrentSize, size_t NewSize)
 Allocate space for the file FD on disk, if the filesystem supports it.
Expected< uint64_tgetBootTime ()
 Get boot time for the OS.

Variables

constexpr StringLiteral CASFormatVersion = "v1"
 The version for all the ondisk database files.

Typedef Documentation

◆ MappedFileRegion

◆ object_refs_range

Function Documentation

◆ checkTable()

Error llvm::cas::ondisk::checkTable ( StringRef Label,
size_t Expected,
size_t Observed,
StringRef Path,
StringRef TrieName )

Definition at line 25 of file DatabaseFile.cpp.

References createTableConfigError(), and llvm::Error::success().

◆ createTableConfigError()

Error llvm::cas::ondisk::createTableConfigError ( std::errc ErrC,
StringRef Path,
StringRef TableName,
const Twine & Msg )

◆ getBootTime()

Expected< uint64_t > llvm::cas::ondisk::getBootTime ( )

Get boot time for the OS.

This can be used to check if the CAS has been validated since boot.

Returns
the boot time in seconds (0 if operation not supported), or an Error.

Definition at line 189 of file OnDiskCommon.cpp.

References llvm::createFileError(), llvm::createStringError(), llvm::errnoAsErrorCode(), and llvm::sys::fs::status().

Referenced by llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

◆ getOverriddenMaxMappingSize()

Expected< std::optional< uint64_t > > llvm::cas::ondisk::getOverriddenMaxMappingSize ( )

Retrieves an overridden maximum mapping size for CAS files, if any, speicified by LLVM_CAS_MAX_MAPPING_SIZE in the environment or set by setMaxMappingSize().

If the value from environment is unreadable, returns an error.

Definition at line 43 of file OnDiskCommon.cpp.

References llvm::createStringError(), llvm::StringRef::getAsInteger(), llvm::sys::Process::GetEnv(), llvm::inconvertibleErrorCode(), OnDiskCASMaxMappingSize, Size, and llvm::Error::success().

Referenced by llvm::cas::ondisk::OnDiskGraphDB::open(), and llvm::cas::ondisk::OnDiskKeyValueDB::open().

◆ lockFileThreadSafe()

std::error_code llvm::cas::ondisk::lockFileThreadSafe ( int FD,
llvm::sys::fs::LockKind Kind )

Thread-safe alternative to sys::fs::lockFile.

This does not support all the platforms that sys::fs::lockFile does, so keep it in the CAS library for now.

Definition at line 73 of file OnDiskCommon.cpp.

References llvm::sys::fs::Exclusive, llvm::sys::fs::lockFile(), and llvm::make_error_code().

Referenced by llvm::cas::ondisk::UnifiedOnDiskCache::open(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

◆ preallocateFileTail()

Expected< size_t > llvm::cas::ondisk::preallocateFileTail ( int FD,
size_t CurrentSize,
size_t NewSize )

Allocate space for the file FD on disk, if the filesystem supports it.

On filesystems that support this operation, this ensures errors such as std::errc::no_space_on_device are detected before we write data.

Returns
the new size of the file, or an Error.

Definition at line 127 of file OnDiskCommon.cpp.

References assert(), llvm::createStringError(), and llvm::errnoAsErrorCode().

Referenced by llvm::cas::MappedFileRegionArena::allocateOffset(), and createTempFile().

◆ setMaxMappingSize()

void llvm::cas::ondisk::setMaxMappingSize ( uint64_t Size)

Set MaxMappingSize for ondisk CAS.

This function is not thread-safe and should be set before creaing any ondisk CAS and does not affect CAS already created. Set value 0 to use default size.

Definition at line 69 of file OnDiskCommon.cpp.

References OnDiskCASMaxMappingSize, and Size.

◆ tryLockFileThreadSafe()

std::error_code llvm::cas::ondisk::tryLockFileThreadSafe ( int FD,
std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
llvm::sys::fs::LockKind Kind = llvm::sys::fs::LockKind::Exclusive )

Thread-safe alternative to sys::fs::tryLockFile.

This does not support all the platforms that sys::fs::lockFile does, so keep it in the CAS library for now.

Definition at line 101 of file OnDiskCommon.cpp.

References llvm::sys::fs::Exclusive, llvm::make_error_code(), llvm::Timeout, and llvm::sys::fs::tryLockFile().

Referenced by llvm::cas::ondisk::UnifiedOnDiskCache::close(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

◆ unlockFileThreadSafe()

std::error_code llvm::cas::ondisk::unlockFileThreadSafe ( int FD)

Thread-safe alternative to sys::fs::unlockFile.

This does not support all the platforms that sys::fs::lockFile does, so keep it in the CAS library for now.

Definition at line 87 of file OnDiskCommon.cpp.

References llvm::make_error_code(), and llvm::sys::fs::unlockFile().

Referenced by llvm::cas::ondisk::UnifiedOnDiskCache::close(), and llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded().

◆ useSmallMappingSize()

bool llvm::cas::ondisk::useSmallMappingSize ( const Twine & Path)

Whether to use a small file mapping for ondisk databases created in Path.

For some file system that doesn't support sparse file, use a smaller file mapping to avoid consuming too much disk space on creation.

Definition at line 172 of file OnDiskCommon.cpp.

References P.

Referenced by llvm::cas::ondisk::OnDiskGraphDB::open().

Variable Documentation

◆ CASFormatVersion

StringLiteral llvm::cas::ondisk::CASFormatVersion = "v1"
constexpr

The version for all the ondisk database files.

It needs to be bumped when compatibility breaking changes are introduced.

Definition at line 21 of file OnDiskCommon.h.

Referenced by llvm::cas::ondisk::OnDiskGraphDB::open(), and llvm::cas::ondisk::OnDiskKeyValueDB::open().