File snapshot.h

Defines

ARRAY_COMP_CHUNK_SIZE
namespace faabric
namespace util

Enums

enum SnapshotDataType

Defines the permitted datatypes for snapshot diffs. Each has a predefined length, except for the raw option which is used for generic streams of bytes.

Values:

enumerator Raw
enumerator Bool
enumerator Int
enumerator Long
enumerator Float
enumerator Double
enum SnapshotMergeOperation

Defines the operation to perform when merging the diff with the original snapshot.

WARNING: this enum forms part of the API with executing applications, so make sure they are updated accordingly when it’s changed.

Values:

enumerator Bytewise
enumerator Sum
enumerator Product
enumerator Subtract
enumerator Max
enumerator Min
enumerator Ignore
enumerator XOR

Functions

template<typename T>
inline bool calculateDiffValue(const uint8_t *original, uint8_t *updated, SnapshotMergeOperation operation)
template<typename T>
inline T applyDiffValue(const uint8_t *original, const uint8_t *diff, SnapshotMergeOperation operation)
class SnapshotData

Public Functions

SnapshotData() = default
explicit SnapshotData(size_t sizeIn)
SnapshotData(size_t sizeIn, size_t maxSizeIn)
explicit SnapshotData(std::span<const uint8_t> dataIn)
SnapshotData(std::span<const uint8_t> dataIn, size_t maxSizeIn)
SnapshotData(const SnapshotData&) = delete
SnapshotData &operator=(const SnapshotData&) = delete
~SnapshotData()
void copyInData(std::span<const uint8_t> buffer, uint32_t offset = 0)
const uint8_t *getDataPtr(uint32_t offset = 0)
std::vector<uint8_t> getDataCopy()
std::vector<uint8_t> getDataCopy(uint32_t offset, size_t dataSize)
void mapToMemory(std::span<uint8_t> target)
void addMergeRegion(uint32_t offset, size_t length, SnapshotDataType dataType, SnapshotMergeOperation operation)
void fillGapsWithBytewiseRegions()
void clearMergeRegions()
std::vector<SnapshotMergeRegion> getMergeRegions()
size_t getQueuedDiffsCount()
void applyDiffs(const std::vector<SnapshotDiff> &diffs)
void applyDiff(const SnapshotDiff &diff)
void queueDiffs(const std::vector<SnapshotDiff> &diffs)
int writeQueuedDiffs()
inline size_t getSize() const
inline size_t getMaxSize() const
std::vector<SnapshotDiff> getTrackedChanges()
void clearTrackedChanges()
std::vector<faabric::util::SnapshotDiff> diffWithDirtyRegions(std::span<uint8_t> updated, const std::vector<char> &dirtyRegions)

Private Functions

uint8_t *validatedOffsetPtr(uint32_t offset)
void mapToMemory(uint8_t *target, bool shared)
void writeData(std::span<const uint8_t> buffer, uint32_t offset = 0)
void xorData(std::span<const uint8_t> buffer, uint32_t offset = 0)
void checkWriteExtension(std::span<const uint8_t> buffer, uint32_t offset)

Private Members

size_t size = 0
size_t maxSize = 0
int fd = -1
std::shared_mutex snapMx
MemoryRegion data = nullptr
std::vector<SnapshotDiff> queuedDiffs
std::vector<std::pair<uint32_t, uint32_t>> trackedChanges
std::vector<SnapshotMergeRegion> mergeRegions
class SnapshotDiff
#include <snapshot.h>

Represents a modification to a snapshot (a.k.a. a dirty region). Specifies the modified data, as well as its offset within the snapshot.

Each diff does not own the data, it just provides a span pointing at the original data.

Public Functions

SnapshotDiff() = default
SnapshotDiff(SnapshotDataType dataTypeIn, SnapshotMergeOperation operationIn, uint32_t offsetIn, std::span<const uint8_t> dataIn)
inline SnapshotDataType getDataType() const
inline SnapshotMergeOperation getOperation() const
inline uint32_t getOffset() const
inline std::span<const uint8_t> getData() const
std::vector<uint8_t> getDataCopy() const

Private Members

SnapshotDataType dataType = SnapshotDataType::Raw
SnapshotMergeOperation operation = SnapshotMergeOperation::Bytewise
uint32_t offset = 0
std::span<const uint8_t> data
class SnapshotMergeRegion
#include <snapshot.h>

Defines how diffs in the given snapshot region should be interpreted wrt the original snapshot.

For example, it may specify that the change should be treated as an integer that needs to be summed (i.e. the diff is the current value minus the original), or just as a region of raw bytes that needs to be XORed with the original.

A merge region specifies an offset, length, data type and operation, e.g. an integer to be summed at offset 100 with a length of 4.

Public Functions

SnapshotMergeRegion() = default
SnapshotMergeRegion(uint32_t offsetIn, size_t lengthIn, SnapshotDataType dataTypeIn, SnapshotMergeOperation operationIn)
void addDiffs(std::vector<SnapshotDiff> &diffs, std::span<const uint8_t> originalData, std::span<uint8_t> updatedData, const std::vector<char> &dirtyRegions)
inline bool operator<(const SnapshotMergeRegion &other) const

This allows us to sort the merge regions which is important for diffing purposes.

inline bool operator==(const SnapshotMergeRegion &other) const

Public Members

uint32_t offset = 0
size_t length = 0
SnapshotDataType dataType = SnapshotDataType::Raw
SnapshotMergeOperation operation = SnapshotMergeOperation::Bytewise