From a00eae006d6b06ea81b1cab345265f826f62476b Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 2 Mar 2016 14:58:28 -0500 Subject: [PATCH] journal: pass metadata instead of finisher to FutureImpl Signed-off-by: Jason Dillaman --- src/journal/FutureImpl.cc | 13 +- src/journal/FutureImpl.h | 9 +- src/journal/JournalRecorder.cc | 4 +- src/test/journal/RadosTestFixture.cc | 8 ++ src/test/journal/RadosTestFixture.h | 10 +- src/test/journal/test_FutureImpl.cc | 151 +++++++++++++++++------ src/test/journal/test_JournalMetadata.cc | 4 +- src/test/journal/test_JournalPlayer.cc | 16 +-- src/test/journal/test_JournalRecorder.cc | 10 -- src/test/journal/test_JournalTrimmer.cc | 9 +- src/test/journal/test_ObjectRecorder.cc | 126 ++++++++++++------- 11 files changed, 228 insertions(+), 132 deletions(-) diff --git a/src/journal/FutureImpl.cc b/src/journal/FutureImpl.cc index c3344ba7d1e9c..0345c09cff18e 100644 --- a/src/journal/FutureImpl.cc +++ b/src/journal/FutureImpl.cc @@ -3,14 +3,15 @@ #include "journal/FutureImpl.h" #include "common/Finisher.h" +#include "journal/JournalMetadata.h" #include "journal/Utils.h" namespace journal { -FutureImpl::FutureImpl(Finisher &finisher, uint64_t tag_tid, uint64_t entry_tid, - uint64_t commit_tid) - : RefCountedObject(NULL, 0), m_finisher(finisher), m_tag_tid(tag_tid), - m_entry_tid(entry_tid), m_commit_tid(commit_tid), +FutureImpl::FutureImpl(JournalMetadataPtr journal_metadata, uint64_t tag_tid, + uint64_t entry_tid, uint64_t commit_tid) + : RefCountedObject(NULL, 0), m_journal_metadata(journal_metadata), + m_tag_tid(tag_tid), m_entry_tid(entry_tid), m_commit_tid(commit_tid), m_lock(utils::unique_lock_name("FutureImpl::m_lock", this)), m_safe(false), m_consistent(false), m_return_value(0), m_flush_state(FLUSH_STATE_NONE), m_consistent_ack(this) { @@ -51,7 +52,7 @@ void FutureImpl::flush(Context *on_safe) { } if (complete && on_safe != NULL) { - m_finisher.queue(on_safe, m_return_value); + m_journal_metadata->get_finisher().queue(on_safe, m_return_value); } else if (flush_handler) { // attached to journal object -- instruct it to flush all entries through // this one. possible to become detached while lock is released, so flush @@ -69,7 +70,7 @@ void FutureImpl::wait(Context *on_safe) { return; } } - m_finisher.queue(on_safe, m_return_value); + m_journal_metadata->get_finisher().queue(on_safe, m_return_value); } bool FutureImpl::is_complete() const { diff --git a/src/journal/FutureImpl.h b/src/journal/FutureImpl.h index e77f049934719..0a9eba58d56d1 100644 --- a/src/journal/FutureImpl.h +++ b/src/journal/FutureImpl.h @@ -14,11 +14,11 @@ #include "include/assert.h" class Context; -class Finisher; namespace journal { class FutureImpl; +class JournalMetadata; typedef boost::intrusive_ptr FutureImplPtr; class FutureImpl : public RefCountedObject, boost::noncopyable { @@ -29,10 +29,11 @@ public: virtual void get() = 0; virtual void put() = 0; }; + typedef boost::intrusive_ptr JournalMetadataPtr; typedef boost::intrusive_ptr FlushHandlerPtr; - FutureImpl(Finisher &finisher, uint64_t tag_tid, uint64_t entry_tid, - uint64_t commit_tid); + FutureImpl(JournalMetadataPtr journal_metadata, uint64_t tag_tid, + uint64_t entry_tid, uint64_t commit_tid); void init(const FutureImplPtr &prev_future); @@ -95,7 +96,7 @@ private: virtual void finish(int r) {} }; - Finisher &m_finisher; + JournalMetadataPtr m_journal_metadata; uint64_t m_tag_tid; uint64_t m_entry_tid; uint64_t m_commit_tid; diff --git a/src/journal/JournalRecorder.cc b/src/journal/JournalRecorder.cc index 21ecc2c90a74a..485c1f2988cd5 100644 --- a/src/journal/JournalRecorder.cc +++ b/src/journal/JournalRecorder.cc @@ -81,8 +81,8 @@ Future JournalRecorder::append(uint64_t tag_tid, ObjectRecorderPtr object_ptr = get_object(splay_offset); uint64_t commit_tid = m_journal_metadata->allocate_commit_tid( object_ptr->get_object_number(), tag_tid, entry_tid); - FutureImplPtr future(new FutureImpl(m_journal_metadata->get_finisher(), - tag_tid, entry_tid, commit_tid)); + FutureImplPtr future(new FutureImpl(m_journal_metadata, tag_tid, entry_tid, + commit_tid)); future->init(m_prev_future); m_prev_future = future; diff --git a/src/test/journal/RadosTestFixture.cc b/src/test/journal/RadosTestFixture.cc index c965c522b61d1..82f946c4d79ea 100644 --- a/src/test/journal/RadosTestFixture.cc +++ b/src/test/journal/RadosTestFixture.cc @@ -43,6 +43,14 @@ int RadosTestFixture::create(const std::string &oid, uint8_t order, return cls::journal::client::create(m_ioctx, oid, order, splay_width, -1); } +journal::JournalMetadataPtr RadosTestFixture::create_metadata( + const std::string &oid, const std::string &client_id, + double commit_internal) { + journal::JournalMetadataPtr metadata(new journal::JournalMetadata( + m_ioctx, oid, client_id, commit_internal)); + return metadata; +} + int RadosTestFixture::append(const std::string &oid, const bufferlist &bl) { librados::ObjectWriteOperation op; op.append(bl); diff --git a/src/test/journal/RadosTestFixture.h b/src/test/journal/RadosTestFixture.h index 3b05a7024da9f..0635032524400 100644 --- a/src/test/journal/RadosTestFixture.h +++ b/src/test/journal/RadosTestFixture.h @@ -19,11 +19,15 @@ public: virtual void SetUp(); virtual void TearDown(); - int create(const std::string &oid, uint8_t order, uint8_t splay_width); + int create(const std::string &oid, uint8_t order = 14, + uint8_t splay_width = 2); + journal::JournalMetadataPtr create_metadata(const std::string &oid, + const std::string &client_id = "client", + double commit_internal = 0.1); int append(const std::string &oid, const bufferlist &bl); - int client_register(const std::string &oid, const std::string &id, - const std::string &description); + int client_register(const std::string &oid, const std::string &id = "client", + const std::string &description = ""); int client_commit(const std::string &oid, const std::string &id, const cls::journal::ObjectSetPosition &commit_position); diff --git a/src/test/journal/test_FutureImpl.cc b/src/test/journal/test_FutureImpl.cc index 3a45a8d9b5fd0..51e19cf35e913 100644 --- a/src/test/journal/test_FutureImpl.cc +++ b/src/test/journal/test_FutureImpl.cc @@ -3,21 +3,12 @@ #include "journal/FutureImpl.h" #include "common/Cond.h" -#include "common/Finisher.h" #include "common/Mutex.h" #include "gtest/gtest.h" #include "test/journal/RadosTestFixture.h" class TestFutureImpl : public RadosTestFixture { public: - - TestFutureImpl() : m_finisher(NULL) { - } - ~TestFutureImpl() { - m_finisher->stop(); - delete m_finisher; - } - struct FlushHandler : public journal::FutureImpl::FlushHandler { uint64_t refs; uint64_t flushes; @@ -34,18 +25,13 @@ public: } }; - void SetUp() { - RadosTestFixture::SetUp(); - m_finisher = new Finisher(reinterpret_cast(m_ioctx.cct())); - m_finisher->start(); - } - - journal::FutureImplPtr create_future(uint64_t tag_tid, uint64_t entry_tid, + journal::FutureImplPtr create_future(journal::JournalMetadataPtr metadata, + uint64_t tag_tid, uint64_t entry_tid, uint64_t commit_tid, const journal::FutureImplPtr &prev = journal::FutureImplPtr()) { - journal::FutureImplPtr future(new journal::FutureImpl(*m_finisher, - tag_tid, entry_tid, + journal::FutureImplPtr future(new journal::FutureImpl(metadata, tag_tid, + entry_tid, commit_tid)); future->init(prev); return future; @@ -54,26 +40,42 @@ public: void flush(const journal::FutureImplPtr &future) { } - Finisher *m_finisher; - FlushHandler m_flush_handler; }; TEST_F(TestFutureImpl, Getters) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_EQ(234U, future->get_tag_tid()); ASSERT_EQ(123U, future->get_entry_tid()); ASSERT_EQ(456U, future->get_commit_tid()); } TEST_F(TestFutureImpl, Attach) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_FALSE(future->attach(&m_flush_handler)); ASSERT_EQ(1U, m_flush_handler.refs); } TEST_F(TestFutureImpl, AttachWithPendingFlush) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); future->flush(NULL); ASSERT_TRUE(future->attach(&m_flush_handler)); @@ -81,21 +83,39 @@ TEST_F(TestFutureImpl, AttachWithPendingFlush) { } TEST_F(TestFutureImpl, Detach) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_FALSE(future->attach(&m_flush_handler)); future->detach(); ASSERT_EQ(0U, m_flush_handler.refs); } TEST_F(TestFutureImpl, DetachImplicit) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_FALSE(future->attach(&m_flush_handler)); future.reset(); ASSERT_EQ(0U, m_flush_handler.refs); } TEST_F(TestFutureImpl, Flush) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_FALSE(future->attach(&m_flush_handler)); C_SaferCond cond; @@ -107,7 +127,13 @@ TEST_F(TestFutureImpl, Flush) { } TEST_F(TestFutureImpl, FlushWithoutContext) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); ASSERT_FALSE(future->attach(&m_flush_handler)); future->flush(NULL); @@ -118,9 +144,17 @@ TEST_F(TestFutureImpl, FlushWithoutContext) { } TEST_F(TestFutureImpl, FlushChain) { - journal::FutureImplPtr future1 = create_future(234, 123, 456); - journal::FutureImplPtr future2 = create_future(234, 124, 457, future1); - journal::FutureImplPtr future3 = create_future(235, 1, 458, future2); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future1 = create_future(metadata, 234, 123, 456); + journal::FutureImplPtr future2 = create_future(metadata, 234, 124, 457, + future1); + journal::FutureImplPtr future3 = create_future(metadata, 235, 1, 458, + future2); ASSERT_FALSE(future1->attach(&m_flush_handler)); ASSERT_FALSE(future2->attach(&m_flush_handler)); ASSERT_FALSE(future3->attach(&m_flush_handler)); @@ -144,8 +178,15 @@ TEST_F(TestFutureImpl, FlushChain) { } TEST_F(TestFutureImpl, FlushInProgress) { - journal::FutureImplPtr future1 = create_future(234, 123, 456); - journal::FutureImplPtr future2 = create_future(234, 124, 457, future1); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future1 = create_future(metadata, 234, 123, 456); + journal::FutureImplPtr future2 = create_future(metadata, 234, 124, 457, + future1); ASSERT_FALSE(future1->attach(&m_flush_handler)); ASSERT_FALSE(future2->attach(&m_flush_handler)); @@ -159,7 +200,13 @@ TEST_F(TestFutureImpl, FlushInProgress) { } TEST_F(TestFutureImpl, FlushAlreadyComplete) { - journal::FutureImplPtr future = create_future(234, 123, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 123, 456); future->safe(-EIO); C_SaferCond cond; @@ -168,7 +215,13 @@ TEST_F(TestFutureImpl, FlushAlreadyComplete) { } TEST_F(TestFutureImpl, Wait) { - journal::FutureImplPtr future = create_future(234, 1, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 1, 456); C_SaferCond cond; future->wait(&cond); @@ -177,7 +230,13 @@ TEST_F(TestFutureImpl, Wait) { } TEST_F(TestFutureImpl, WaitAlreadyComplete) { - journal::FutureImplPtr future = create_future(234, 1, 456); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future = create_future(metadata, 234, 1, 456); future->safe(-EEXIST); C_SaferCond cond; @@ -186,8 +245,15 @@ TEST_F(TestFutureImpl, WaitAlreadyComplete) { } TEST_F(TestFutureImpl, SafePreservesError) { - journal::FutureImplPtr future1 = create_future(234, 123, 456); - journal::FutureImplPtr future2 = create_future(234, 124, 457, future1); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future1 = create_future(metadata, 234, 123, 456); + journal::FutureImplPtr future2 = create_future(metadata, 234, 124, 457, + future1); future1->safe(-EIO); future2->safe(-EEXIST); @@ -196,8 +262,15 @@ TEST_F(TestFutureImpl, SafePreservesError) { } TEST_F(TestFutureImpl, ConsistentPreservesError) { - journal::FutureImplPtr future1 = create_future(234, 123, 456); - journal::FutureImplPtr future2 = create_future(234, 124, 457, future1); + std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); + + journal::FutureImplPtr future1 = create_future(metadata, 234, 123, 456); + journal::FutureImplPtr future2 = create_future(metadata, 234, 124, 457, + future1); future2->safe(-EEXIST); future1->safe(-EIO); diff --git a/src/test/journal/test_JournalMetadata.cc b/src/test/journal/test_JournalMetadata.cc index 91ed2d7ca19f6..ec96fc01e9dd8 100644 --- a/src/test/journal/test_JournalMetadata.cc +++ b/src/test/journal/test_JournalMetadata.cc @@ -20,8 +20,8 @@ public: journal::JournalMetadataPtr create_metadata(const std::string &oid, const std::string &client_id, double commit_internal = 0.1) { - journal::JournalMetadataPtr metadata(new journal::JournalMetadata( - m_ioctx, oid, client_id, commit_internal)); + journal::JournalMetadataPtr metadata = RadosTestFixture::create_metadata( + oid, client_id, commit_internal); m_metadata_list.push_back(metadata); metadata->add_listener(&m_listener); return metadata; diff --git a/src/test/journal/test_JournalPlayer.cc b/src/test/journal/test_JournalPlayer.cc index 7612b4982f561..d6c0fa1b39ad4 100644 --- a/src/test/journal/test_JournalPlayer.cc +++ b/src/test/journal/test_JournalPlayer.cc @@ -53,14 +53,6 @@ public: RadosTestFixture::TearDown(); } - int create(const std::string &oid, uint8_t splay_width = 2) { - return RadosTestFixture::create(oid, 14, splay_width); - } - - int client_register(const std::string &oid) { - return RadosTestFixture::client_register(oid, "client", ""); - } - int client_commit(const std::string &oid, journal::JournalPlayer::ObjectSetPosition position) { return RadosTestFixture::client_commit(oid, "client", position); @@ -72,12 +64,6 @@ public: return journal::Entry(tag_tid, entry_tid, payload_bl); } - journal::JournalMetadataPtr create_metadata(const std::string &oid) { - journal::JournalMetadataPtr metadata(new journal::JournalMetadata( - m_ioctx, oid, "client", 0.1)); - return metadata; - } - journal::JournalPlayer *create_player(const std::string &oid, const journal::JournalMetadataPtr &metadata) { journal::JournalPlayer *player(new journal::JournalPlayer( @@ -355,7 +341,7 @@ TEST_F(TestJournalPlayer, PrefetchSkippedObject) { cls::journal::ObjectSetPosition commit_position; - ASSERT_EQ(0, create(oid, 3)); + ASSERT_EQ(0, create(oid, 14, 3)); ASSERT_EQ(0, client_register(oid)); ASSERT_EQ(0, client_commit(oid, commit_position)); diff --git a/src/test/journal/test_JournalRecorder.cc b/src/test/journal/test_JournalRecorder.cc index 099c9a28b007a..d384e7f7d938d 100644 --- a/src/test/journal/test_JournalRecorder.cc +++ b/src/test/journal/test_JournalRecorder.cc @@ -18,16 +18,6 @@ public: RadosTestFixture::TearDown(); } - int client_register(const std::string &oid) { - return RadosTestFixture::client_register(oid, "client", ""); - } - - journal::JournalMetadataPtr create_metadata(const std::string &oid) { - journal::JournalMetadataPtr metadata(new journal::JournalMetadata( - m_ioctx, oid, "client", 0.1)); - return metadata; - } - journal::JournalRecorder *create_recorder(const std::string &oid, const journal::JournalMetadataPtr &metadata) { journal::JournalRecorder *recorder(new journal::JournalRecorder( diff --git a/src/test/journal/test_JournalTrimmer.cc b/src/test/journal/test_JournalTrimmer.cc index 62a6a2751b3e4..9c55aa4f5d2ee 100644 --- a/src/test/journal/test_JournalTrimmer.cc +++ b/src/test/journal/test_JournalTrimmer.cc @@ -34,14 +34,9 @@ public: return r; } - using RadosTestFixture::client_register; - int client_register(const std::string &oid) { - return RadosTestFixture::client_register(oid, "client", ""); - } - journal::JournalMetadataPtr create_metadata(const std::string &oid) { - journal::JournalMetadataPtr metadata(new journal::JournalMetadata( - m_ioctx, oid, "client", 0.1)); + journal::JournalMetadataPtr metadata = RadosTestFixture::create_metadata( + oid); m_metadata_list.push_back(metadata); metadata->add_listener(&m_listener); return metadata; diff --git a/src/test/journal/test_ObjectRecorder.cc b/src/test/journal/test_ObjectRecorder.cc index 9d3d0e51c379a..a04b3a842677b 100644 --- a/src/test/journal/test_ObjectRecorder.cc +++ b/src/test/journal/test_ObjectRecorder.cc @@ -3,7 +3,6 @@ #include "journal/ObjectRecorder.h" #include "common/Cond.h" -#include "common/Finisher.h" #include "common/Mutex.h" #include "common/Timer.h" #include "gtest/gtest.h" @@ -16,16 +15,10 @@ public: TestObjectRecorder() : m_flush_interval(std::numeric_limits::max()), m_flush_bytes(std::numeric_limits::max()), - m_flush_age(600), - m_finisher(NULL) + m_flush_age(600) { } - ~TestObjectRecorder() { - m_finisher->stop(); - delete m_finisher; - } - struct OverflowHandler : public journal::ObjectRecorder::OverflowHandler { Mutex lock; Cond cond; @@ -52,14 +45,6 @@ public: double m_flush_age; OverflowHandler m_overflow_handler; - Finisher *m_finisher; - - void SetUp() { - RadosTestFixture::SetUp(); - m_finisher = new Finisher(reinterpret_cast(m_ioctx.cct())); - m_finisher->start(); - } - void TearDown() { for (ObjectRecorders::iterator it = m_object_recorders.begin(); it != m_object_recorders.end(); ++it) { @@ -80,10 +65,11 @@ public: m_flush_age = i; } - journal::AppendBuffer create_append_buffer(uint64_t tag_tid, uint64_t entry_tid, + journal::AppendBuffer create_append_buffer(journal::JournalMetadataPtr metadata, + uint64_t tag_tid, uint64_t entry_tid, const std::string &payload) { - journal::FutureImplPtr future(new journal::FutureImpl(*m_finisher, - tag_tid, entry_tid, 456)); + journal::FutureImplPtr future(new journal::FutureImpl(metadata, tag_tid, + entry_tid, 456)); future->init(journal::FutureImplPtr()); bufferlist bl; @@ -103,18 +89,24 @@ public: TEST_F(TestObjectRecorder, Append) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, - "payload"); + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, + "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(1U, object->get_pending_appends()); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, - "payload"); + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, + "payload"); append_buffers = {append_buffer2}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(2U, object->get_pending_appends()); @@ -127,19 +119,25 @@ TEST_F(TestObjectRecorder, Append) { TEST_F(TestObjectRecorder, AppendFlushByCount) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); set_flush_interval(2); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, - "payload"); + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, + "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(1U, object->get_pending_appends()); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, - "payload"); + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, + "payload"); append_buffers = {append_buffer2}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(0U, object->get_pending_appends()); @@ -151,19 +149,25 @@ TEST_F(TestObjectRecorder, AppendFlushByCount) { TEST_F(TestObjectRecorder, AppendFlushByBytes) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); set_flush_bytes(10); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, - "payload"); + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, + "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(1U, object->get_pending_appends()); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, - "payload"); + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, + "payload"); append_buffers = {append_buffer2}; ASSERT_FALSE(object->append(append_buffers)); ASSERT_EQ(0U, object->get_pending_appends()); @@ -175,18 +179,24 @@ TEST_F(TestObjectRecorder, AppendFlushByBytes) { TEST_F(TestObjectRecorder, AppendFlushByAge) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); set_flush_age(0.1); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, - "payload"); + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, + "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, - "payload"); + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, + "payload"); append_buffers = {append_buffer2}; ASSERT_FALSE(object->append(append_buffers)); @@ -198,17 +208,23 @@ TEST_F(TestObjectRecorder, AppendFlushByAge) { TEST_F(TestObjectRecorder, AppendFilledObject) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object = create_object(oid, 12); std::string payload(2048, '1'); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, payload); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, payload); append_buffers = {append_buffer2}; ASSERT_TRUE(object->append(append_buffers)); @@ -221,11 +237,16 @@ TEST_F(TestObjectRecorder, AppendFilledObject) { TEST_F(TestObjectRecorder, Flush) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, - "payload"); + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, + "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1}; ASSERT_FALSE(object->append(append_buffers)); @@ -243,10 +264,15 @@ TEST_F(TestObjectRecorder, Flush) { TEST_F(TestObjectRecorder, FlushFuture) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer = create_append_buffer(234, 123, + journal::AppendBuffer append_buffer = create_append_buffer(metadata, + 234, 123, "payload"); journal::AppendBuffers append_buffers; append_buffers = {append_buffer}; @@ -263,10 +289,15 @@ TEST_F(TestObjectRecorder, FlushFuture) { TEST_F(TestObjectRecorder, FlushDetachedFuture) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object = create_object(oid, 24); - journal::AppendBuffer append_buffer = create_append_buffer(234, 123, + journal::AppendBuffer append_buffer = create_append_buffer(metadata, + 234, 123, "payload"); journal::AppendBuffers append_buffers; @@ -284,14 +315,20 @@ TEST_F(TestObjectRecorder, FlushDetachedFuture) { TEST_F(TestObjectRecorder, Overflow) { std::string oid = get_temp_oid(); + ASSERT_EQ(0, create(oid)); + ASSERT_EQ(0, client_register(oid)); + journal::JournalMetadataPtr metadata = create_metadata(oid); + ASSERT_EQ(0, init_metadata(metadata)); journal::ObjectRecorderPtr object1 = create_object(oid, 12); journal::ObjectRecorderPtr object2 = create_object(oid, 12); std::string payload(2048, '1'); - journal::AppendBuffer append_buffer1 = create_append_buffer(234, 123, + journal::AppendBuffer append_buffer1 = create_append_buffer(metadata, + 234, 123, payload); - journal::AppendBuffer append_buffer2 = create_append_buffer(234, 124, + journal::AppendBuffer append_buffer2 = create_append_buffer(metadata, + 234, 124, payload); journal::AppendBuffers append_buffers; append_buffers = {append_buffer1, append_buffer2}; @@ -302,7 +339,8 @@ TEST_F(TestObjectRecorder, Overflow) { ASSERT_EQ(0, cond.wait()); ASSERT_EQ(0U, object1->get_pending_appends()); - journal::AppendBuffer append_buffer3 = create_append_buffer(456, 123, + journal::AppendBuffer append_buffer3 = create_append_buffer(metadata, + 456, 123, payload); append_buffers = {append_buffer3}; -- 2.39.5