changeset 35: |
f54f7cc7458b |
parent 34: |
0bdabb09f005 |
child 36: |
0f678bfd8699 |
author: |
ellis <ellis@rwest.io> |
date: |
Tue, 19 Dec 2023 16:46:55 -0500 |
files: |
examples/db/cl-simple-example.lisp examples/db/tao.lisp examples/rdb/cl-simple-example.lisp |
description: |
cl-simple-example implemented, init db/tao.lisp |
1.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2+++ b/examples/db/cl-simple-example.lisp Tue Dec 19 16:46:55 2023 -0500
1.3@@ -0,0 +1,63 @@
1.4+;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c
1.5+
1.6+;; ref: https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c
1.7+
1.8+;;; Usage:
1.9+
1.10+;; To compile and run from the shell:
1.11+#|
1.12+sbcl --eval '(ql:quickload :rdb)' \
1.13+ --eval '(ql:quickload :cli)' \
1.14+ --eval '(compile-file "cl-simple-example.lisp")' \
1.15+ --eval '(load "cl-simple-example.fasl")' \
1.16+ --eval "(sb-ext:save-lisp-and-die \"cl-simple-example\" :toplevel #'cl-simple-example::main :executable t)"
1.17+
1.18+time ./cl-simple-example
1.19+|#
1.20+
1.21+;; Compare to C:
1.22+#|
1.23+# in rocksdb/examples
1.24+gcc -lrocksdb c_simple_example.c -oc_simple_example
1.25+
1.26+time ./c_simple_example
1.27+|#
1.28+
1.29+;;; Code:
1.30+(defpackage :examples/rdb/cl-simple-example
1.31+ (:nicknames :cl-simple-example)
1.32+ (:use :cl :std :cli :rdb :sb-alien :rocksdb)
1.33+ (:export :main))
1.34+
1.35+(rocksdb:load-rocksdb :save t)
1.36+
1.37+(in-package :cl-simple-example)
1.38+
1.39+(in-readtable :std)
1.40+
1.41+(defvar *num-cpus* (alien-funcall (extern-alien "sysconf" (function long integer)) sb-unix:sc-nprocessors-onln)
1.42+ "CPU count.")
1.43+
1.44+(defparameter *db-path* "/tmp/rocksdb-cl-simple-example")
1.45+
1.46+(defparameter *db-backup-path* "/tmp/rocksdb-cl-simple-example-backup")
1.47+
1.48+(defmain ()
1.49+ ;; open Backup Engine that we will use for backing up our database
1.50+ (let ((options
1.51+ (make-rocksdb-options
1.52+ (lambda (opt)
1.53+ (rocksdb-options-increase-parallelism opt *num-cpus*) ;; set # of online cores
1.54+ (rocksdb-options-optimize-level-style-compaction opt 0)
1.55+ (rocksdb-options-set-create-if-missing opt 1)))))
1.56+ (with-open-backup-engine-raw (be *db-backup-path* options)
1.57+ ;; open DB
1.58+ (with-open-db-raw (db *db-path* options)
1.59+ ;; put key-value
1.60+ (put-kv-str-raw db "key" "value")
1.61+ ;; get value
1.62+ (string= (get-kv-str-raw db "key") "value")
1.63+ ;; create new backup in a directory specified by *db-backup-path*
1.64+ (create-new-backup-raw be db))
1.65+ ;; if something is wrong, you might want to restore data from last backup
1.66+ (restore-from-latest-backup-raw be *db-path* *db-backup-path*))))
2.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2+++ b/examples/db/tao.lisp Tue Dec 19 16:46:55 2023 -0500
2.3@@ -0,0 +1,13 @@
2.4+;;; tao.lisp --- Common Lisp implementation of the TAO data model
2.5+
2.6+;; https://research.facebook.com/publications/tao-facebooks-distributed-data-store-for-the-social-graph/
2.7+
2.8+;;; Code:
2.9+(defpackage :examples/rdb/tao
2.10+ (:nicknames :tao)
2.11+ (:use :cl :std :cli :rdb)
2.12+ (:export :main))
2.13+
2.14+(in-package :tao)
2.15+
2.16+(defmain ())
3.1--- a/examples/rdb/cl-simple-example.lisp Mon Dec 18 22:13:30 2023 -0500
3.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3@@ -1,13 +0,0 @@
3.4-;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c
3.5-
3.6-;; https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c
3.7-
3.8-;;; Code:
3.9-(defpackage :examples/rdb/cl-simple-example
3.10- (:nicknames :cl-simple-example)
3.11- (:use :cl :std :cli :rdb)
3.12- (:export :main))
3.13-
3.14-(in-package :cl-simple-example)
3.15-
3.16-(defmain ())