|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
适用于最小写入单元受限的 Flash 存储的数据库实现 Database implementation for Flash storage with minimum write unit restrictions. More...
#include <raw.hpp>
Public Member Functions | |
| ErrorCode | Get (Database::KeyBase &key) override |
DatabaseRaw 的对外生命周期入口区域 / Public lifecycle entry section of DatabaseRaw | |
| ErrorCode | Set (KeyBase &key, RawData data) override |
| 设置数据库中的键值 Set the key's value in the database. | |
| ErrorCode | Add (KeyBase &key) override |
| 添加新键到数据库 / Add a new key to the database. | |
| DatabaseRaw (Flash &flash, size_t recycle_threshold=128) | |
| 构造函数,初始化 Flash 存储和缓冲区 Constructor to initialize Flash storage and buffer. | |
| void | Init () |
| 初始化数据库存储区,确保主备块正确 Initialize database storage, ensuring main and backup blocks are valid. | |
| void | Restore () |
| 还原存储数据,清空 Flash 区域 Restore storage data, clearing Flash memory area. | |
| ErrorCode | Recycle () |
| 回收 Flash 空间,整理数据 Recycle Flash storage space and organize data. | |
适用于最小写入单元受限的 Flash 存储的数据库实现 Database implementation for Flash storage with minimum write unit restrictions.
此类提供适用于 Flash 存储的键值存储管理,该存储要求数据以固定大小块写入。 This class provides key-value storage management for Flash memory that requires data to be written in fixed-size blocks.
REQUIRE。 If the underlying Flash read, write, or erase operation fails, the current implementation treats it as an unrecoverable fault and triggers REQUIRE immediately.
|
inlineexplicit |
构造函数,初始化 Flash 存储和缓冲区 Constructor to initialize Flash storage and buffer.
| flash | 目标 Flash 存储设备 / Target Flash storage device. |
| recycle_threshold | 回收阈值 / Recycle threshold. |
Definition at line 71 of file raw.hpp.
|
inlineoverridevirtual |
添加新键到数据库 / Add a new key to the database.
| key | 需要添加的键 / Key to add. |
Implements LibXR::Database.
|
inlineoverridevirtual |
DatabaseRaw 的对外生命周期入口区域 / Public lifecycle entry section of DatabaseRaw
DatabaseRaw 的生命周期与主流程片段 / Lifecycle and main-flow fragment of DatabaseRaw
获取数据库中的键值 Retrieve the key's value from the database.
| key | 需要获取的键 / Key to retrieve. |
ErrorCode::OK,否则返回 ErrorCode::NOT_FOUND Operation result, returns ErrorCode::OK if found, otherwise ErrorCode::NOT_FOUND. Implements LibXR::Database.
Definition at line 21 of file raw.hpp.
|
inline |
初始化数据库存储区,确保主备块正确 Initialize database storage, ensuring main and backup blocks are valid.
IsBackupComplete()),回收是在重写主块 期间或前后被打断的,主块可能只擦了一部分,因此以备份块为准恢复主块;主块无效时 也接受旧版本留下的完整备份块;否则相信有效的主块,主块无效时初始化为空块。仍有 键的其他备份块重新准备,不再作为恢复来源。最后检查主块链表,修复掉电留下的状态。 When the backup is the complete copy written by a recycle (see IsBackupComplete()), that recycle was cut while, just before, or just after it rewrote the main block, which may be partly erased, so the main block is restored from the backup; an invalid main block also accepts a complete backup left by older versions; otherwise a valid main block is trusted and an invalid one is initialized empty. Any other backup that still holds keys is prepared again and is no longer a recovery source. The main chain is then checked and repaired after a power loss. Definition at line 97 of file raw.hpp.
|
inline |
回收 Flash 空间,整理数据 Recycle Flash storage space and organize data.
将主存储块中的有效键移动到备份块,并擦除主存储块。 Moves valid keys from the main block to the backup block and erases the main block.
ErrorCode::FULL Operation result; when the compacted keys plus the CRC unit do not fit, nothing is written and ErrorCode::FULL is returned. Definition at line 159 of file raw.hpp.
|
inline |
还原存储数据,清空 Flash 区域 Restore storage data, clearing Flash memory area.
Definition at line 129 of file raw.hpp.
|
inlineoverridevirtual |
设置数据库中的键值 Set the key's value in the database.
| key | 目标键 / Target key. |
| data | 需要存储的新值 / New value to store. |
Implements LibXR::Database.