Skip to content

Commit 9dff822

Browse files
committed
Split UpdateAux constrcutors for in-memory and on-disk
1 parent 650e023 commit 9dff822

15 files changed

+71
-58
lines changed

category/mpt/cli_tool_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ struct impl_t
728728
MONAD_ASYNC_NAMESPACE::AsyncIO::
729729
MONAD_IO_BUFFERS_WRITE_SIZE);
730730
auto io = MONAD_ASYNC_NAMESPACE::AsyncIO{*pool, rwbuf};
731-
MONAD_MPT_NAMESPACE::UpdateAux<> aux(&io);
731+
MONAD_MPT_NAMESPACE::UpdateAux<> aux(io);
732732
for (;;) {
733733
auto const *item = aux.db_metadata()->fast_list_begin();
734734
if (item == nullptr) {
@@ -971,7 +971,7 @@ struct impl_t
971971
2,
972972
MONAD_ASYNC_NAMESPACE::AsyncIO::MONAD_IO_BUFFERS_READ_SIZE);
973973
auto io = MONAD_ASYNC_NAMESPACE::AsyncIO{*pool, rwbuf};
974-
MONAD_MPT_NAMESPACE::UpdateAux<> aux(&io);
974+
MONAD_MPT_NAMESPACE::UpdateAux<> aux(io);
975975
size_t slow_chunks_inserted = 0;
976976
size_t fast_chunks_inserted = 0;
977977
auto override_insertion_count =
@@ -1558,7 +1558,7 @@ opened.
15581558
MONAD_ASYNC_NAMESPACE::AsyncIO::
15591559
MONAD_IO_BUFFERS_READ_SIZE);
15601560
auto io = MONAD_ASYNC_NAMESPACE::AsyncIO{*impl.pool, rwbuf};
1561-
MONAD_MPT_NAMESPACE::UpdateAux<> aux(&io);
1561+
MONAD_MPT_NAMESPACE::UpdateAux<> aux(io);
15621562

15631563
{
15641564
cout << R"(MPT database on storages:
@@ -1604,7 +1604,7 @@ opened.
16041604
impl.cli_ask_question(ss.str().c_str());
16051605
}
16061606
aux.unset_io();
1607-
aux.set_io(&io, impl.reset_history_length);
1607+
aux.set_io(io, impl.reset_history_length);
16081608
cout << "Success! Done resetting history to "
16091609
<< impl.reset_history_length.value() << ".\n";
16101610
impl.print_db_history_summary(aux);

category/mpt/db.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Db::ROOnDiskBlocking final : public Db::Impl
166166

167167
public:
168168
explicit ROOnDiskBlocking(AsyncIOContext &io_ctx)
169-
: aux_(&io_ctx.io)
169+
: aux_(io_ctx.io)
170170
{
171171
}
172172

@@ -257,7 +257,7 @@ class Db::InMemory final : public Db::Impl
257257

258258
public:
259259
explicit InMemory(StateMachine &machine)
260-
: aux_{nullptr}
260+
: aux_{}
261261
, machine_{machine}
262262
{
263263
}
@@ -402,7 +402,7 @@ struct OnDiskWithWorkerThreadImpl
402402
ReadOnlyOnDiskDbConfig const &options)
403403
: parent(parent)
404404
, async_io(options)
405-
, aux(&async_io.io)
405+
, aux(async_io.io)
406406
{
407407
}
408408

