This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
2022-07-23 07:28:33 +00:00
|
|
|
# mdb
|
|
|
|
|
2022-07-25 05:39:16 +00:00
|
|
|
An in-process, in-memory database for Go.
|
|
|
|
|
|
|
|
## TO DO
|
|
|
|
|
2022-07-26 12:10:41 +00:00
|
|
|
* [ ] mdb: db exclusive lock
|
|
|
|
* [ ] mdb: clean up tests
|
2022-07-25 05:39:16 +00:00
|
|
|
|
|
|
|
## Structure
|
|
|
|
|
|
|
|
### Files
|
|
|
|
|
|
|
|
```
|
|
|
|
wal/<id>/data
|
|
|
|
wal/<id>/length
|
|
|
|
wal/<id>/archived
|
|
|
|
max-committed-id
|
|
|
|
write-lock
|
|
|
|
commit-lock
|
|
|
|
```
|
|
|
|
|
|
|
|
`<day-ts>` is the unix timestamp / 86400. Therefore a new segment will be
|
|
|
|
created every day. The data file is append-only, and the length is written
|
|
|
|
atomically.
|
|
|
|
|
|
|
|
`write-lock` is used by `flock` to ensure there's only one
|
|
|
|
writer. `commit-lock` is used by the commit routine. This routine will commit
|
|
|
|
data to the database and update `max-committed-id` atomically.
|
|
|
|
|
|
|
|
### Code
|
|
|
|
|
|
|
|
```
|
|
|
|
retry/
|
|
|
|
wal/
|
|
|
|
segment/
|
|
|
|
storage/
|
|
|
|
```
|
|
|
|
|
|
|
|
## WAL File Format
|
|
|
|
|
|
|
|
The WAL file consists of an 8 byte minimum ID followed by a stream of entries
|
|
|
|
of the form
|
|
|
|
|
|
|
|
```
|
|
|
|
(4) Data length
|
|
|
|
(Data length) Data
|
|
|
|
(8) ID.
|
|
|
|
```
|
|
|
|
|
|
|
|
This allows us to quickly get the min and max IDs from the file, and iterate
|
|
|
|
though the segment from the beginning.
|