From 15c606e0bfb116c8324362d7baa44c9145d4ff8a Mon Sep 17 00:00:00 2001 From: Eric Cano <Eric.Cano@cern.ch> Date: Thu, 21 Feb 2019 16:41:41 +0100 Subject: [PATCH] #433: implemented `ObjectOps<>::asyncInsert()` --- objectstore/ObjectOps.hpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/objectstore/ObjectOps.hpp b/objectstore/ObjectOps.hpp index 9fcbb39061..c388d57f66 100644 --- a/objectstore/ObjectOps.hpp +++ b/objectstore/ObjectOps.hpp @@ -460,7 +460,6 @@ public: private: ObjectOps & m_obj; std::unique_ptr<Backend::AsyncLockfreeFetcher> m_asyncLockfreeFetcher; - }; friend AsyncLockfreeFetcher; @@ -471,6 +470,38 @@ public: return ret.release(); } + class AsyncInserter { + friend class ObjectOps; + AsyncInserter(ObjectOps & obj): m_obj(obj) {} + public: + void wait() { + m_asyncCreator->wait(); + m_obj.m_existingObject = true; + } + private: + ObjectOps & m_obj; + std::unique_ptr<Backend::AsyncCreator> m_asyncCreator; + }; + friend AsyncInserter; + + AsyncInserter * asyncInsert() { + std::unique_ptr<AsyncInserter> ret; + // Current simplification: the parsing of the header/payload is synchronous. + // This could be delegated to the backend. + // Check that we are not dealing with an existing object + if (m_existingObject) + throw NotNewObject("In ObjectOps::asyncInsert: trying to insert an already exitsting object"); + // Check that the object is ready in memory + if (!m_headerInterpreted || !m_payloadInterpreted) + throw NotInitialized("In ObjectOps::insert: trying to insert an uninitialized object"); + // Push the payload into the header and write the object + // We don't require locking here, as the object does not exist + // yet in the object store (and this is ensured by the ) + m_header.set_payload(m_payload.SerializeAsString()); + ret->m_asyncCreator.reset(m_objectStore.asyncCreate(getAddressIfSet(), m_header.SerializeAsString())); + return ret.release(); + } + void commit() { checkPayloadWritable(); if (!m_existingObject) -- GitLab