调试Aerospike Lua UDF。

我对lua和aerospike非常陌生。我想开发在aerospike上运行的UDF,但是我找不到带有调试选项的方法。

我尝试安装eclipse LDT,但似乎无法找到aerospike的要求。

我该怎么做?

我尝试了一些简单的内容:加载表的所有记录并打印。

function test(rec)

        print(rec['bin1'])
end

当然,我创建了表并插入了记录。

谢谢

点赞
用户1442917
用户1442917

如果 Aerospike 支持 luasocket,或者提供了一种加载 luasocket 库的方法(我没有在文档中找到是否支持),您可以按照 远程调试说明 尝试使用 ZeroBrane Studio 调试您的脚本。

2015-05-14 16:41:03
用户582436
用户582436

在 aerospike.com 网站上有一个 UDF Developer Guide ,针对这种情况,请参阅“Developing Record UDFs”一文。要记录数据集(_表格_)中所有记录,您需要将记录 UDF 应用于扫描。要使用 Python 客户端做到这一点,请参见 aerospike.Client.scan_apply() 方法。

您需要为 UDF 操作设置日志文件以进行调试,并在您的示例中记录数据集中的记录。在 /etc/aerospike/aerospike.conf 文件中添加 logging 部分,然后重新启动服务:

logging {
  file /var/log/aerospike/udf.log {
    context any warning
    context ldt info
    context udf debug
    context query debug
  }
}

现在,您可以创建一个使用 info() 方法的 Lua 模块,如 Lua UDF - Best Practices 文中所述。

我创建了一个名为 sample.lua 的模块,其中包含一个名为 show_set 的记录 UDF:

function show_set(rec, ns, set)
  out = ''
  bins = record.bin_names(rec)
  for i, bin_name in ipairs(bins) do
    out = out .. "'" .. tostring(bin_name) .. "'"
    out = out .. '=>' .. tostring(rec[bin_name]) .. ","
  end
  info("show_set(%s.%s, %s): %s", ns, set, tostring(record.key(rec)), out)
end

我使用了一个简单的 Python 脚本将其加载到服务器,并将记录 UDF 应用于扫描:

import aerospike
from aerospike.exception import *
import time

config = { 'hosts': [ ('192.168.119.3', 3000)]}
client = aerospike.client(config).connect()

try:
    client.udf_put('sample.lua')
    time.sleep(2)
except AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))

client.put(('test','demo','key1'), {'id':1,'a':1},
           policy={'key':aerospike.POLICY_KEY_SEND})
client.put(('test','demo','key2'), {'id':2,'b':2},
           policy={'key':aerospike.POLICY_KEY_SEND})
client.put(('test','demo','key3'), {'id':3,'c':3},
           policy={'key':aerospike.POLICY_KEY_SEND})

try:
    scan_id = client.scan_apply('test', 'demo', 'sample', 'show_set', ['test',
    'demo'])
    while True:
        response = client.scan_info(scan_id)
        if (response['status'] == aerospike.SCAN_STATUS_COMPLETED) or \
            response['status'] == aerospike.SCAN_STATUS_ABORTED:
            break
    if response['status'] == aerospike.SCAN_STATUS_COMPLETED:
        print("Background scan successful")
        print("Progess percentage : ", response['progress_pct'])
        print("Number of scanned records : ", response['records_scanned'])
        print("Background scan status : ", "SCAN_STATUS_COMPLETED")
    else:
        print("Scan_apply failed")
except AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
client.close()

我运行了该脚本,并使用 tail -f /var/log/aerospike/udf.log | grep show_set 命令查看结果:

May 14 2015 21:01:47 GMT: INFO (udf): ([C]::-1) show_set(test.demo, key1): 'a'=>1,'id'=>1, May 14 2015 21:01:47 GMT: INFO (udf): ([C]::-1) show_set(test.demo, key3): 'c'=>3,'id'=>3, May 14 2015 21:01:47 GMT: INFO (udf): ([C]::-1) show_set(test.demo, key2): 'b'=>2,'id'=>2,

2015-05-14 21:03:10