databases/keydb: New port!

KeyDB is a high performance fork of Redis with a focus on multithreading,
memory efficiency, and high throughput. In addition to performance
improvements, KeyDB offers features such as Active Replication, FLASH
Storage and Subkey Expires. KeyDB has a MVCC architecture that allows you
to execute queries such as KEYS and SCAN without blocking the database and
degrading performance.

KeyDB maintains full compatibility with the Redis protocol, modules, and
scripts. This includes the atomicity guarantees for scripts and transactions.
Because KeyDB keeps in sync with Redis development KeyDB is a superset of
Redis functionality, making KeyDB a drop in replacement for existing Redis
deployments.

On the same hardware KeyDB can achieve significantly higher throughput than
Redis. Active-Replication simplifies hot-spare failover allowing you to
easily distribute writes over replicas and use simple TCP based load
balancing/failover. KeyDB's higher performance allows you to do more on less
hardware which reduces operation costs and complexity.

WWW: https://docs.keydb.dev/
This commit is contained in:
Ryan Steinmetz 2023-10-25 14:16:34 -04:00
parent 9c64647054
commit 11f4c366bf
No known key found for this signature in database
GPG key ID: D2C3D2B2FEF36DD7
18 changed files with 462 additions and 2 deletions

2
GIDs
View file

@ -476,7 +476,7 @@ dkimproxy:*:525:
# free: 533
pgbouncer:*:534:
redis:*:535:
# free: 536
keydb:*:536:
# free: 537
# free: 538
# free: 539

2
UIDs
View file

@ -482,7 +482,7 @@ dkimproxy:*:525:525::0:0:DKIM Proxy Owner:/nonexistent:/usr/sbin/nologin
# free: 533
pgbouncer:*:534:534::0:0:Pgbouncer Daemon:/nonexistent:/usr/sbin/nologin
redis:*:535:535::0:0:Redis Daemon:/nonexistent:/usr/sbin/nologin
# free: 536
keydb:*:536:536::0:0:KeyDB Daemon:/nonexistent:/usr/sbin/nologin
# free: 537
# free: 538
# free: 539

View file

@ -120,6 +120,7 @@
SUBDIR += kbibtex
SUBDIR += kdb
SUBDIR += kexi
SUBDIR += keydb
SUBDIR += kyotocabinet
SUBDIR += kyototycoon
SUBDIR += ldb15

93
databases/keydb/Makefile Normal file
View file

