QcChunkIo Class
Reading and writing the chunks of a world in the background (decision E-373), so the server tick never waits for the disk: one thread owns the QcChunkStore and runs every request in the order it was made, so a chunk read after it was handed over for writing gets what was handed over. More...
| Header: | #include <server/storage/QcChunkIo.h> |
Public Types
| struct | Arrival |
| struct | Departure |
| struct | SaveResult |
| Preparation |
Public Functions
| QcChunkIo(const QcChunkIo &) | |
| QcChunkIo(QcChunkIo &&) | |
| const std::optional<QcChunkStore::Damaged> & | damaged() const |
| bool | hasDirectory() const |
| void | keep(QcChunkIo::Departure departure) |
| QcResult<QHash<QcChunkPos, QcChunkStore::Stored>> | open() |
| const QStringList & | openWarnings() const |
| qsizetype | pendingChunks() const |
| void | read(QcChunkPos pos, quint64 request) |
| QcResult<std::optional<QByteArray>> | readFileNow(const QString &name) |
| QcChunkIo::Arrival | readNow(QcChunkPos pos) |
| quint64 | save(QList<QcChunkIo::Departure> chunks, QList<QcChunkStore::WholeFile> files) |
| void | setBlockEntityLimit(quint32 limit) |
| void | setPreparation(QcChunkIo::Preparation prepare) |
| std::vector<QcChunkIo::Arrival> | takeArrivals() |
| std::vector<QcChunkIo::SaveResult> | takeSaves() |
| void | waitForIdle() |
| QcChunkIo & | operator=(QcChunkIo &&) |
| QcChunkIo & | operator=(const QcChunkIo &) |
Detailed Description
Encoding and decoding happen there too. The tick collects finished reads and saves (takeArrivals, takeSaves). Without a directory the store keeps everything in memory.
Member Type Documentation
[alias] QcChunkIo::Preparation
Called on the I/O thread with every chunk read in the background that has blocks, before it is handed over (the world prepares its light). Set before the first read.
Member Function Documentation
[delete] QcChunkIo::QcChunkIo(const QcChunkIo &)
Copy-constructs an instance of QcChunkIo. This function is deleted.
[delete] QcChunkIo::QcChunkIo(QcChunkIo &&)
Move-constructs an instance of QcChunkIo. This function is deleted.
const std::optional<QcChunkStore::Damaged> &QcChunkIo::damaged() const
Returns the file open() failed on; std::nullopt when it did not.
bool QcChunkIo::hasDirectory() const
Returns whether the chunks are written to a directory (else kept in memory).
void QcChunkIo::keep(QcChunkIo::Departure departure)
Hands over departure, what is kept of a chunk; it is written with the next save.
QcResult<QHash<QcChunkPos, QcChunkStore::Stored>> QcChunkIo::open()
Opens the store (before any request; see QcChunkStore::open). Returns what it holds, or the error.
const QStringList &QcChunkIo::openWarnings() const
Returns the warnings of open() for the player (QcChunkStore::openWarnings).
qsizetype QcChunkIo::pendingChunks() const
Returns the chunks handed over and not yet written (as of the last finished request).
void QcChunkIo::read(QcChunkPos pos, quint64 request)
Reads the chunk pos in the background for request; the result comes from takeArrivals(). A read goes before the writing work waiting in the queue unless the chunk itself is among it.
QcResult<std::optional<QByteArray>> QcChunkIo::readFileNow(const QString &name)
Returns the whole file name of the world (a player file) as the latest save handed it over or as it is on disk (none: no such file), or the error; waits only for itself. Tick thread.
QcChunkIo::Arrival QcChunkIo::readNow(QcChunkPos pos)
Reads the chunk pos and waits for it (spawn, commands, tests). Returns what was read; it goes before the waiting writing work unless the chunk is still being handed over, and waits only for itself.
quint64 QcChunkIo::save(QList<QcChunkIo::Departure> chunks, QList<QcChunkStore::WholeFile> files)
Hands over chunks of a save and writes everything handed over so far with files, the whole files of the save (QcChunkStore::commit). Returns the id the result comes with from takeSaves().
void QcChunkIo::setBlockEntityLimit(quint32 limit)
Test hook: limit is the bytes a chunk's block entities may take (QcBlockEntityCodec::encodeWithin; QcRegionFile::maxBlobBytes otherwise). Set before the first request.
void QcChunkIo::setPreparation(QcChunkIo::Preparation prepare)
Sets prepare as the preparation of every chunk read in the background.
std::vector<QcChunkIo::Arrival> QcChunkIo::takeArrivals()
Returns the chunks read in the background since the last call; tick thread.
std::vector<QcChunkIo::SaveResult> QcChunkIo::takeSaves()
Returns the saves finished since the last call; tick thread.
void QcChunkIo::waitForIdle()
Waits until every request so far is done.
[delete] QcChunkIo &QcChunkIo::operator=(QcChunkIo &&)
Move-assigns other to this QcChunkIo instance. This function is deleted.
[delete] QcChunkIo &QcChunkIo::operator=(const QcChunkIo &)
Copy-assigns other to this QcChunkIo instance. This function is deleted.