开发者

Highly reliable storage for a 'log' / time series

开发者 https://www.devze.com 2023-02-14 00:41 出处:网络
In an application I\'m wor开发者_开发百科king on, I need a write-behind data log. That is, the application accumulates data in memory, and can hold all the data in memory. It must, however, persist, t

In an application I'm wor开发者_开发百科king on, I need a write-behind data log. That is, the application accumulates data in memory, and can hold all the data in memory. It must, however, persist, tolerate reasonable faults, and allow for backup.

Obviously, I could write to a SQL database; Derby springs to mind for easy embedding. I'm not tremendously fond of the dealing with a SQL API (JDBC however lipsticked) and I don't need any queries, indices, or other decoration. The records go out, and on restart, I need to read them all back.

Are there any other suitable alternatives?


Try using a just a simple log file.

As data comes in, store in memory and write (append) to a file. write() followed by fsync() will guarantee (on most systems, read your system and filesystem docs carefully) that the data is written to persistent storage (disc). These are the same mechanisms any database engine would use to get data in persistent storage.

On restart, reload the log. Occasionally, trim the front of the log file so data usage doesn't grow infinitely. Or, model the log file as a circular buffer the same size as what you can hold in memory.


Have you looked at (now Oracle) Berkeley DB for Java? The "Direct Persistence Layer" is actually quite simple to use. Docs here for DPL.

Has different options for backups comes with a few utilities. Runs embedded.

(Licensing: a form of the BSD License I beleive.)

0

精彩评论

暂无评论...
验证码 换一张
取 消