@ -0,0 +1,93 @@
PORTNAME= keydb
DISTVERSIONPREFIX= v
DISTVERSION= 6.3.3
CATEGORIES= databases
MAINTAINER= zi@FreeBSD.org
COMMENT= High performance fork of Redis--a persistent key-value database
WWW= https://docs.keydb.dev/
LICENSE= BSD3CLAUSE
LICENSE_FILE= ${WRKSRC}/COPYING
LIB_DEPENDS= libuuid.so:misc/e2fsprogs-libuuid \
liblz4.so:archivers/liblz4 \
libsnappy.so:archivers/snappy \
libzstd.so:archivers/zstd
USES= compiler:c11 cpe gmake pkgconfig:build tcl:test
USE_GITHUB= yes
GH_ACCOUNT= Snapchat
GH_PROJECT= KeyDB
USE_RC_SUBR= keydb keydb_sentinel
MAKE_ENV= OPTIMIZATION= \
V=yo
CFLAGS+= -I${LOCALBASE}/include
LDFLAGS+= -lpthread -lm -lexecinfo -L${LOCALBASE}/lib
SUB_FILES= pkg-message
SUB_LIST= PORTNAME=${PORTNAME} \
KEYDB_DBDIR=${KEYDB_DBDIR} \
KEYDB_LOGDIR=${KEYDB_LOGDIR} \
KEYDB_RUNDIR=${KEYDB_RUNDIR} \
KEYDB_USER=${USERS}
USERS= keydb
GROUPS= keydb
PLIST_SUB= KEYDB_DBDIR=${KEYDB_DBDIR} \
KEYDB_GROUP=${GROUPS} \
KEYDB_LOGDIR=${KEYDB_LOGDIR} \
KEYDB_RUNDIR=${KEYDB_RUNDIR} \
KEYDB_USER=${USERS}
OPTIONS_DEFINE= TLS
OPTIONS_DEFAULT= TLS
TLS_DESC= Use TLS (openssl req.)
TLS_USES= ssl
TLS_MAKE_ENV= BUILD_TLS=yes
BIN_FILES= keydb-benchmark keydb-check-aof keydb-check-rdb keydb-cli \
keydb-sentinel keydb-server
KEYDB_DBDIR?= /var/db/keydb
KEYDB_RUNDIR?= /var/run/keydb
KEYDB_LOGDIR?= /var/log/keydb
.include <bsd.port.pre.mk>
.if ${ARCH} == i386 && !${CFLAGS:M-march=*}
# Needed for __atomic_fetch_add_8
USE_GCC= yes
CFLAGS+= -march=i586
.endif
.if defined(_ADDFLAGS)
CFLAGS+= -fPIC
LDFLAGS+= -Wl,-E
.endif
post-patch:
${REINPLACE_CMD} 's|/usr/local|${PREFIX}|g' ${WRKSRC}/src/Makefile
post-build:
${SED} ${SUB_LIST:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
${WRKSRC}/keydb.conf > ${WRKDIR}/keydb.conf
do-install:
${INSTALL_PROGRAM} ${BIN_FILES:C!^!${WRKSRC}/src/!} ${STAGEDIR}${PREFIX}/bin/
${INSTALL_DATA} ${WRKDIR}/keydb.conf ${STAGEDIR}${PREFIX}/etc/keydb.conf.sample
${INSTALL_DATA} ${WRKSRC}/sentinel.conf ${STAGEDIR}${PREFIX}/etc/keydb_sentinel.conf.sample
${MKDIR} ${STAGEDIR}${KEYDB_LOGDIR} \
${STAGEDIR}${KEYDB_DBDIR} \
${STAGEDIR}${KEYDB_RUNDIR}
do-test:
@cd ${WRKSRC} && ${TCLSH} tests/test_helper.tcl
.include <bsd.port.post.mk>

3
databases/keydb/distinfo Normal file
View file

@ -0,0 +1,3 @@
TIMESTAMP = 1698245036
SHA256 (Snapchat-KeyDB-v6.3.3_GH0.tar.gz) = c6798cea3fe4ba4d1b42eea6ca2cfaee261786d12bf30aef1a53211d25ab66d9
SIZE (Snapchat-KeyDB-v6.3.3_GH0.tar.gz) = 11541110

View file

@ -0,0 +1,67 @@
#!/bin/sh
# PROVIDE: keydb
# REQUIRE: LOGIN
# BEFORE: securelevel
# KEYWORD: shutdown
# Add the following line to /etc/rc.conf to enable `keydb':
#
#keydb_enable="YES"
#
# Define profiles here to run separate keydb instances:
#
#keydb_profiles="foo bar" # Script uses %%PREFIX%%/etc/keydb-NAME.conf respectively.
# For correct script working please update pidfile entries in
# keydb-NAME.conf files.
. /etc/rc.subr
name="keydb"
rcvar="${name}_enable"
extra_commands="reload"
command="%%PREFIX%%/bin/keydb-server"
pidfile="%%KEYDB_RUNDIR%%/$name.pid"
# read configuration and set defaults
load_rc_config "$name"
: ${keydb_enable="NO"}
: ${keydb_user="%%KEYDB_USER%%"}
: ${keydb_config="%%PREFIX%%/etc/$name.conf"}
command_args="${keydb_config}"
required_files="${keydb_config}"
_profile_exists() {
for _p in ${keydb_profiles}; do
[ "${_p}" = "$1" ] && return 1;
done
return 0
}
if [ $# -eq 2 ]; then
_profile=$2
_profile_exists $_profile
_exists=$?
[ ${_exists} -ne 1 ] && {
echo "`basename %%PREFIX%%/etc/rc.d/keydb`: no '$2' in 'keydb_profiles'"
exit 1
};
echo "-- Profile: ${_profile} --"
config_file="%%PREFIX%%/etc/${name}-${_profile}.conf"
command_args="${config_file}"
pidfile="%%KEYDB_RUNDIR%%/${_profile}.pid"
required_files="${config_file}"
elif [ -n "${keydb_profiles}" ]; then
_swap=$*; shift; _profiles=$*
_profiles=${_profiles:-${keydb_profiles}}
set -- ${_swap}
for _profile in ${_profiles}; do
%%PREFIX%%/etc/rc.d/keydb $1 ${_profile}
done
exit 0
fi
run_rc_command "$1"

View file

@ -0,0 +1,39 @@
#!/bin/sh
# PROVIDE: keydb_sentinel
# REQUIRE: LOGIN
# BEFORE: securelevel
# KEYWORD: shutdown
# Add the following line to /etc/rc.conf to enable `sentinel':
#
#keydb_sentinel_enable="YES"
#
. /etc/rc.subr
name="keydb_sentinel"
rcvar="${name}_enable"
command="/usr/local/bin/keydb-sentinel"
pidfile="/var/run/keydb/$name.pid"
# read configuration and set defaults
load_rc_config "$name"
: ${keydb_sentinel_enable="NO"}
: ${keydb_sentinel_user="keydb"}
: ${keydb_sentinel_config="/usr/local/etc/$name.conf"}
command_args="${keydb_sentinel_config} --daemonize yes --pidfile ${pidfile}"
required_files="${keydb_sentinel_config}"
start_precmd="${name}_checks"
restart_precmd="${name}_checks"
keydb_sentinel_checks()
{
if [ x`id -u ${keydb_sentinel_user}` != x`stat -f %u ${keydb_sentinel_config}` ]; then
err 1 "${keydb_sentinel_config} must be owned by user ${keydb_sentinel_user}"
fi
}
run_rc_command "$1"

View file

@ -0,0 +1,40 @@
--- deps/hiredis/Makefile.orig 2023-10-25 15:54:51 UTC
+++ deps/hiredis/Makefile
@@ -21,7 +21,7 @@ HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | a
HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}')
# Installation related variables and target
-PREFIX?=/usr/local
+PREFIX?=${PREFIX}
INCLUDE_PATH?=include/hiredis
LIBRARY_PATH?=lib
PKGCONF_PATH?=pkgconfig
@@ -44,10 +44,9 @@ export REDIS_TEST_CONFIG
# Fallback to gcc when $CC is not in $PATH.
CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
-OPTIMIZATION?=-O3
WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers
DEBUG_FLAGS?= -g -ggdb
-REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS)
+REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS) $(PLATFORM_FLAGS)
REAL_LDFLAGS=$(LDFLAGS)
DYLIBSUFFIX=so
@@ -106,6 +105,16 @@ ifeq ($(uname_S),Darwin)
DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
SSL_DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME) -o $(SSL_DYLIBNAME) $(LDFLAGS) $(SSL_LDFLAGS)
DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup
+endif
+ifeq ($(uname_S),FreeBSD)
+ CFLAGS?=$(CFLAGS)
+ CCLINK?=pthread
+ LDFLAGS?=-L. -Wl,-rpath,.
+ DYLIBNAME?=libhiredis.so
+ DYLIB_MAKE_CMD?=$(CC) -o ${DYLIBNAME} ${OBJ}
+ STLIBNAME?=libhiredis.a
+ STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
+ SSL_LDFLAGS+=${OPENSSL_LDFLAGS}
endif
all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)

