From: Xinze Chi Date: Fri, 6 Nov 2015 13:45:18 +0000 (+0800) Subject: tests: fix test case using new api X-Git-Tag: v10.0.1~61^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F6484%2Fhead;p=ceph.git tests: fix test case using new api Signed-off-by: Xinze Chi --- diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 70b7cc92fd0f..8579fa984f12 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -1959,10 +1959,7 @@ int FileStore::queue_transactions(Sequencer *posr, list &tls, journal->throttle(); //prepare and encode transactions data out of lock bufferlist tbl; - int orig_len = -1; - if (journal && journal->is_writeable()) { - orig_len = journal->prepare_entry(o->tls, &tbl); - } + int orig_len = journal->prepare_entry(o->tls, &tbl); uint64_t op_num = submit_manager.op_submit_start(); o->op = op_num; @@ -2011,11 +2008,11 @@ int FileStore::queue_transactions(Sequencer *posr, list &tls, return 0; } - + assert(journal); //prepare and encode transactions data out of lock bufferlist tbl; int orig_len = -1; - if (journal && journal->is_writeable()) { + if (journal->is_writeable()) { orig_len = journal->prepare_entry(tls, &tbl); } uint64_t op = submit_manager.op_submit_start(); diff --git a/src/test/test_filejournal.cc b/src/test/test_filejournal.cc index aaf64876b047..bd0ff5293384 100644 --- a/src/test/test_filejournal.cc +++ b/src/test/test_filejournal.cc @@ -12,6 +12,7 @@ #include "include/Context.h" #include "common/Mutex.h" #include "common/safe_io.h" +#include "os/JournalingObjectStore.h" Finisher *finisher; Cond sync_cond; @@ -137,9 +138,11 @@ TEST(TestFileJournal, WriteSmall) { ASSERT_EQ(0, j.create()); j.make_writeable(); + list tls; bufferlist bl; bl.append("small"); - j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(1, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -165,9 +168,10 @@ TEST(TestFileJournal, WriteBig) { memset(foo, 1, sizeof(foo)); bl.append(foo, sizeof(foo)); } - j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); + list tls; + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(1, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done)); wait(); - j.close(); } } @@ -187,14 +191,15 @@ TEST(TestFileJournal, WriteMany) { C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); + list tls; bufferlist bl; bl.append("small"); uint64_t seq = 1; for (int i=0; i<100; i++) { bl.append("small"); - j.submit_entry(seq++, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(seq++, bl, orig_len, gb.new_sub()); } - gb.activate(); wait(); @@ -220,7 +225,9 @@ TEST(TestFileJournal, WriteManyVecs) { bufferlist first; first.append("small"); - j.submit_entry(1, first, 0, gb.new_sub()); + list tls; + int orig_len = j.prepare_entry(tls, &first); + j.submit_entry(1, first, orig_len, gb.new_sub()); bufferlist bl; for (int i=0; i_conf->set_val("journal_write_header_frequency", "0"); g_ceph_context->_conf->apply_changes(NULL); + list tls; + for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); fsid.generate_random(); @@ -265,11 +275,14 @@ TEST(TestFileJournal, ReplaySmall) { bufferlist bl; bl.append("small"); - j.submit_entry(1, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(1, bl, orig_len, gb.new_sub()); bl.append("small"); - j.submit_entry(2, bl, 0, gb.new_sub()); + orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(2, bl, orig_len, gb.new_sub()); bl.append("small"); - j.submit_entry(3, bl, 0, gb.new_sub()); + orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(3, bl, orig_len, gb.new_sub()); gb.activate(); wait(); @@ -306,6 +319,7 @@ TEST(TestFileJournal, ReplayCorrupt) { g_ceph_context->_conf->set_val("journal_write_header_frequency", "0"); g_ceph_context->_conf->apply_changes(NULL); + list tls; for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); fsid.generate_random(); @@ -320,13 +334,17 @@ TEST(TestFileJournal, ReplayCorrupt) { const char *newneedle = "in a haystack"; bufferlist bl; bl.append(needle); - j.submit_entry(1, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(1, bl, orig_len, gb.new_sub()); bl.append(needle); - j.submit_entry(2, bl, 0, gb.new_sub()); + orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(2, bl, orig_len, gb.new_sub()); bl.append(needle); - j.submit_entry(3, bl, 0, gb.new_sub()); + orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(3, bl, orig_len, gb.new_sub()); bl.append(needle); - j.submit_entry(4, bl, 0, gb.new_sub()); + orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(4, bl, orig_len, gb.new_sub()); gb.activate(); wait(); @@ -342,10 +360,10 @@ TEST(TestFileJournal, ReplayCorrupt) { for (unsigned o=0; o < sizeof(buf) - strlen(needle); o++) { if (memcmp(buf+o, needle, strlen(needle)) == 0) { if (n >= 2) { - cout << "replacing at offset " << o << std::endl; - memcpy(buf+o, newneedle, strlen(newneedle)); + cout << "replacing at offset " << o << std::endl; + memcpy(buf+o, newneedle, strlen(newneedle)); } else { - cout << "leaving at offset " << o << std::endl; + cout << "leaving at offset " << o << std::endl; } n++; } @@ -398,13 +416,15 @@ TEST(TestFileJournal, WriteTrim) { memset(foo, 1, sizeof(foo)); uint64_t seq = 1, committed = 0; + list tls; for (unsigned i=0; ic); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(seq++, bl, orig_len, ls.back()->c); while (ls.size() > size_mb/2) { delete ls.front(); @@ -430,6 +450,7 @@ TEST(TestFileJournal, WriteTrimSmall) { g_ceph_context->_conf->set_val("journal_ignore_corruption", "false"); g_ceph_context->_conf->set_val("journal_write_header_frequency", "0"); g_ceph_context->_conf->apply_changes(NULL); + list tls; for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); @@ -453,7 +474,8 @@ TEST(TestFileJournal, WriteTrimSmall) { bl.push_back(buffer::copy(foo, sizeof(foo) / 128)); bl.zero(); ls.push_back(new C_Sync); - j.submit_entry(seq++, bl, 0, ls.back()->c); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(seq++, bl, orig_len, ls.back()->c); while (ls.size() > size_mb/2) { delete ls.front(); @@ -478,6 +500,7 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) { g_ceph_context->_conf->set_val("journal_write_header_frequency", "1"); g_ceph_context->_conf->apply_changes(NULL); + list tls; for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); fsid.generate_random(); @@ -492,14 +515,16 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) { for (unsigned i = 1; i <= 4; ++i) { bufferlist bl; bl.append(needle); - j.submit_entry(i, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(i, bl, orig_len, gb.new_sub()); } gb.activate(); wait(); bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -532,6 +557,7 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) { g_ceph_context->_conf->set_val("journal_write_header_frequency", "1"); g_ceph_context->_conf->apply_changes(NULL); + list tls; for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); fsid.generate_random(); @@ -546,14 +572,16 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) { for (unsigned i = 1; i <= 4; ++i) { bufferlist bl; bl.append(needle); - j.submit_entry(i, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(i, bl, orig_len, gb.new_sub()); } gb.activate(); wait(); bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -586,6 +614,7 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) { g_ceph_context->_conf->set_val("journal_write_header_frequency", "1"); g_ceph_context->_conf->apply_changes(NULL); + list tls; for (unsigned i = 0 ; i < 3; ++i) { SCOPED_TRACE(subtests[i].description); fsid.generate_random(); @@ -600,14 +629,16 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) { for (unsigned i = 1; i <= 4; ++i) { bufferlist bl; bl.append(needle); - j.submit_entry(i, bl, 0, gb.new_sub()); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(i, bl, orig_len, gb.new_sub()); } gb.activate(); wait(); bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); + int orig_len = j.prepare_entry(tls, &bl); + j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close();