# HG changeset patch # User ellis # Date 1703022415 18000 # Node ID f54f7cc7458bb5e355eecddba1ce9732f80c7d69 # Parent 0bdabb09f0056f93d92989c7d93d94d313c94acc cl-simple-example implemented, init db/tao.lisp diff -r 0bdabb09f005 -r f54f7cc7458b examples/db/cl-simple-example.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/db/cl-simple-example.lisp Tue Dec 19 16:46:55 2023 -0500 @@ -0,0 +1,63 @@ +;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c + +;; ref: https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c + +;;; Usage: + +;; To compile and run from the shell: +#| +sbcl --eval '(ql:quickload :rdb)' \ + --eval '(ql:quickload :cli)' \ + --eval '(compile-file "cl-simple-example.lisp")' \ + --eval '(load "cl-simple-example.fasl")' \ + --eval "(sb-ext:save-lisp-and-die \"cl-simple-example\" :toplevel #'cl-simple-example::main :executable t)" + +time ./cl-simple-example +|# + +;; Compare to C: +#| +# in rocksdb/examples +gcc -lrocksdb c_simple_example.c -oc_simple_example + +time ./c_simple_example +|# + +;;; Code: +(defpackage :examples/rdb/cl-simple-example + (:nicknames :cl-simple-example) + (:use :cl :std :cli :rdb :sb-alien :rocksdb) + (:export :main)) + +(rocksdb:load-rocksdb :save t) + +(in-package :cl-simple-example) + +(in-readtable :std) + +(defvar *num-cpus* (alien-funcall (extern-alien "sysconf" (function long integer)) sb-unix:sc-nprocessors-onln) + "CPU count.") + +(defparameter *db-path* "/tmp/rocksdb-cl-simple-example") + +(defparameter *db-backup-path* "/tmp/rocksdb-cl-simple-example-backup") + +(defmain () + ;; open Backup Engine that we will use for backing up our database + (let ((options + (make-rocksdb-options + (lambda (opt) + (rocksdb-options-increase-parallelism opt *num-cpus*) ;; set # of online cores + (rocksdb-options-optimize-level-style-compaction opt 0) + (rocksdb-options-set-create-if-missing opt 1))))) + (with-open-backup-engine-raw (be *db-backup-path* options) + ;; open DB + (with-open-db-raw (db *db-path* options) + ;; put key-value + (put-kv-str-raw db "key" "value") + ;; get value + (string= (get-kv-str-raw db "key") "value") + ;; create new backup in a directory specified by *db-backup-path* + (create-new-backup-raw be db)) + ;; if something is wrong, you might want to restore data from last backup + (restore-from-latest-backup-raw be *db-path* *db-backup-path*)))) diff -r 0bdabb09f005 -r f54f7cc7458b examples/db/tao.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/db/tao.lisp Tue Dec 19 16:46:55 2023 -0500 @@ -0,0 +1,13 @@ +;;; tao.lisp --- Common Lisp implementation of the TAO data model + +;; https://research.facebook.com/publications/tao-facebooks-distributed-data-store-for-the-social-graph/ + +;;; Code: +(defpackage :examples/rdb/tao + (:nicknames :tao) + (:use :cl :std :cli :rdb) + (:export :main)) + +(in-package :tao) + +(defmain ()) diff -r 0bdabb09f005 -r f54f7cc7458b examples/rdb/cl-simple-example.lisp --- a/examples/rdb/cl-simple-example.lisp Mon Dec 18 22:13:30 2023 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c - -;; https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c - -;;; Code: -(defpackage :examples/rdb/cl-simple-example - (:nicknames :cl-simple-example) - (:use :cl :std :cli :rdb) - (:export :main)) - -(in-package :cl-simple-example) - -(defmain ())