# What's the usage of messageBlocks in LogData strucuture?

**URL:** <https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949>\
**Category:** FoundationDB Core\
**Created:** [October 17, 2021, 3:40am UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949 "2021-10-17T03:40:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [October 17, 2021, 3:40am UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/1 "2021-10-17T03:40:26Z")

</div>

According to [link](https://github.com/apple/foundationdb/blob/87f46ccb00d1cfd432808d57ba386f216834e148/fdbserver/TLogServer.actor.cpp#L517), LogData has a messageBlocks member, which will copy the StringRef messages from `LogCommitRequest` in a block ([link](https://github.com/apple/foundationdb/blob/87f46ccb00d1cfd432808d57ba386f216834e148/fdbserver/TLogServer.actor.cpp#L1404-L1519)), but as I read the code, this member seems to have nothing to do with durability, as it is handled by [TLogQueueEntryRef](https://github.com/apple/foundationdb/blob/87f46ccb00d1cfd432808d57ba386f216834e148/fdbserver/TLogServer.actor.cpp#L52), it’s used only for some statistics of the size of messages. Is this not a waste of memory to copy messages, while the only usage is to get the statistics of their sizes?

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [October 17, 2021, 5:53pm UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/2 "2021-10-17T17:53:09Z")

</div>

`messageBlocks` is used to send messages to storage servers quickly. In the steady state, tlogs keep two copies of data: one in memory and one on disk. This way reading is fast. It’s a bit like an in-memory database. The disk queue is only used to recover this data if the process restarts. If the tlog queue grows (usually due to some storage server failures and them therefore not popping) it will eventually start spilling and write an index for the queued data to disk.

---

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [October 19, 2021, 11:57am UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/3 "2021-10-19T11:57:57Z")

</div>

@markus.pilman One more question, what’s the policy to erase the `memoryBlocks`? will fdb consider about storage server read speed? Like if storage server havent read those `memoryBlocks` the log server will keep them longer, or it just erase them after those blocks are durable on disk?

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [October 19, 2021, 3:26pm UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/4 "2021-10-19T15:26:22Z")

</div>

It only uses memory pressure. Usually storages don’t fall this far behind because they’re slow. The reason we spill is usually because a number of storage servers have failed and therefore don’t read from tlogs at all – but in theory it could be due to a very slow storage server.

It’s also not about durability: the data is written to disk immediately. The only thing we write when we spill is an index into the log file for faster from-disk reading.

---

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [October 19, 2021, 3:33pm UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/5 "2021-10-19T15:33:26Z")

</div>

but it seems that [link](https://github.com/apple/foundationdb/blob/063cae88020310b7395b49e52bddb7848a45d129/fdbserver/TLogServer.actor.cpp#L1106-L1113), `messageBlocks` simply got erased in `updateStorage` method. I didnt find anything related to memory. @markus.pilman

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [October 19, 2021, 8:23pm UTC](https://forums.foundationdb.org/t/whats-the-usage-of-messageblocks-in-logdata-strucuture/2949/6 "2021-10-19T20:23:18Z")

</div>

`updateStorage` is also called for spilling. Though I have to admit I am not familiar enough with that particular code to go into detail.