View file

@ -0,0 +1,39 @@
--- deps/hiredis/net.c.orig 2019-11-28 19:32:05 UTC
+++ deps/hiredis/net.c
@@ -178,14 +178,34 @@
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
-#else
-#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__)
+#elif defined(__GLIBC__)
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
val = interval/3;
+ if (val == 0) val = 1;
+ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
+ __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
+ return REDIS_ERR;
+ }
+
+ val = 3;
+ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
+ __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
+ return REDIS_ERR;
+ }
+#else
+#if !defined(__sun) && defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTL) && \
+ defined(TCP_KEEPCNT)
+ val = interval;
+ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
+ __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
+ return REDIS_ERR;
+ }
+
+ val = internal/3;
if (val == 0) val = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));

View file

@ -0,0 +1,15 @@
--- deps/linenoise/Makefile.orig 2019-09-25 10:40:18 UTC
+++ deps/linenoise/Makefile
@@ -1,10 +1,10 @@
STD=
WARN= -Wall
-OPT= -Os
+#OPT= -Os
R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
R_LDFLAGS= $(LDFLAGS)
-DEBUG= -g
+#DEBUG= -g
R_CC=$(CC) $(R_CFLAGS)
R_LD=$(CC) $(R_LDFLAGS)

View file

@ -0,0 +1,10 @@
--- deps/Makefile.orig 2023-10-25 17:16:24 UTC
+++ deps/Makefile
@@ -38,7 +38,6 @@ distclean:
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
- -(cd rocksdb && $(MAKE) clean) > /dev/null || true
-(cd hdr_histogram && $(MAKE) clean) > /dev/null || true
-(rm -f .make-*)

