README + prevent data inconsistency on db/add.

draft
Philippe PITTOLI 2022-10-14 17:48:48 +02:00
parent b29badbad0
commit 94d522e778
2 changed files with 27 additions and 15 deletions

View File

@ -6,6 +6,12 @@ When storing simple files directly on the file-system is enough.
This project is a work in progress.
# Constraints (WIP)
TODO:
- parallelism: run dodb on several threads (solved by a locking system)
- fs data integrity: in case of a crash, dodb won't corrupt data on disk (solved by a temp file on the same filesystem, then a simple mv)
# Crystal version
Follow [this link for the Crystal version of DODB][dodbcr].

View File

@ -62,8 +62,6 @@
(setf current-index id))
(setf (gethash id data) value)))
(format t "Max current index: ~A~&" current-index)
(make-db
:struct-name struct-name
:path path
@ -172,7 +170,7 @@
(db-data database)))
; Example: database -> "000000000000018".
(defun db/add/new-data-filename (database)
(defun db/add/new-data-basename (database)
(number->filename (db-current-index database)))
; Example: {db-path}/data/000000000000018
@ -181,20 +179,23 @@
(defun db/add (database object)
(incf (db-current-index database))
(let ((file-name (db/add/new-data-filename database)))
(let* ((file-basename (db/add/new-data-basename database))
(tmp-file-basename (concatenate 'string file-basename "_tmp"))
(tmp-file-path (get-filepath database tmp-file-basename)))
; write object to file
(util:write-object-to-file
object
(get-filepath database file-name))
; write object to temporary file
(util:write-object-to-file object tmp-file-path)
; rename the temporary file
(rename-file tmp-file-path file-basename)
; handle indexes
(loop for index in (db-indexes database)
do (db/index/new database index object file-name))
do (db/index/new database index object file-basename))
; handle partitions
(loop for partition in (db-partitions database)
do (db/partition/new database partition object file-name)))
do (db/partition/new database partition object file-basename)))
; store new in-memory data
; database.data[database.current-index] = object
@ -249,6 +250,11 @@
(alias db/get-by-index db/search/fs/get-by-index)
(alias db/get-by-partition db/search/fs/get-by-partition)
;(defun db/update (database object-index)
; (let ((object (gethash object-index (db-data database))))
; ; TODO: write the object on the FS
; ))
;
; TEST SCENARIO
;
@ -257,11 +263,11 @@
(defparameter cars (db/new "vehicle" "./storage/cars/"))
;(db/add cars (make-vehicle :name "Corvet" :color "Red"))
;(db/add cars (make-vehicle :name "Ferrari" :color "Red"))
;(db/add cars (make-vehicle :name "Deudeuch" :color "Beige"))
;(db/add cars (make-vehicle :name "BMW" :color "Blue"))
;(db/add cars (make-vehicle :name "Suzuki Wagon" :color "Blue"))
(db/add cars (make-vehicle :name "Corvet" :color "Red"))
(db/add cars (make-vehicle :name "Ferrari" :color "Red"))
(db/add cars (make-vehicle :name "Deudeuch" :color "Beige"))
(db/add cars (make-vehicle :name "BMW" :color "Blue"))
(db/add cars (make-vehicle :name "Suzuki Wagon" :color "Blue"))
(db/new-index cars "name")
(db/new-partition cars "color")