Skip to content

Commit 45569fd

Browse files
committed
New DelKey.lua, and initial smax / dsm function libs
1 parent c2ee575 commit 45569fd

File tree

7 files changed

+491
-8
lines changed

7 files changed

+491
-8
lines changed

install.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ sed -i "s:/usr:$DESTDIR:g" $SYSTEMD/smax-scripts.service
7878

7979
if [[ ! $1 =~ ^(sma|SMA)$ ]] ; then
8080
echo ". Removing SMA-specific sections from scripts"
81-
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lua
81+
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lua $SMAX/lua/*.lib
8282
fi
8383

8484
# Register smax-scripts with systemd
@@ -142,7 +142,7 @@ else
142142
echo # (optional) move to a new line
143143
if [[ $REPLY =~ ^[Yy]$ ]] ; then
144144
echo ". Removing SMA-specific sections from scripts"
145-
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua
145+
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua *.lib
146146
fi
147147

148148
read -p "start redis with SMA-X scripts at this time? " -n 1 -r

lua/DelKey.lua

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- keys: [1+] SMA-X keywords
2+
-- arguments: (none)
3+
-- returns: (integer) the total number of fields deleted, including in sub-structures, and in parent structures.
4+
5+
local metas = { '<timestamps>', '<types>', '<dims>', '<origins>', '<writes>', '<reads>', '<descriptions>', '<units>', '<coords>' }
6+
local n = 0
7+
8+
local function DelKey (table)
9+
-- Recursively delete table entries
10+
for f in redis.call('hkeys', table) do
11+
DelKey(table..':'..field)
12+
end
13+
14+
-- Delete metadata for the table
15+
for m in metas do
16+
redis.call("hdel", m, table)
17+
end
18+
19+
-- Delete the table itself
20+
if redis.call('del', table) == 1 then
21+
n = n + 1
22+
end
23+
end
24+
25+
-- Process each input keyword
26+
for key in KEYS do
27+
-- Delete the table (if any) recuresively
28+
DelKey(key)
29+
30+
-- match the substring starting with the last :
31+
local tail = key:gmatch(':(?:.(?!:))+')
32+
33+
-- If the keyword can be split...
34+
if tail ~= nil and tail ~= '' then
35+
-- Delete reference from parent table
36+
local parent = table:sub(1, -tail:len())
37+
local ref = tail:sub(2)
38+
if redis.call('hdel', parent, ref) == 1 then
39+
n = n + 1
40+
end
41+
end
42+
end
43+
44+
return n

lua/DelStruct.lua

-6
This file was deleted.

lua/dsm.lib

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!lua name=dsm
2+
3+
-- Legacy DSM emulation helper library for Redis
4+
-- Author: Attila Kovacs
5+
-- Version: 11 December 2024
6+
--
7+
-- GitHub: Smithsonian/smax-server
8+
9+
local function dsm_get_key(KEYS, ARGS)
10+
-- keys: <none>
11+
-- arguments: host target key
12+
-- returns name SMA-X table name under which the data can be found
13+
14+
local table = "DSM:"..ARGV[2]
15+
local key = ARGV[3]
16+
17+
-- If the data is stored under the target name, use that
18+
if redis.call('hexists', table, key) == 1 then
19+
return table
20+
end
21+
22+
-- If the data is stored under the caller's name, use that
23+
table = "DSM:"..ARGV[1]
24+
if redis.call('hexists', table, key) == 1 then
25+
return table
26+
end
27+
28+
-- LUA false maps to Redis nil
29+
return false
30+
end
31+
32+
33+
redis.register_function {
34+
function_name='dsm_get_key',
35+
callback=dsm_get_key,
36+
flags={ 'no-writes' },
37+
description='(|host, target, key) Returns the SMA-X table for the given host and target machine and DSM key'
38+
}

0 commit comments

Comments
 (0)