Debug aerospike lua UDF

I am very new to lua and aerospike. I would like to develop a UDF that works on aerospace, but I cannot find a way to do it with debug capability.

I tried to install eclipse LDT, but it cannot find aerospace security needs.

How can i do this?

I tried something simple: download all table records and print.

function test(rec)


        print(rec['bin1'])
end

      

of course i created a table and inserted records.

thank

+3


source to share


2 answers


Aerospike.com has a UDF Developer's Guide , and specifically for this case look at Developing UDFs Record. "To register all records in a set (table), you would use a UDF record to scan. For an example of this with a Python client, see aerospike.Client.scan_apply () method .

You need to set up a log file for UDF operations for debugging, and in your example, log the entries to the set. In your /etc/aerospike/aerospike.conf add a section logging

, restart the service:

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

      

Now you can create a Lua module with a function that uses a method info()

as described in the article Lua UDF - Best Practices .

I created a module called sample.lua

that has a UDF entry called 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

      

I uploaded it to the server using a simple Python script that also applies the UDF entry to the scan:

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()

      

I ran the script and tail -f /var/log/aerospike/udf.log | grep show_set

:

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

+6


source


If aerospike supports luasocket or provides a way to download the luasocket library (I couldn't find it in the documentation if there is one), you can try debugging your script using ZeroBrane Studio by following the instructions for remote debugging .



0


source







All Articles