LLVM 22.0.0git
OnDiskCommon.h
Go to the documentation of this file.
1//===- OnDiskCommon.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_CAS_ONDISKCOMMON_H
10#define LLVM_LIB_CAS_ONDISKCOMMON_H
11
12#include "llvm/Support/Error.h"
14#include <chrono>
15#include <optional>
16
17namespace llvm::cas::ondisk {
18
19/// The version for all the ondisk database files. It needs to be bumped when
20/// compatibility breaking changes are introduced.
22
23/// Retrieves an overridden maximum mapping size for CAS files, if any,
24/// speicified by LLVM_CAS_MAX_MAPPING_SIZE in the environment or set by
25/// `setMaxMappingSize()`. If the value from environment is unreadable, returns
26/// an error.
28
29/// Set MaxMappingSize for ondisk CAS. This function is not thread-safe and
30/// should be set before creaing any ondisk CAS and does not affect CAS already
31/// created. Set value 0 to use default size.
33
34/// Whether to use a small file mapping for ondisk databases created in \p Path.
35///
36/// For some file system that doesn't support sparse file, use a smaller file
37/// mapping to avoid consuming too much disk space on creation.
38bool useSmallMappingSize(const Twine &Path);
39
40/// Thread-safe alternative to \c sys::fs::lockFile. This does not support all
41/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library
42/// for now.
43std::error_code lockFileThreadSafe(int FD, llvm::sys::fs::LockKind Kind);
44
45/// Thread-safe alternative to \c sys::fs::unlockFile. This does not support all
46/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library
47/// for now.
48std::error_code unlockFileThreadSafe(int FD);
49
50/// Thread-safe alternative to \c sys::fs::tryLockFile. This does not support
51/// all the platforms that \c sys::fs::lockFile does, so keep it in the CAS
52/// library for now.
53std::error_code tryLockFileThreadSafe(
54 int FD, std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
56
57/// Allocate space for the file \p FD on disk, if the filesystem supports it.
58///
59/// On filesystems that support this operation, this ensures errors such as
60/// \c std::errc::no_space_on_device are detected before we write data.
61///
62/// \returns the new size of the file, or an \c Error.
63Expected<size_t> preallocateFileTail(int FD, size_t CurrentSize,
64 size_t NewSize);
65
66} // namespace llvm::cas::ondisk
67
68#endif // LLVM_LIB_CAS_ONDISKCOMMON_H
Tagged union holding either a T or a Error.
Definition Error.h:485
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
constexpr StringLiteral CASFormatVersion
The version for all the ondisk database files.
void setMaxMappingSize(uint64_t Size)
Set MaxMappingSize for ondisk CAS.
Expected< std::optional< uint64_t > > getOverriddenMaxMappingSize()
Retrieves an overridden maximum mapping size for CAS files, if any, speicified by LLVM_CAS_MAX_MAPPIN...
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.
bool useSmallMappingSize(const Twine &Path)
Whether to use a small file mapping for ondisk databases created in Path.
LockKind
An enumeration for the lock kind.
@ Timeout
Reached timeout while waiting for the owner to release the lock.