【问题标题】:Debug aerospike lua UDF调试 aerospike lua UDF
【发布时间】:2015-05-14 14:03:57
【问题描述】:

我对 lua 和 aerospike 很陌生。我想开发一个在 aerospike 上运行的 UDF,但我找不到通过调试选项来执行此操作的方法。

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

我该怎么做?

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

function test(rec)


        print(rec['bin1'])
end

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

谢谢

【问题讨论】:

    标签: lua aerospike


    【解决方案1】:

    在 aerospike.com 网站上有一个UDF Developer Guide,专门针对这种情况,请查看“Developing Record UDFs”文章。要记录集合(table)中的所有记录,您可以将记录 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:

    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,

    【讨论】:

      【解决方案2】:

      如果 aerospike 支持 luasocket 或提供加载 luasocket 库的方法(如果支持,我在文档中找不到),您可以按照 instructions for remote debugging 尝试使用 ZeroBrane Studio 调试您的脚本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-13
        • 1970-01-01
        • 2016-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-07
        相关资源
        最近更新 更多