I’m working on an app that needs an append-only file type. I believe the following algorithm will work, but I’m wondering if there is a better way. It looks something like this:
Start with a pointer to a scratchpad type. The first 4MB if data is written to the scratchpad by the user app.
Once a write will overflow the scratchpad:
- The scratchpad contents are written to a new chunk
- Any overflowed data is written into the scratchpad
- A graphEntry type is created pointing to the newly created chunk and the scratchpad
- The pointer is updated to point to the graphEntry
This continues and each time the scratchpad overflows, a new chunk is written out, a new graphEntry is created, and the pointer is updated to reference the new graphEntry.
Now my question is how best to handle the graphEntry to point to all the chunks? I see multiple possiblities:
- Each new chunk creates a new graphEntry that points to the new chunk and the previous graphEntry. This would be the cheapest from a write standpoint, but slowest to read since you have to iteratively pull each graphEntry to build the full list.
- Each new chunk creates a new graphEntry that points to all previous chunks and the scratchpad. Most expensive write, fastest read.
- Hybrid of the 2 and create a new iterative graphEntry up to a fixed number, say 20 chunks, and then reference these 20 chunk graphEntries. This could be scaled for the best tradeoff of price vs performance.
Is this the right way to go about this? If so, which approach should I choose? Or am I just making this harder than it needs to be?