QcChunkStore Class
The chunks of a world on disk (decision E-373): per kind (blocks, block entities, entities) one indexed region file per region (QcRegionFile), read chunk by chunk when a chunk is needed. More...
| Header: | #include <server/storage/QcChunkStore.h> |
Public Types
| struct | Blobs |
| struct | Damaged |
| struct | Stored |
| struct | WholeFile |
| enum class | Kind { Blocks, BlockEntities, Entities } |
Public Functions
| QHash<QcChunkPos, QcChunkStore::Stored> | catalog() const |
| QcStatus | commit(const QList<QcChunkStore::WholeFile> &files) |
| const std::optional<QcChunkStore::Damaged> & | damaged() const |
| const QString & | directory() const |
| void | failRenamesAfter(int count) |
| const QcGeneratedChunks & | generated() const |
| const QString & | generatedFile() const |
| bool | has(QcChunkStore::Kind kind, QcChunkPos chunk) const |
| void | noteGenerated(QcChunkPos chunk) |
| QcStatus | open() |
| const QStringList & | openWarnings() const |
| qsizetype | pendingChunks() const |
| void | put(QcChunkStore::Kind kind, QcChunkPos chunk, std::optional<QByteArray> blob, quint16 marks = 0) |
| QcResult<QcChunkStore::Blobs> | read(QcChunkPos chunk) |
| QcResult<std::optional<QByteArray>> | readFile(const QString &name) |
Static Public Members
| QString | extensionOf(QcChunkStore::Kind kind) |
| QString | folderOf(QcChunkStore::Kind kind) |
| const QStringView | journalName |
| const int | kindCount |
Detailed Description
What is handed over for writing waits in memory (put) until the next commit, which writes every changed region and the world's other files of a save as one: all files first under a staging name, then a journal naming them, then the renames, then the journal goes. A save that breaks off before the journal leaves the previous save whole; one that breaks off after it is finished when the world opens again (open()). Without a directory nothing is written and everything stays in memory. Not thread-safe: QcChunkIo uses it from its one thread.
Member Type Documentation
enum class QcChunkStore::Kind
The kinds of data of a chunk, each in its own region files.
| Constant | Value | Description |
|---|---|---|
QcChunkStore::Kind::Blocks | 0 | The blocks (QcChunkCodec). |
QcChunkStore::Kind::BlockEntities | 1 | The block entities (QcBlockEntityCodec). |
QcChunkStore::Kind::Entities | 2 | The entities (QcEntityCodec). |
Member Function Documentation
QHash<QcChunkPos, QcChunkStore::Stored> QcChunkStore::catalog() const
Returns every chunk with data, on disk or waiting to be written.
QcStatus QcChunkStore::commit(const QList<QcChunkStore::WholeFile> &files)
Writes everything handed over and files as one save (see the class); returns an error on failure. Then nothing handed over is lost, the files included: it waits for the next commit.
const std::optional<QcChunkStore::Damaged> &QcChunkStore::damaged() const
Returns the file open() failed on; std::nullopt when it did not.
const QString &QcChunkStore::directory() const
Returns the world directory; empty when everything stays in memory.
[static] QString QcChunkStore::extensionOf(QcChunkStore::Kind kind)
Returns the file extension of the region files of kind ("qcr", "qcb", "qen").
void QcChunkStore::failRenamesAfter(int count)
Test hook: renames of a commit after count fail (-1: none fail).
[static] QString QcChunkStore::folderOf(QcChunkStore::Kind kind)
Returns the folder of the region files of kind ("regions", "blockentities", "entities").
const QcGeneratedChunks &QcChunkStore::generated() const
Returns the index of generated chunks: what open() read, with what was noted since.
const QString &QcChunkStore::generatedFile() const
Returns the file (relative to the directory) the next commit writes the index to.
bool QcChunkStore::has(QcChunkStore::Kind kind, QcChunkPos chunk) const
Returns whether data of kind of chunk is on disk or waiting to be written.
void QcChunkStore::noteGenerated(QcChunkPos chunk)
Adds chunk to the index of generated chunks (QcGeneratedChunks), written with the next commit that follows.
QcStatus QcChunkStore::open()
Finishes a save the journal names, removes staged files of a save that broke off and reads the index of every region file. Returns an error naming the file for a damaged index or a file of an older version (damaged()).
const QStringList &QcChunkStore::openWarnings() const
Returns the warnings of the last open() for the player (a damaged or newer index).
qsizetype QcChunkStore::pendingChunks() const
Returns the largest number of chunks of one kind with data waiting for the next commit (not the number of distinct chunks).
void QcChunkStore::put(QcChunkStore::Kind kind, QcChunkPos chunk, std::optional<QByteArray> blob, quint16 marks = 0)
Hands over blob, the data of kind of chunk, for the next commit (none: the chunk has no data of that kind any more). marks counts for block entities only.
QcResult<QcChunkStore::Blobs> QcChunkStore::read(QcChunkPos chunk)
Returns the data of chunk: what waits to be written, else what is on disk. A blob that fails its check is an error.
QcResult<std::optional<QByteArray>> QcChunkStore::readFile(const QString &name)
Returns the whole file name as the next commit writes it (waiting) or as it is on disk; none: no such file.
Member Variable Documentation
const QStringView QcChunkStore::journalName
Name of the journal of a save in the world directory.
const int QcChunkStore::kindCount
The number of kinds.