LLVM 22.0.0git
|
Content-addressable storage for objects. More...
#include "llvm/CAS/ObjectStore.h"
Public Member Functions | |
virtual Expected< CASID > | parseID (StringRef ID)=0 |
Get a CASID from a ID , which should have been generated by CASID::print(). | |
virtual Expected< ObjectRef > | store (ArrayRef< ObjectRef > Refs, ArrayRef< char > Data)=0 |
Store object into ObjectStore. | |
virtual CASID | getID (ObjectRef Ref) const =0 |
Get an ID for Ref . | |
virtual std::optional< ObjectRef > | getReference (const CASID &ID) const =0 |
Get an existing reference to the object called ID . | |
virtual Expected< bool > | isMaterialized (ObjectRef Ref) const =0 |
virtual Error | validate (const CASID &ID)=0 |
Validate the underlying object referred by CASID. | |
Expected< ObjectProxy > | createProxy (ArrayRef< ObjectRef > Refs, StringRef Data) |
Helper functions to store object and returns a ObjectProxy. | |
Expected< ObjectRef > | storeFromString (ArrayRef< ObjectRef > Refs, StringRef String) |
Store object from StringRef. | |
Expected< ObjectRef > | storeFromOpenFile (sys::fs::file_t FD, std::optional< sys::fs::file_status > Status=std::nullopt) |
Default implementation reads FD and calls storeNode(). | |
Expected< ObjectProxy > | getProxy (const CASID &ID) |
Create ObjectProxy from CASID. If the object doesn't exist, get an error. | |
Expected< ObjectProxy > | getProxy (ObjectRef Ref) |
Create ObjectProxy from ObjectRef. | |
Expected< std::optional< ObjectProxy > > | getProxyIfExists (ObjectRef Ref) |
uint64_t | readData (ObjectHandle Node, raw_ostream &OS, uint64_t Offset=0, uint64_t MaxBytes=-1ULL) const |
Read the data from Data into OS . | |
Error | validateTree (ObjectRef Ref) |
Validate the whole node tree. | |
const CASContext & | getContext () const |
Get CASContext. | |
virtual | ~ObjectStore ()=default |
Static Public Member Functions | |
static Error | createUnknownObjectError (const CASID &ID) |
Protected Member Functions | |
virtual Expected< std::optional< ObjectHandle > > | loadIfExists (ObjectRef Ref)=0 |
Load the object referenced by Ref . | |
Expected< ObjectHandle > | load (ObjectRef Ref) |
Like loadIfExists but returns an error if the object is missing. | |
virtual uint64_t | getDataSize (ObjectHandle Node) const =0 |
Get the size of some data. | |
virtual Error | forEachRef (ObjectHandle Node, function_ref< Error(ObjectRef)> Callback) const =0 |
Methods for handling objects. | |
virtual ObjectRef | readRef (ObjectHandle Node, size_t I) const =0 |
virtual size_t | getNumRefs (ObjectHandle Node) const =0 |
virtual ArrayRef< char > | getData (ObjectHandle Node, bool RequiresNullTerminator=false) const =0 |
virtual Expected< ObjectRef > | storeFromOpenFileImpl (sys::fs::file_t FD, std::optional< sys::fs::file_status > Status) |
Get ObjectRef from open file. | |
StringRef | getDataString (ObjectHandle Node) |
Get a lifetime-extended StringRef pointing at Data . | |
std::unique_ptr< MemoryBuffer > | getMemoryBuffer (ObjectHandle Node, StringRef Name="", bool RequiresNullTerminator=true) |
Get a lifetime-extended MemoryBuffer pointing at Data . | |
virtual void | readRefs (ObjectHandle Node, SmallVectorImpl< ObjectRef > &Refs) const |
Read all the refs from object in a SmallVector. | |
ObjectStore (const CASContext &Context) |
Friends | |
class | ObjectProxy |
Content-addressable storage for objects.
Conceptually, objects are stored in a "unique set".
The ObjectStore interface has a few ways of referencing objects:
Both ObjectRef and ObjectHandle are lightweight, wrapping a uint64_t and are only valid with the associated ObjectStore instance.
There are a few options for accessing content of objects, with different lifetime tradeoffs:
Definition at line 85 of file ObjectStore.h.
|
virtualdefault |
|
inlineprotected |
Definition at line 227 of file ObjectStore.h.
Referenced by llvm::cas::builtin::BuiltinCAS::BuiltinCAS().
Expected< ObjectProxy > ObjectStore::createProxy | ( | ArrayRef< ObjectRef > | Refs, |
StringRef | Data ) |
Helper functions to store object and returns a ObjectProxy.
Definition at line 113 of file ObjectStore.cpp.
References llvm::arrayRefFromStringRef(), llvm::Data, getProxy(), llvm::Ref, and store().
Definition at line 108 of file ObjectStore.cpp.
References llvm::createStringError().
Referenced by getProxy().
|
protectedpure virtual |
Methods for handling objects.
CAS implementations need to override to provide functions to access stored CAS objects and references.
Referenced by readRefs(), and validateTree().
|
inline |
Get CASContext.
Definition at line 222 of file ObjectStore.h.
Referenced by llvm::cas::builtin::BuiltinCAS::parseID().
|
protectedpure virtual |
Implemented in llvm::cas::builtin::BuiltinCAS.
Referenced by getDataString(), getMemoryBuffer(), and readData().
|
protectedpure virtual |
Get the size of some data.
Implemented in llvm::cas::builtin::BuiltinCAS.
|
inlineprotected |
Get a lifetime-extended StringRef pointing at Data
.
Depending on the CAS implementation, this may involve in-memory storage overhead.
Definition at line 147 of file ObjectStore.h.
References getData(), and llvm::toStringRef().
Get an ID for Ref
.
References llvm::Ref.
Referenced by llvm::cas::ObjectProxy::getReferenceID(), load(), and validateTree().
|
protected |
Get a lifetime-extended MemoryBuffer pointing at Data
.
Depending on the CAS implementation, this may involve in-memory storage overhead.
Definition at line 67 of file ObjectStore.cpp.
References getData(), llvm::MemoryBuffer::getMemBuffer(), and llvm::toStringRef().
|
protectedpure virtual |
Expected< ObjectProxy > ObjectStore::getProxy | ( | const CASID & | ID | ) |
Create ObjectProxy from CASID. If the object doesn't exist, get an error.
Definition at line 82 of file ObjectStore.cpp.
References createUnknownObjectError(), getProxy(), getReference(), and llvm::Ref.
Referenced by createProxy(), and getProxy().
Expected< ObjectProxy > ObjectStore::getProxy | ( | ObjectRef | Ref | ) |
Create ObjectProxy from ObjectRef.
If the object can't be loaded, get an error.
Definition at line 90 of file ObjectStore.cpp.
References H, llvm::cas::ObjectProxy::load(), load, and llvm::Ref.
Expected< std::optional< ObjectProxy > > ObjectStore::getProxyIfExists | ( | ObjectRef | Ref | ) |
std::nullopt
if the object is missing from the CAS. Definition at line 99 of file ObjectStore.cpp.
References H, llvm::cas::ObjectProxy::load(), loadIfExists(), and llvm::Ref.
|
pure virtual |
Get an existing reference to the object called ID
.
Returns None
if the object is not stored in this CAS.
Referenced by getProxy(), and llvm::cas::builtin::BuiltinCAS::validate().
References llvm::Ref.
|
protected |
Like loadIfExists
but returns an error if the object is missing.
Definition at line 56 of file ObjectStore.cpp.
References llvm::createStringError(), getID(), llvm::invalid_argument, loadIfExists(), llvm::Ref, and llvm::toString().
|
protectedpure virtual |
Load the object referenced by Ref
.
Errors if the object cannot be loaded.
std::nullopt
if the object is missing from the CAS. References llvm::Ref.
Referenced by getProxyIfExists(), and load().
Get a CASID
from a ID
, which should have been generated by CASID::print().
This succeeds as long as validateID() would pass. The object may be unknown to this CAS instance.
TODO: Remove, and update callers to use validateID() or extractHashFromID().
Implemented in llvm::cas::builtin::BuiltinCAS.
|
inline |
Read the data from Data
into OS
.
Definition at line 209 of file ObjectStore.h.
References assert(), llvm::Data, getData(), llvm::Offset, and llvm::toStringRef().
|
protectedpure virtual |
References I.
|
protectedvirtual |
Read all the refs from object in a SmallVector.
Definition at line 74 of file ObjectStore.cpp.
References llvm::consumeError(), forEachRef(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Ref, and llvm::Error::success().
|
pure virtual |
Store object into ObjectStore.
Implemented in llvm::cas::builtin::BuiltinCAS.
References llvm::Data.
Referenced by createProxy(), storeFromOpenFileImpl(), and storeFromString().
|
inline |
Default implementation reads FD
and calls storeNode().
Does not take ownership of FD
; the caller is responsible for closing it.
If Status
is sent in it is to be treated as a hint. Implementations must protect against the file size potentially growing after the status was taken (i.e., they cannot assume that an mmap will be null-terminated where Status
implies).
Returns the CASID and the size of the file.
Definition at line 192 of file ObjectStore.h.
References storeFromOpenFileImpl().
|
protectedvirtual |
Get ObjectRef from open file.
Definition at line 122 of file ObjectStore.cpp.
References llvm::arrayRefFromStringRef(), llvm::errorCodeToError(), llvm::MemoryBuffer::getOpenFile(), Size, and store().
Referenced by storeFromOpenFile().
|
inline |
Store object from StringRef.
Definition at line 177 of file ObjectStore.h.
References llvm::arrayRefFromStringRef(), store(), and llvm::String.
Validate the underlying object referred by CASID.
Implemented in llvm::cas::builtin::BuiltinCAS.
Referenced by validateTree().
Validate the whole node tree.
Definition at line 134 of file ObjectStore.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::empty(), forEachRef(), getID(), I, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), load, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Ref, llvm::Error::success(), llvm::Expected< T >::takeError(), and validate().
|
friend |