@@ -411,7 +411,7 @@ struct OnDiskWithWorkerThreadImpl
411411
OnDiskDbConfig const &options)
412412
: parent(parent)
413413
, async_io(options)
414-
, aux{&async_io.io, options.fixed_history_length}
414+
, aux{async_io.io, options.fixed_history_length}
415415
{
416416
if (options.rewind_to_latest_finalized) {
417417
auto const latest_block_id = aux.get_latest_finalized_version();

category/mpt/find_notify_fiber.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ namespace
5353
{
5454
static constexpr bool lifetime_managed_internally = true;
5555

56-
UpdateAuxImpl *aux;
5756
inflight_map_t &inflights;
5857
Node::SharedPtr parent;
5958
chunk_offset_t rd_offset; // required for sender
@@ -62,10 +61,9 @@ namespace
6261
unsigned const branch_index;
6362

6463
find_receiver(
65-
UpdateAuxImpl &aux, inflight_map_t &inflights,
66-
Node::SharedPtr parent_, unsigned char const branch)
67-
: aux(&aux)
68-
, inflights(inflights)
64+
inflight_map_t &inflights, Node::SharedPtr parent_,
65+
unsigned char const branch)
66+
: inflights(inflights)
6967
, parent(std::move(parent_))
7068
, rd_offset(0, 0)
7169
, branch_index(parent->to_child_index(branch))
@@ -112,7 +110,7 @@ namespace
112110
{
113111
static constexpr bool lifetime_managed_internally = true;
114112

115-
UpdateAuxImpl *aux;
113+
UpdateAuxImpl &aux;
116114
NodeCache &node_cache;
117115
inflight_map_owning_t &inflights;
118116
chunk_offset_t offset;
@@ -125,7 +123,7 @@ namespace
125123
UpdateAuxImpl &aux, NodeCache &node_cache,
126124
inflight_map_owning_t &inflights, chunk_offset_t const offset,
127125
virtual_chunk_offset_t const virtual_offset)
128-
: aux(&aux)
126+
: aux(aux)
129127
, node_cache(node_cache)
130128
, inflights(inflights)
131129
, offset(offset)
@@ -154,7 +152,7 @@ namespace
154152
CacheNodeCursor start_cursor{};
155153
// verify the offset it read is still valid and has not been reused
156154
// to write new data.
157-
auto const virtual_offset_after = aux->physical_to_virtual(offset);
155+
auto const virtual_offset_after = aux.physical_to_virtual(offset);
158156
if (virtual_offset_after == virtual_offset) {
159157
{
160158
NodeCache::ConstAccessor acc;
@@ -270,7 +268,7 @@ void find_notify_fiber_future(
270268
return;
271269
}
272270
inflights[offset].emplace_back(cont);
273-
find_receiver receiver(aux, inflights, std::move(node), branch);
271+
find_receiver receiver(inflights, std::move(node), branch);
274272
detail::initiate_async_read_update(
275273
*aux.io, std::move(receiver), receiver.bytes_to_read);
276274
}

category/mpt/test/blocking_read_concurrency_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ TEST_F(DbConcurrencyTest1, version_outdated_during_blocking_find)
109109
monad::io::Buffers rwbuf{monad::io::make_buffers_for_read_only(
110110
ring, 2, AsyncIO::MONAD_IO_BUFFERS_READ_SIZE)};
111111
AsyncIO io{pool, rwbuf};
112-
monad::test::UpdateAux<void> ro_aux{&io};
112+
monad::test::UpdateAux<void> ro_aux{io};
113113

114114
int count = 0;
115115
while (!stop_token.stop_requested()) {
@@ -187,7 +187,7 @@ TEST_F(DbConcurrencyTest2, version_outdated_during_blocking_traverse)
187187
monad::io::Buffers rwbuf{monad::io::make_buffers_for_read_only(
188188
ring, 2, AsyncIO::MONAD_IO_BUFFERS_READ_SIZE)};
189189
AsyncIO io{pool, rwbuf};
190-
monad::test::UpdateAux<void> ro_aux{&io};
190+
monad::test::UpdateAux<void> ro_aux{io};
191191

192192
DummyTraverseMachine traverse{};
193193
int count = 0;

category/mpt/test/cli_tool_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct cli_tool_fixture
222222
1,
223223
monad::async::AsyncIO::MONAD_IO_BUFFERS_READ_SIZE);
224224
monad::async::AsyncIO testio(pool, testrwbuf);
225-
monad::mpt::UpdateAux<> const aux{&testio};
225+
monad::mpt::UpdateAux<> const aux{testio};
226226
monad::mpt::Node::SharedPtr root_ptr{read_node_blocking(
227227
aux,
228228
aux.get_latest_root_offset(),
@@ -325,7 +325,7 @@ struct cli_tool_fixture
325325
1,
326326
monad::async::AsyncIO::MONAD_IO_BUFFERS_READ_SIZE);
327327
monad::async::AsyncIO testio(pool, testrwbuf);
328-
monad::mpt::UpdateAux<> const aux{&testio};
328+
monad::mpt::UpdateAux<> const aux{testio};
329329
monad::mpt::Node::SharedPtr root_ptr{read_node_blocking(
330330
aux,
331331
aux.get_latest_root_offset(),

category/mpt/test/db_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ TEST(DbTest, history_length_adjustment_never_under_min)
846846
monad::io::Buffers read_buffers = monad::io::make_buffers_for_read_only(
847847
read_ring, 128, monad::async::AsyncIO::MONAD_IO_BUFFERS_READ_SIZE);
848848
monad::async::AsyncIO io_ctx(pool, read_buffers);
849-
UpdateAux aux_reader{&io_ctx};
849+
UpdateAux aux_reader{io_ctx};
850850

851851
auto batch_upsert_once = [&](uint64_t const version) {
852852
UpdateList ls;
@@ -2090,7 +2090,7 @@ TEST_F(OnDiskDbWithFileFixture, history_ring_buffer_wrap_around)
20902090
monad::io::Buffers robuf = monad::io::make_buffers_for_read_only(
20912091
ring, 2, monad::async::AsyncIO::MONAD_IO_BUFFERS_READ_SIZE);
20922092
monad::async::AsyncIO testio(pool_ro, robuf);
2093-
monad::mpt::UpdateAux<> aux_reader{&testio};
2093+
monad::mpt::UpdateAux<> aux_reader{testio};
20942094
return aux_reader.root_offsets().capacity();
20952095
}();
20962096
std::cout << root_offsets_ring_capacity << std::endl;

category/mpt/test/load_all_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct LoadAllTest
3131

3232
TEST_F(LoadAllTest, works)
3333
{
34-
monad::test::UpdateAux<void> aux{&state()->io};
34+
monad::test::UpdateAux<void> aux{state()->io};
3535
monad::test::StateMachineAlwaysMerkle sm;
3636
monad::mpt::Node::SharedPtr root{monad::mpt::read_node_blocking(
3737
state()->aux,

category/mpt/test/mixed_async_sync_loads_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace
5656
TEST_F(MixedAsyncSyncLoadsTest, works)
5757
{
5858
// Make a new empty DB
59-
monad::test::UpdateAux<void> aux{&state()->io};
59+
monad::test::UpdateAux<void> aux{state()->io};
6060
monad::test::StateMachineAlwaysMerkle sm;
6161
// Load its root
6262
auto const latest_version = aux.db_history_max_version();

category/mpt/test/monad_trie_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,7 @@ int main(int argc, char *argv[])
530530
}
531531
};
532532

533-
auto aux =
534-
in_memory ? UpdateAux<>() : UpdateAux<>(&io, history_len);
533+
auto aux = in_memory ? UpdateAux<>() : UpdateAux<>(io, history_len);
535534
monad::test::StateMachineMerkleWithPrefix<prefix_len> sm{};
536535

537536
Node::SharedPtr root{};
@@ -679,7 +678,7 @@ int main(int argc, char *argv[])
679678
Node::SharedPtr &root = std::get<1>(*ret);
680679
NodeCursor &state_start = std::get<2>(*ret);
681680
if (!in_memory) {
682-
aux.set_io(&io, history_len);
681+
aux.set_io(io, history_len);
683682
}
684683
root = read_node_blocking(
685684
aux,

category/mpt/test/node_writer_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct NodeWriterTestBase : public ::testing::Test
8484
ring1, ring2, 2, 4, AsyncIO::MONAD_IO_BUFFERS_READ_SIZE,
8585
AsyncIO::MONAD_IO_BUFFERS_WRITE_SIZE)}
8686
, io{pool, rwbuf}
87-
, aux{&io}
87+
, aux{io}
8888
{
8989
}
9090

0 commit comments

Comments
 (0)