summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-12-01 20:08:34 -0300
committerEuAndreh <eu@euandre.org>2025-12-01 20:08:34 -0300
commit6c1930eadbdfec8b825f1aadc2304a5017a03551 (patch)
treedbd67653f8a75188796f4d7edaad52837e0bc63d
parentm (diff)
downloaddatomic-6c1930eadbdfec8b825f1aadc2304a5017a03551.tar.gz
datomic-6c1930eadbdfec8b825f1aadc2304a5017a03551.tar.xz
m
-rw-r--r--Makefile98
-rwxr-xr-xbin/transactor19
-rwxr-xr-xbin/transactor.in79
-rw-r--r--etc/transactor.properties.tmpl (renamed from etc/transactor.properties)9
4 files changed, 183 insertions, 22 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..14f8cf8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,98 @@
+.POSIX:
+DATE = 1970-01-01
+VERSION = 0.1.0
+NAME = datomic
+NAME_UC = $(NAME)
+LANGUAGES = en
+## Installation prefix. Defaults to "/usr".
+PREFIX = /usr
+BINDIR = $(PREFIX)/bin
+SYSCONFDIR = $(PREFIX)/etc
+LIBDIR = $(PREFIX)/lib
+INCLUDEDIR = $(PREFIX)/include
+SRCDIR = $(PREFIX)/src/$(NAME)
+SHAREDIR = $(PREFIX)/share
+LOCALEDIR = $(SHAREDIR)/locale
+MANDIR = $(SHAREDIR)/man
+EXEC = ./
+## Where to store the installation. Empty by default.
+DESTDIR =
+LDLIBS =
+
+
+
+.SUFFIXES:
+.SUFFIXES: .in
+
+.in:
+ sed \
+ -e 's:@SYSCONFDIR@:$(SYSCONFDIR):g' \
+ < $< > $@
+ if [ -x $< ]; then chmod +x $@; fi
+
+
+
+all:
+include deps.mk
+
+
+sources = \
+ $(sources.sh) \
+
+
+derived-assets = \
+ bin/transactor \
+
+side-assets = \
+
+
+
+## Default target. Builds all artifacts required for testing
+## and installation.
+all: $(derived-assets)
+
+
+
+check-unit:
+
+
+check-integration:
+
+
+## Run all tests. Each test suite is isolated, so that a parallel
+## build can run tests at the same time. The required artifacts
+## are created if missing.
+check: check-unit check-integration
+
+
+
+## Remove *all* derived artifacts produced during the build.
+## A dedicated test asserts that this is always true.
+clean:
+ rm -rf $(derived-assets) $(side-assets)
+
+
+## Installs into $(DESTDIR)$(PREFIX). Its dependency target
+## ensures that all installable artifacts are crafted beforehand.
+install: all
+ mkdir -p \
+ '$(DESTDIR)$(BINDIR)' \
+ '$(DESTDIR)$(SRCDIR)' \
+
+ cp $(sources.sh) '$(DESTDIR)$(BINDIR)'
+ cp $(sources.sh) '$(DESTDIR)$(SRCDIR)'
+
+
+## Uninstalls from $(DESTDIR)$(PREFIX). This is a perfect mirror
+## of the "install" target, and removes *all* that was installed.
+## A dedicated test asserts that this is always true.
+uninstall:
+ rm -rf \
+ '$(DESTDIR)$(SRCDIR)' \
+
+ for f in $(sources.sh); do \
+ rm -f '$(DESTDIR)$(BINDIR)'/"$${f#src/}"; \
+ done
+
+
+ALWAYS:
diff --git a/bin/transactor b/bin/transactor
deleted file mode 100755
index 54c7b0d..0000000
--- a/bin/transactor
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-set -euo pipefail
-
-sqlite3 storage.db < etc/init.sql
-mkdir -p tmp cache
-
-exec java \
- -server \
- -Djava.security.manager=allow \
- -Ddatomic.valcachePath=cache2 \
- -Ddatomic.valcacheMaxGb=100 \
- -Xms4g \
- -Xmx4g \
- -XX:+UseG1GC \
- -XX:MaxGCPauseMillis=50 \
- --class-path 'etc/:lib/*' \
- clojure.main \
- --main datomic.launcher \
- etc/transactor.properties
diff --git a/bin/transactor.in b/bin/transactor.in
new file mode 100755
index 0000000..c47f2c7
--- /dev/null
+++ b/bin/transactor.in
@@ -0,0 +1,79 @@
+#!/bin/sh
+set -euo pipefail
+
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ transactor [-p PORT] FILE
+ EOF
+}
+
+
+
+VALCACHESIZE=
+PORT=50200
+CACHEDIR='cache'
+TEMPDATADIR='tmp'
+while getopts 'p:C:S:T:' flag; do
+ case "$flag" in
+ (p)
+ PORT="$OPTARG"
+ ;;
+ (C)
+ CACHEDIR="$OPTARG"
+ ;;
+ (S)
+ VALCACHESIZE="$OPTARG"
+ ;;
+ (T)
+ TEMPDATADIR="$OPTARG"
+ ;;
+ (*)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ -z "${1:-}" ]; then
+ echo 'Missing FILE.' >&2
+ usage >&2
+ exit 2
+fi
+FILE="$1"
+
+
+
+if [ -z "$VALCACHESIZE" ]; then
+ VALCACHESIZE="$(
+ df -Pk "$FILE" |
+ tail -n1 |
+ awk '{printf "%.0f\n", $2 / (1024 * 1024)}'
+ )"
+fi
+
+sqlite3 "$FILE" < @SYSCONFDIR@/init.sql >&2
+
+set -x
+exec java \
+ -server \
+ -Djava.security.manager=allow \
+ -Xms4g \
+ -Xmx4g \
+ -XX:+UseG1GC \
+ -XX:MaxGCPauseMillis=50 \
+ --class-path 'etc/:lib/*' \
+ clojure.main \
+ --main datomic.launcher \
+ <(
+ sed \
+ -e "s|@PORT@|$PORT|g" \
+ -e "s|@FILE@|$FILE|g" \
+ -e "s|@CACHEDIR@|$CACHEDIR|g" \
+ -e "s|@TEMPDATADIR@|$TEMPDATADIR|g" \
+ -e "s|@VALCACHESIZE@|$VALCACHESIZE|g" \
+ @SYSCONFDIR@/transactor.properties.tmpl |
+ tee /dev/stderr
+ )
diff --git a/etc/transactor.properties b/etc/transactor.properties.tmpl
index 28a05be..0037c35 100644
--- a/etc/transactor.properties
+++ b/etc/transactor.properties.tmpl
@@ -1,10 +1,13 @@
protocol=sql
host=localhost
-port=50200
+port=@PORT@
encrypt-channel=false
sql-driver-class=org.sqlite.JDBC
-sql-url=jdbc:sqlite:storage.db
-data-dir=tmp
+sql-url=jdbc:sqlite:@FILE@
+data-dir=@TEMPDATADIR@
+
+valcache-path=@CACHEDIR@
+valcache-max-gb=@VALCACHESIZE@
# 4GiB VM
memory-index-threshold=32m