From 77b365c133ed7e0e7378c1dd953e5e4cb3f5eafb Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Thu, 16 Jan 2025 15:40:16 +0100 Subject: [PATCH] feat(remoteFDB): add exists to remote store --- src/fdb5/remote/client/RemoteStore.cc | 14 ++++++++++++- src/fdb5/remote/server/StoreHandler.cc | 27 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/fdb5/remote/client/RemoteStore.cc b/src/fdb5/remote/client/RemoteStore.cc index 8df0bb25e..946862239 100644 --- a/src/fdb5/remote/client/RemoteStore.cc +++ b/src/fdb5/remote/client/RemoteStore.cc @@ -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 { diff --git a/src/fdb5/remote/server/StoreHandler.cc b/src/fdb5/remote/server/StoreHandler.cc index e11d4e491..c0c290e47 100644 --- a/src/fdb5/remote/server/StoreHandler.cc +++ b/src/fdb5/remote/server/StoreHandler.cc @@ -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"; @@ -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) { { @@ -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