File StateKeyValue.h

Defines

STATE_STREAMING_CHUNK_SIZE

Functions

constexpr int REMOTE_LOCK_TIMEOUT_SECS (1)
constexpr int REMOTE_LOCK_MAX_RETRIES (100)
namespace faabric
namespace state

WARNING - key-value objects are shared between threads, BUT hiredis is not thread-safe, so make sure you always retrieve the reference to Redis inline rather than sharing a reference within the class.

class StateChunk

Public Functions

inline StateChunk(long offsetIn, size_t lengthIn, uint8_t *dataIn)
inline StateChunk(long offsetIn, std::vector<uint8_t> &data)

Public Members

long offset
size_t length
uint8_t *data
class StateKeyValue

Subclassed by faabric::state::InMemoryStateKeyValue, faabric::state::RedisStateKeyValue

Public Functions

StateKeyValue(const std::string &userIn, const std::string &keyIn, size_t sizeIn)
StateKeyValue(const std::string &userIn, const std::string &keyIn)
void get(uint8_t *buffer)
uint8_t *get()
void getChunk(long offset, uint8_t *buffer, size_t length)
uint8_t *getChunk(long offset, long len)
std::vector<StateChunk> getAllChunks()
void set(const uint8_t *buffer)
void setChunk(long offset, const uint8_t *buffer, size_t length)
void append(const uint8_t *buffer, size_t length)
void getAppended(uint8_t *buffer, size_t length, long nValues)
void clearAppended()
void mapSharedMemory(void *destination, long pagesOffset, long nPages)
void unmapSharedMemory(void *mappedAddr)
void pull()
void pushPartial()
void pushPartialMask(const std::shared_ptr<StateKeyValue> &maskKv)
void lockRead()
void unlockRead()
void lockWrite()
void unlockWrite()
void flagDirty()
void flagChunkDirty(long offset, long len)
size_t size() const
size_t getSharedMemorySize() const
void pushFull()

Public Members

const std::string user
const std::string key

Public Static Functions

static uint32_t waitOnRedisRemoteLock(const std::string &redisKey)

Protected Functions

void doSet(const uint8_t *data)
void doSetChunk(long offset, const uint8_t *buffer, size_t length)
virtual void pullFromRemote() = 0
virtual void pullChunkFromRemote(long offset, size_t length) = 0
virtual void pushToRemote() = 0
virtual void appendToRemote(const uint8_t *data, size_t length) = 0
virtual void pullAppendedFromRemote(uint8_t *data, size_t length, long nValues) = 0
virtual void clearAppendedFromRemote() = 0
virtual void pushPartialToRemote(const std::vector<StateChunk> &dirtyChunks) = 0

Protected Attributes

std::shared_mutex valueMutex
size_t valueSize
size_t sharedMemSize
void *sharedMemory = nullptr

Private Functions

void zeroDirtyMask()
void configureSize()
void checkSizeConfigured()
void markDirtyChunk(long offset, long len)
bool isChunkPulled(long offset, size_t length)
void allocateChunk(long offset, size_t length)
void reserveStorage()
void doPull(bool lazy)
void doPullChunk(bool lazy, long offset, size_t length)
void doPushPartial(const uint8_t *dirtyMaskBytes)
std::vector<StateChunk> getDirtyChunks(const uint8_t *dirtyMaskBytes)

Private Members

std::atomic<bool> fullyAllocated = false
std::atomic<bool> fullyPulled = false
std::unique_ptr<uint8_t[]> pulledMask = nullptr
std::unique_ptr<uint8_t[]> dirtyMask = nullptr
bool isDirty = false
class StateKeyValueException : public runtime_error

Public Functions

inline explicit StateKeyValueException(const std::string &message)