diff --git a/block.tcc b/block.tcc index 1979bd2..16c1f7a 100644 --- a/block.tcc +++ b/block.tcc @@ -112,9 +112,10 @@ block_manager::write_lock_zero(block_address location) buffer buf; zero_buffer(buf); + register_lock(location, WRITE_LOCK); typename block::ptr b(new block(location, buf, lock_count_, ordinary_count_), bind(&block_manager::write_release, this, _1)); - register_lock(location, WRITE_LOCK); + return write_ref(b); } diff --git a/block_t.cc b/block_t.cc index 2e68a24..c42c13e 100644 --- a/block_t.cc +++ b/block_t.cc @@ -92,7 +92,6 @@ BOOST_AUTO_TEST_CASE(different_block_sizes) BOOST_CHECK_EQUAL(sizeof(rr.data()), 4096); } - { block_manager<64 * 1024> bm("./test.data", 64); auto rr = bm.read_lock(0); diff --git a/space_map_disk_t.cc b/space_map_disk_t.cc index 015ec60..ea8729f 100644 --- a/space_map_disk_t.cc +++ b/space_map_disk_t.cc @@ -11,7 +11,7 @@ using namespace persistent_data; //---------------------------------------------------------------- namespace { - block_address const NR_BLOCKS = 1023; + block_address const NR_BLOCKS = 10237; block_address const SUPERBLOCK = 0; unsigned const BLOCK_SIZE = 4096; @@ -105,4 +105,18 @@ BOOST_AUTO_TEST_CASE(test_set_count) BOOST_CHECK_EQUAL(sm->get_count(43), 5); } +BOOST_AUTO_TEST_CASE(test_set_effects_nr_allocated) +{ + auto sm = create_sm_disk(); + for (unsigned i = 0; i < NR_BLOCKS; i++) { + sm->set_count(i, 1); + BOOST_CHECK_EQUAL(sm->get_nr_free(), NR_BLOCKS - i - 1); + } + + for (unsigned i = 0; i < NR_BLOCKS; i++) { + sm->set_count(i, 0); + BOOST_CHECK_EQUAL(sm->get_nr_free(), i + 1); + } +} + //---------------------------------------------------------------- diff --git a/transaction_manager_t.cc b/transaction_manager_t.cc index 08b4ecb..657fa5d 100644 --- a/transaction_manager_t.cc +++ b/transaction_manager_t.cc @@ -18,6 +18,7 @@ namespace { block_manager<4096>::ptr bm(new block_manager<4096>("./test.data", NR_BLOCKS)); space_map::ptr sm(new core_map(NR_BLOCKS)); transaction_manager<4096>::ptr tm(new transaction_manager<4096>(bm, sm)); + tm->get_sm()->inc(0); return tm; } } @@ -37,20 +38,29 @@ BOOST_AUTO_TEST_CASE(shadowing) auto sm = tm->get_sm(); sm->inc(1); - auto p = tm->shadow(1); - auto b = p.first.get_location(); - BOOST_CHECK(b != 1); - BOOST_CHECK(!p.second); - BOOST_CHECK(sm->get_count(1) == 0); + block_address b; - p = tm->shadow(b); - BOOST_CHECK(p.first.get_location() == b); - BOOST_CHECK(!p.second); + { + auto p = tm->shadow(1); + b = p.first.get_location(); + BOOST_CHECK(b != 1); + BOOST_CHECK(!p.second); + BOOST_CHECK(sm->get_count(1) == 0); + } + + { + auto p = tm->shadow(b); + BOOST_CHECK(p.first.get_location() == b); + BOOST_CHECK(!p.second); + } sm->inc(b); - p = tm->shadow(b); - BOOST_CHECK(p.first.get_location() != b); - BOOST_CHECK(p.second); + + { + auto p = tm->shadow(b); + BOOST_CHECK(p.first.get_location() != b); + BOOST_CHECK(p.second); + } } BOOST_AUTO_TEST_CASE(multiple_shadowing)