8000 Remove state global locks by Shillaker · Pull Request #242 · faasm/faabric · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove state global locks #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll oc 8000 casionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/faabric/state/InMemoryStateKeyValue.h
10000
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ class InMemoryStateKeyValue final : public StateKeyValue

InMemoryStateRegistry& stateRegistry;

std::shared_mutex globalLock;

std::vector<AppendedInMemoryState> appendedData;

void lockGlobal() override;

void unlockGlobal() override;

void pullFromRemote() override;

void pullChunkFromRemote(long offset, size_t length) override;
Expand Down
6 changes: 0 additions & 6 deletions include/faabric/state/RedisStateKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class RedisStateKeyValue final : public StateKeyValue
private:
const std::string joinedKey;

uint32_t lastRemoteLockId = 0;

void lockGlobal() override;

void unlockGlobal() override;

void pullFromRemote() override;

void pullChunkFromRemote(long offset, size_t length) override;
Expand Down
4 changes: 1 addition & 3 deletions include/faabric/state/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ enum StateCalls
Append = 4,
ClearAppended = 5,
PullAppended = 6,
Lock = 7,
Unlock = 8,
Delete = 9,
Delete = 7,
};

class State
Expand Down
2 changes: 2 additions & 0 deletions include/faabric/state/StateClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ class StateClient : public faabric::transport::MessageEndpointClient
void sendStateRequest(faabric::state::StateCalls header,
const uint8_t* data,
int length);

void logRequest(const std::string& op);
};
}
4 changes: 0 additions & 4 deletions include/faabric/state/StateKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class StateKeyValue

void pushFull();

virtual void lockGlobal() = 0;

virtual void unlockGlobal() = 0;

protected:
std::shared_mutex valueMutex;

Expand Down
8 changes: 2 additions & 6 deletions include/faabric/state/StateServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class StateServer final : public faabric::transport::MessageEndpointServer
private:
State& state;

void logOperation(const std::string& op);

void doAsyncRecv(int header,
const uint8_t* buffer,
size_t bufferSize) override;
Expand Down Expand Up @@ -44,11 +46,5 @@ class StateServer final : public faabric::transport::MessageEndpointServer

std::unique_ptr<google::protobuf::Message> recvDelete(const uint8_t* buffer,
size_t bufferSize);

std::unique_ptr<google::protobuf::Message> recvLock(const uint8_t* buffer,
size_t bufferSize);

std::unique_ptr<google::protobuf::Message> recvUnlock(const uint8_t* buffer,
size_t bufferSize);
};
}
20 changes: 0 additions & 20 deletions src/state/InMemoryStateKeyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,6 @@ bool InMemoryStateKeyValue::isMaster()
// Normal state key-value API
// ----------------------------------------

void InMemoryStateKeyValue::lockGlobal()
{
if (status == InMemoryStateKeyStatus::MASTER) {
globalLock.lock();
} else {
StateClient cli(user, key, masterIP);
cli.lock();
}
}

void InMemoryStateKeyValue::unlockGlobal()
{
if (status == InMemoryStateKeyStatus::MASTER) {
globalLock.unlock();
} else {
StateClient cli(user, key, masterIP);
cli.unlock();
}
}

void InMemoryStateKeyValue::pullFromRemote()
{
if (status == InMemoryStateKeyStatus::MASTER) {
Expand Down
15 changes: 0 additions & 15 deletions src/state/RedisStateKeyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,6 @@ void RedisStateKeyValue::clearAll(bool global)
}
}

// TODO - the remote locking here is quite primitive since we ignore the fact
// threads can run on the same machine. Redis is also aware of scheduling and so
// we could optimise this.
void RedisStateKeyValue::lockGlobal()
{
faabric::util::FullLock lock(valueMutex);
lastRemoteLockId = waitOnRedisRemoteLock(joinedKey);
}

void RedisStateKeyValue::unlockGlobal()
{
faabric::util::FullLock lock(valueMutex);
redis::Redis::getState().releaseLock(joinedKey, lastRemoteLockId);
}

