LLVM: llvm::cas::ObjectStore Class Reference (original) (raw)

Content-addressable storage for objects. More...

#include "[llvm/CAS/ObjectStore.h](ObjectStore%5F8h%5Fsource.html)"

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 validateObject (const CASID &ID)=0
Validate the underlying object referred by CASID.
virtual Error validate (bool CheckHash) const =0
Validate the entire ObjectStore.
LLVM_ABI_FOR_TEST 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().
LLVM_ABI Expected< ObjectProxy > getProxy (const CASID &ID)
Create ObjectProxy from CASID. If the object doesn't exist, get an error.
LLVM_ABI 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.
virtual Error setSizeLimit (std::optional< uint64_t > SizeLimit)
Set the size for limiting growth of on-disk storage.
virtual Expected< std::optional< uint64_t > > getStorageSize () const
virtual Error pruneStorageData ()
Prune local storage to reduce its size according to the desired size limit.
Error validateTree (ObjectRef Ref)
Validate the whole node tree.
Expected< ObjectRef > importObject (ObjectStore &Upstream, ObjectRef Other)
Import object from another CAS.
virtual void print (raw_ostream &) const
Print the ObjectStore internals for debugging purpose.
void dump () const
const CASContext & getContext () const
Get CASContext.
virtual ~ObjectStore ()=default
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 90 of file ObjectStore.h.

virtual llvm::cas::ObjectStore::~ObjectStore ( ) virtualdefault

ObjectStore()

llvm::cas::ObjectStore::ObjectStore ( const CASContext & Context) inlineprotected

createProxy()

createUnknownObjectError()

dump()

forEachRef()

Methods for handling objects.

CAS implementations need to override to provide functions to access stored CAS objects and references.

Referenced by readRefs(), and validateTree().

getContext()

getData()

getDataSize()

virtual uint64_t llvm::cas::ObjectStore::getDataSize ( ObjectHandle Node) const protectedpure virtual

getDataString()

getID()

virtual CASID llvm::cas::ObjectStore::getID ( ObjectRef Ref) const pure virtual

getMemoryBuffer()

getNumRefs()

virtual size_t llvm::cas::ObjectStore::getNumRefs ( ObjectHandle Node) const protectedpure virtual

getProxy() [1/2]

getProxy() [2/2]

getProxyIfExists()

getReference()

virtual std::optional< ObjectRef > llvm::cas::ObjectStore::getReference ( const CASID & ID) const pure virtual

getStorageSize()

virtual Expected< std::optional< uint64_t > > llvm::cas::ObjectStore::getStorageSize ( ) const inlinevirtual

Returns

the storage size of the on-disk CAS data.

Implementations that don't have an implementation for this should return std::nullopt.

Definition at line 239 of file ObjectStore.h.

importObject()

Import object from another CAS.

This will import the full tree from the other CAS.

Keeps track of the state of visitation for current node and all of its parents. Upstream Cursor holds information only from upstream CAS.

PrimaryNodeStack holds the ObjectRef of the current CAS, with nodes either just stored in the CAS or nodes already exists in the current CAS.

A map from upstream ObjectRef to current ObjectRef.

Definition at line 159 of file ObjectStore.cpp.

References llvm::ArrayRef(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::SmallVectorTemplateCommon< T, typename >::front(), getData(), getNumRefs(), I, LLVM_UNLIKELY, load(), ObjectStore(), llvm::Other, llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), readRef(), llvm::Ref, llvm::SmallVectorTemplateCommon< T, typename >::size(), store(), llvm::SmallVectorImpl< T >::truncate(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().

isMaterialized()

Returns

true if the object is directly available from the local CAS, for implementations that have this kind of distinction.

References llvm::Ref.

load()

loadIfExists()

Load the object referenced by Ref.

Errors if the object cannot be loaded.

Returns

std::nullopt if the object is missing from the CAS.

References llvm::Ref.

Referenced by getProxyIfExists(), and load().

parseID()

Get a [CASID](classllvm%5F1%5F1cas%5F1%5F1CASID.html "Unique identifier for a CAS object.") from a [ID](namespacellvm%5F1%5F1CallingConv.html#abdf8cf606905c10634e831390981b0ed "LLVM IR allows to use arbitrary numbers as calling convention identifiers."), 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.

print()

virtual void llvm::cas::ObjectStore::print ( raw_ostream & ) const inlinevirtual

pruneStorageData()

virtual Error llvm::cas::ObjectStore::pruneStorageData ( ) inlinevirtual

Prune local storage to reduce its size according to the desired size limit.

Pruning can happen concurrently with other operations.

Implementations may leave this unimplemented.

Definition at line 247 of file ObjectStore.h.

References llvm::Error::success().

readData()

readRef()

readRefs()

setSizeLimit()

virtual Error llvm::cas::ObjectStore::setSizeLimit ( std::optional< uint64_t > SizeLimit) inlinevirtual

Set the size for limiting growth of on-disk storage.

This has an effect for when the instance is closed.

Implementations may leave this unimplemented.

Definition at line 231 of file ObjectStore.h.

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

store()

storeFromOpenFile()

Default implementation reads FD and calls storeNode().

Does not take ownership of FD; the caller is responsible for closing it.

If [Status](structStatus.html) 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](structStatus.html) implies).

Returns the CASID and the size of the file.

Definition at line 201 of file ObjectStore.h.

References storeFromOpenFileImpl().

storeFromOpenFileImpl()

storeFromString()

validate()

virtual Error llvm::cas::ObjectStore::validate ( bool CheckHash) const pure virtual

validateObject()

virtual Error llvm::cas::ObjectStore::validateObject ( const CASID & ID) pure virtual

validateTree()

Validate the whole node tree.

Definition at line 135 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(), and validateObject().

ObjectProxy


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