View file

@ -0,0 +1,12 @@
--- deps/lua/src/lua_cjson.c.orig 2019-09-25 10:40:18 UTC
+++ deps/lua/src/lua_cjson.c
@@ -46,7 +46,9 @@
#include "strbuf.h"
#include "fpconv.h"
+#if defined(__sun)
#include "../../../src/solarisfixes.h"
+#endif
#ifndef CJSON_MODNAME
#define CJSON_MODNAME "cjson"

View file

@ -0,0 +1,38 @@
--- keydb.conf.orig 2023-10-25 15:57:07 UTC
+++ keydb.conf
@@ -281,7 +281,7 @@ tcp-keepalive 300
# By default KeyDB does not run as a daemon. Use 'yes' if you need it.
# Note that KeyDB will write a pid file in /var/run/keydb.pid when daemonized.
-daemonize no
+daemonize yes
# If you run KeyDB from upstart or systemd, KeyDB can interact with your
# supervision tree. Options:
@@ -304,7 +304,7 @@ supervised no
#
# Creating a pid file is best effort: if KeyDB is not able to create it
# nothing bad happens, the server will start and run normally.
-pidfile /var/run/keydb_6379.pid
+pidfile %%KEYDB_RUNDIR%%/keydb.pid
# Specify the server verbosity level.
# This can be one of:
@@ -317,7 +317,7 @@ loglevel notice
# Specify the log file name. Also the empty string can be used to force
# KeyDB to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
-logfile ""
+logfile %%KEYDB_LOGDIR%%/keydb.log
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
@@ -470,7 +470,7 @@ rdb-del-sync-files no
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
-dir ./
+dir %%KEYDB_DBDIR%%/
################################# REPLICATION #################################

View file

