diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2021-08-27 19:22:51 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2021-08-27 21:35:05 -0700 |
commit | e7d4b13994b5255eaef0135905b017ba357370c1 (patch) | |
tree | c58985faadbea38949b6d5d8267ef86fd93c3322 /src/journals.h | |
parent | 02aa67ba96680f278158385762c7d5a7964f179f (diff) |
journals: implement rudimentary read buffers
This adds eight 8KiB "fixed" buffers per opened journal,
recycled in a basic LRU fashion.
Any read 8KiB or smaller passes through this cache, simply
memcpy()d from the buffer when already resident, or upsized to an
8KiB read when absent, to then be memcpy()d out of the populated
buffer when the read into the buffer completes.
Any read larger than 8KiB bypasses the buffers to be read
directly into the provided destination via iou as if the cache
weren't present at all.
Diffstat (limited to 'src/journals.h')
-rw-r--r-- | src/journals.h | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/journals.h b/src/journals.h index 84c7a0f..1327a5e 100644 --- a/src/journals.h +++ b/src/journals.h @@ -13,14 +13,29 @@ #include "upstream/journal-def.h" -typedef struct iou_t iou_t; - -typedef struct journal_t { - char *name; - int fd, idx; -} journal_t; +/* TODO: the journal buf stuff should be made private to journals.c */ +#define JOURNAL_BUF_SIZE 8192 +#define JOURNAL_BUF_CNT 8 +typedef struct iou_t iou_t; typedef struct journals_t journals_t; +typedef struct journal_t journal_t; +typedef struct journal_buf_t journal_buf_t; + +struct journal_buf_t { + journal_buf_t *lru_prev, *lru_next; + uint64_t offset, length; + unsigned valid:1; + int idx; + uint8_t data[JOURNAL_BUF_SIZE]; +}; + +struct journal_t { + char *name; + int fd, idx; + journal_buf_t *lru_head, *lru_tail; + journal_buf_t bufs[JOURNAL_BUF_CNT]; +}; THUNK_DECLARE(journals_open, iou_t *, iou, char **, machid, int, flags, journals_t **, journals, thunk_t *, closure); THUNK_DECLARE(journal_get_header, iou_t *, iou, journal_t **, journal, Header *, header, thunk_t *, closure); @@ -40,4 +55,6 @@ THUNK_DECLARE(journals_for_each, journals_t **, journals, journal_t **, journal_ const char * journal_object_type_str(ObjectType type); const char * journal_state_str(JournalState state); +int journal_read(iou_t *iou, journal_t *journal, uint64_t offset, uint64_t length, void *dest, thunk_t *closure); + #endif |