2015-05-14 176 views
3

我对lua和aerospike很新。我想开发一个在aerospike上运行的UDF,但是我找不到可以通过选项进行调试的方法。调试aerospike lua UDF

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

我该怎么做?

我尝试了一件简单的事情:加载一张表的所有记录并打印。

function test(rec) 


     print(rec['bin1']) 
end 

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

感谢

回答

0

如果塞支持luasocket或提供一种方式来加载luasocket库(我不能在文件中找到,如果它),你可以尝试通过以下的instructions for remote debugging调试使用ZeroBrane Studio中的脚本。

6

在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 UDF - Best Practices文章中描述的功能的Lua模块。

我创建了一个名为sample.lua模块具有记录UDF名为show_set

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

中号ay 14 2015 21:01:47 GMT:INFO(udf):([C] :: - 1)show_set(test.demo, key1):'a'=> 1,'id'=> 1,5月14日2015 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,

+0

为你工作? –