@ -0,0 +1,52 @@
--- src/Makefile.orig 2023-10-25 15:47:51 UTC
+++ src/Makefile
@@ -138,21 +138,11 @@ endif
# Override default settings if possible
-include .make-settings
-DEBUG=-g -ggdb
FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(KEYDB_CFLAGS) $(REDIS_CFLAGS)
FINAL_CXXFLAGS=$(CXX_STD) $(WARN) $(OPT) $(DEBUG) $(CXXFLAGS) $(KEYDB_CFLAGS) $(REDIS_CFLAGS)
FINAL_LDFLAGS=$(LDFLAGS) $(KEYDB_LDFLAGS) $(DEBUG)
FINAL_LIBS+=-lm -lz -lcrypto -lbz2 -lzstd -llz4 -lsnappy
-ifneq ($(uname_S),Darwin)
- FINAL_LIBS+=-latomic
-endif
-# Linux ARM32 needs -latomic at linking time
-ifneq (,$(findstring armv,$(uname_M)))
- FINAL_LIBS+=-latomic
-endif
-
-
ifeq ($(uname_S),SunOS)
# SunOS
ifeq ($(findstring -m32,$(FINAL_CFLAGS)),)
@@ -211,7 +201,9 @@ ifeq ($(uname_S),NetBSD)
else
ifeq ($(uname_S),FreeBSD)
# FreeBSD
- FINAL_LIBS+= -lpthread -lexecinfo
+ FINAL_LIBS+= -lpthread -lexecinfo -luuid
+ FINAL_CFLAGS?= $(CFLAGS) $(REDIS_CFLAGS) -I${PREFIX}/include
+ FINAL_LDFLAGS= $(LDFLAGS) -pthread
else
ifeq ($(uname_S),DragonFly)
# DragonFly
@@ -347,7 +339,7 @@ else
endif
# Alpine OS doesn't have support for the execinfo backtrace library we use for debug, so we provide an alternate implementation using libwunwind.
-OS := $(shell cat /etc/os-release | grep ID= | head -n 1 | cut -d'=' -f2)
+OS := $(shell uname -r)
ifeq ($(OS),alpine)
FINAL_CXXFLAGS+=-DUNW_LOCAL_ONLY -DALPINE
FINAL_LIBS += -lunwind
@@ -417,7 +409,6 @@ persist-settings: distclean
echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
echo PREV_FINAL_CXXFLAGS=$(FINAL_CXXFLAGS) >> .make-settings
echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
- -(cd modules && $(MAKE))
-(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
.PHONY: persist-settings

View file

@ -0,0 +1,11 @@
--- src/mkreleasehdr.sh.orig 2019-11-22 16:54:22 UTC
+++ src/mkreleasehdr.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1`
-GIT_DIRTY=`git diff --no-ext-diff 2> /dev/null | wc -l`
+GIT_SHA1="00000000"
+GIT_DIRTY="0"
BUILD_ID=`uname -n`"-"`date +%s`
if [ -n "$SOURCE_DATE_EPOCH" ]; then
BUILD_ID=$(date -u -d "@$SOURCE_DATE_EPOCH" +%s 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" +%s 2>/dev/null || date -u +%s)

View file

@ -0,0 +1,11 @@
[
{ type: install
message: <<EOM
To setup "%%PORTNAME%%" you need to edit the configuration file:
%%PREFIX%%/etc/%%PORTNAME%%.conf
To run keydb from startup, add %%PORTNAME%%_enable="YES"
in your /etc/rc.conf.
EOM
}
]

18
databases/keydb/pkg-descr Normal file
View file

@ -0,0 +1,18 @@
KeyDB is a high performance fork of Redis with a focus on multithreading,
memory efficiency, and high throughput. In addition to performance
improvements, KeyDB offers features such as Active Replication, FLASH
Storage and Subkey Expires. KeyDB has a MVCC architecture that allows you
to execute queries such as KEYS and SCAN without blocking the database and
degrading performance.
KeyDB maintains full compatibility with the Redis protocol, modules, and
scripts. This includes the atomicity guarantees for scripts and transactions.
Because KeyDB keeps in sync with Redis development KeyDB is a superset of
Redis functionality, making KeyDB a drop in replacement for existing Redis
deployments.
On the same hardware KeyDB can achieve significantly higher throughput than
Redis. Active-Replication simplifies hot-spare failover allowing you to
easily distribute writes over replicas and use simple TCP based load
balancing/failover. KeyDB's higher performance allows you to do more on less
hardware which reduces operation costs and complexity.

11
databases/keydb/pkg-plist Normal file
View file

@ -0,0 +1,11 @@
bin/keydb-benchmark
bin/keydb-check-aof
bin/keydb-check-rdb
bin/keydb-cli
bin/keydb-sentinel
bin/keydb-server
@sample etc/keydb.conf.sample
@sample(%%KEYDB_USER%%,%%KEYDB_GROUP%%,) etc/keydb_sentinel.conf.sample
@dir(%%KEYDB_USER%%,%%KEYDB_GROUP%%,) %%KEYDB_DBDIR%%
@dir(%%KEYDB_USER%%,%%KEYDB_GROUP%%,) %%KEYDB_LOGDIR%%
@dir(%%KEYDB_USER%%,%%KEYDB_GROUP%%,) %%KEYDB_RUNDIR%%