void RedisStateKeyValue::pullFromRemote()
{
PROF_START(statePull)
Expand Down
28 changes: 18 additions & 10 deletions src/state/StateClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <faabric/util/macros.h>

namespace faabric::state {

StateClient::StateClient(const std::string& userIn,
const std::string& keyIn,
const std::string& hostIn)
Expand All @@ -15,6 +16,11 @@ StateClient::StateClient(const std::string& userIn,
, key(keyIn)
{}

void StateClient::logRequest(const std::string& op)
{
SPDLOG_TRACE("Requesting {} on {}/{} at {}", op, user, key, host);
}

void StateClient::sendStateRequest(faabric::state::StateCalls header,
const uint8_t* data,
int length)
Expand All @@ -33,6 +39,8 @@ void StateClient::sendStateRequest(faabric::state::StateCalls header,

void StateClient::pushChunks(const std::vector<StateChunk>& chunks)
{
logRequest("push-chunks");

for (const auto& chunk : chunks) {
faabric::StatePart stateChunk;
stateChunk.set_user(user);
Expand All @@ -48,6 +56,8 @@ void StateClient::pushChunks(const std::vector<StateChunk>& chunks)
void StateClient::pullChunks(const std::vector<StateChunk>& chunks,
uint8_t* bufferStart)
{
logRequest("pull-chunks");

for (const auto& chunk : chunks) {
// Prepare request
faabric::StateChunkRequest request;
Expand All @@ -69,11 +79,14 @@ void StateClient::pullChunks(const std::vector<StateChunk>& chunks,

void StateClient::append(const uint8_t* data, size_t length)
{
logRequest("append");
sendStateRequest(faabric::state::StateCalls::Append, data, length);
}

void StateClient::pullAppended(uint8_t* buffer, size_t length, long nValues)
{
logRequest("pull-appended");

// Prepare request
faabric::StateAppendedRequest request;
request.set_user(user);
Expand Down Expand Up @@ -101,11 +114,14 @@ void StateClient::pullAppended(uint8_t* buffer, size_t length, long nValues)

void StateClient::clearAppended()
{
logRequest("clear-appended");
sendStateRequest(faabric::state::StateCalls::ClearAppended, nullptr, 0);
}

size_t StateClient::stateSize()
{
logRequest("state-size");

faabric::StateRequest request;
request.set_user(user);
request.set_key(key);
Expand All @@ -118,16 +134,8 @@ size_t StateClient::stateSize()

void StateClient::deleteState()
{
sendStateRequest(faabric::state::StateCalls::Delete, nullptr, 0);
}
logRequest("delete");

void StateClient::lock()
{
sendStateRequest(faabric::state::StateCalls::Lock, nullptr, 0);
}

void StateClient::unlock()
{
sendStateRequest(faabric::state::StateCalls::Unlock, nullptr, 0);
sendStateRequest(faabric::state::StateCalls::Delete, nullptr, 0);
}
}
48 changes: 6 additions & 42 deletions src/state/StateServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ StateServer::doSyncRecv(int header, const uint8_t* buffer, size_t bufferSize)
case faabric::state::StateCalls::PullAppended: {
return recvPullAppended(buffer, bufferSize);
}
case faabric::state::StateCalls::Lock: {
return recvLock(buffer, bufferSize);
}
case faabric::state::StateCalls::Unlock: {
return recvUnlock(buffer, bufferSize);
}
case faabric::state::StateCalls::Delete: {
return recvDelete(buffer, bufferSize);
}
Expand All @@ -73,7 +67,7 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvSize(
PARSE_MSG(faabric::StateRequest, buffer, bufferSize)

// Prepare the response
SPDLOG_TRACE("Size {}/{}", msg.user(), msg.key());
SPDLOG_TRACE("Received size {}/{}", msg.user(), msg.key());
KV_FROM_REQUEST(msg)
auto response = std::make_unique<faabric::StateSizeResponse>();
response->set_user(kv->user);
Expand All @@ -89,7 +83,7 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvPull(
{
PARSE_MSG(faabric::StateChunkRequest, buffer, bufferSize)

SPDLOG_TRACE("Pull {}/{} ({}->{})",
SPDLOG_TRACE("Received pull {}/{} ({}->{})",
msg.user(),
msg.key(),
msg.offset(),
Expand Down Expand Up @@ -118,7 +112,7 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvPush(
PARSE_MSG(faabric::StatePart, buffer, bufferSize)

// Update the KV store
SPDLOG_TRACE("Push {}/{} ({}->{})",
SPDLOG_TRACE("Received push {}/{} ({}->{})",
msg.user(),
msg.key(),
msg.offset(),
Expand Down Expand Up @@ -155,7 +149,7 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvPullAppended(
PARSE_MSG(faabric::StateAppendedRequest, buffer, bufferSize)

// Prepare response
SPDLOG_TRACE("Pull appended {}/{}", msg.user(), msg.key());
SPDLOG_TRACE("Received pull-appended {}/{}", msg.user(), msg.key());
KV_FROM_REQUEST(msg)

auto response = std::make_unique<faabric::StateAppendedResponse>();
Expand All @@ -178,7 +172,7 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvDelete(
PARSE_MSG(faabric::StateRequest, buffer, bufferSize)

// Delete value
SPDLOG_TRACE("Delete {}/{}", msg.user(), msg.key());
SPDLOG_TRACE("Received delete {}/{}", msg.user(), msg.key());
state.deleteKV(msg.user(), msg.key());

auto response = std::make_unique<faabric::StateResponse>();
Expand All @@ -192,41 +186,11 @@ std::unique_ptr<google::protobuf::Message> StateServer::recvClearAppended(
PARSE_MSG(faabric::StateRequest, buffer, bufferSize)

// Perform operation
SPDLOG_TRACE("Clear appended {}/{}", msg.user(), msg.key());
SPDLOG_TRACE("Received clear-appended {}/{}", msg.user(), msg.key());
KV_FROM_REQUEST(msg)
kv->clearAppended();

auto response = std::make_unique<faabric::StateResponse>();
return response;
}

std::unique_ptr<google::protobuf::Message> StateServer::recvLock(
const uint8_t* buffer,
size_t bufferSize)
{
PARSE_MSG(faabric::StateRequest, buffer, bufferSize)

// Perform operation
SPDLOG_TRACE("Lock {}/{}", msg.user(), msg.key());
KV_FROM_REQUEST(msg)
kv->lockWrite();

auto response = std::make_unique<faabric::StateResponse>();
return response;
}

std::unique_ptr<google::protobuf::Message> StateServer::recvUnlock(
const uint8_t* buffer,
size_t bufferSize)
{
PARSE_MSG(faabric::StateRequest, buffer, bufferSize)

// Perform operation
SPDLOG_TRACE("Unlock {}/{}", msg.user(), msg.key());
KV_FROM_REQUEST(msg)
kv->unlockWrite();

auto response = std::make_unique<faabric::StateResponse>();
return response;
}
}
0