Skip to content

Commit

Permalink
New DelKey.lua, and initial smax / dsm function libs
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 11, 2024
1 parent c2ee575 commit bf01534
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 6 deletions.
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ sed -i "s:/usr:$DESTDIR:g" $SYSTEMD/smax-scripts.service
if [[ ! $1 =~ ^(sma|SMA)$ ]] ; then
echo ". Removing SMA-specific sections from scripts"
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lua
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lib
fi

# Register smax-scripts with systemd
Expand Down
44 changes: 44 additions & 0 deletions lua/DelKey.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- keys: [1+] SMA-X keywords
-- arguments: (none)
-- returns: (integer) the total number of fields deleted, including in sub-structures, and in parent structures.

local metas = { '<timestamps>', '<types>', '<dims>', '<origins>', '<writes>', '<reads>', '<descriptions>', '<units>', '<coords>' }
local n = 0

local function DelKey (table)
-- Recursively delete table entries
for f in redis.call('hkeys', table) do
DelKey(table..':'..field)
end

-- Delete metadata for the table
for m in metas do
redis.call("hdel", m, table)
end

-- Delete the table itself
if redis.call('del', table) == 1 then
n = n + 1
end
end

-- Process each input keyword
for key in KEYS do
-- Delete the table (if any) recuresively
DelKey(key)

-- match the substring starting with the last :
local tail = key:gmatch(':(?:.(?!:))+')

-- If the keyword can be split...
if tail ~= nil and tail ~= '' then
-- Delete reference from parent table
local parent = table:sub(1, -tail:len())
local ref = tail:sub(2)
if redis.call('hdel', parent, ref) == 1 then
n = n + 1
end
end
end

return n
6 changes: 0 additions & 6 deletions lua/DelStruct.lua

This file was deleted.

32 changes: 32 additions & 0 deletions lua/dsm.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!lua name=dsm

local function dsm_get_key(KEYS, ARGS)
-- keys: <none>
-- arguments: host target key
-- returns name SMA-X table name under which the data can be found

local table = "DSM:"..ARGV[2]
local key = ARGV[3]

-- If the data is stored under the target name, use that
if redis.call('hexists', table, key) == 1 then
return table
end

-- If the data is stored under the caller's name, use that
table = "DSM:"..ARGV[1]
if redis.call('hexists', table, key) == 1 then
return table
end

-- LUA false maps to Redis nil
return false
end


redis.register_function {
function_name='dsm_het_key',
callback=dsm_get_key,
flags={ 'no-writes' },
description='(|host, target, key) Returns the SMA-X table for the given host and target machine and DSM key'
}
Loading

0 comments on commit bf01534

Please sign in to comment.