我对lua和aerospike非常陌生。我想开发一个运行在aerospike上的UDF,但我找不到一种方法来实现这一点,并提供调试选项。
我试着安装eclipse LDT,但它似乎找不到aerospike要求。
我该怎么做呢?
我尝试了一些简单的方法:加载表中的所有记录并打印。
function test(rec)
print(rec['bin1'])
end当然,我创建了表并插入了记录。
谢谢
发布于 2015-05-15 05:03:11
在aerospike.com网站上有一个UDF Developer Guide,特别针对这种情况,请参阅"Developing Record UDFs“一文。要记录集合(表格)中的所有记录,您需要将记录UDF应用于扫描。有关使用Python客户端执行此操作的示例,请参阅aerospike.Client.scan_apply()方法。
您需要为用于调试的UDF操作设置一个日志文件,并在您的示例中记录集合中的记录。在您的/etc/aerospike/airospike.conf中添加一个logging部分,重新启动服务:
logging {
file /var/log/aerospike/udf.log {
context any warning
context ldt info
context udf debug
context query debug
}
}您现在可以创建一个Lua模块,其中包含使用info()方法的函数,如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
2015年5月14日21:01:47 GMT: INFO (udf):(C::-1) show_set(test.demo,key1):'a'=>1,'id'=>1,2015年5月14日21:01:47 GMT: INFO (udf):(C::-1) show_set(test.demo,key3):'c'=>3,'id'=>3,2015年5月14日21:01:47 GMT: INFO (udf):(C::-1) show_set(test.demo,key2):'b'=>2,'id'=>2,
发布于 2015-05-15 00:41:03
如果ZeroBrane支持luasocket或提供一种加载luasocket库的方法(如果支持,我在文档中找不到),您可以尝试使用ZeroBrane Studio按照instructions for remote debugging调试您的脚本。
https://stackoverflow.com/questions/30239415
复制相似问题