Skip to content

Commit

Permalink
feat(remoteFDB): add exists to remote store
Browse files Browse the repository at this point in the history
  • Loading branch information
mcakircali committed Jan 16, 2025
1 parent 17f4378 commit 77b365c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/fdb5/remote/client/RemoteStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,19 @@ eckit::URI RemoteStore::uri() const {
}

bool RemoteStore::exists() const {
return true;

bool result = false;

eckit::Buffer sendBuf(defaultBufferSizeKey);
eckit::MemoryStream sms(sendBuf);
sms << dbKey_;

eckit::Buffer recvBuf = controlWriteReadResponse(Message::Exists, generateRequestID(), sendBuf, sms.position());

eckit::MemoryStream rms(recvBuf);
rms >> result;

return result;
}

eckit::DataHandle* RemoteStore::retrieve(Field& field) const {
Expand Down
27 changes: 27 additions & 0 deletions src/fdb5/remote/server/StoreHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Handled StoreHandler::handleControl(Message message, uint32_t clientID, uint32_t
flush(clientID, requestID, payload);
return Handled::Yes;

case Message::Exists: // given key (payload), check if store exists
exists(clientID, requestID, payload);
return Handled::Replied;

default: {
std::stringstream ss;
ss << "ERROR: Unexpected message recieved (" << message << "). ABORTING";
Expand All @@ -94,6 +98,8 @@ Handled StoreHandler::handleControl(Message message, uint32_t clientID, uint32_t
return Handled::No;
}

//----------------------------------------------------------------------------------------------------------------------

void StoreHandler::read(uint32_t clientID, uint32_t requestID, const eckit::Buffer& payload) {

{
Expand Down Expand Up @@ -272,4 +278,25 @@ Store& StoreHandler::store(uint32_t clientID, const Key& dbKey) {
return *((stores_.emplace(clientID, StoreHelper(!single_, dbKey, config_)).first)->second.store);
}

void StoreHandler::exists(const uint32_t clientID, const uint32_t requestID, const eckit::Buffer& payload) const {

ASSERT(payload.size() > 0);

bool exists = false;

{
eckit::MemoryStream stream(payload);
const Key dbKey(stream);
exists = StoreFactory::instance().build(dbKey, config_)->exists();
}

eckit::Buffer existBuf(5);
eckit::MemoryStream stream(existBuf);
stream << exists;

write(Message::Received, true, clientID, requestID, existBuf.data(), stream.position());
}

//----------------------------------------------------------------------------------------------------------------------

} // namespace fdb5::remote

0 comments on commit 77b365c

Please sign in to comment.