Record UDF and stream UDF: where to find them?

Hi all,

I registered two lua module using aql:

aggiorna_gender.lua (record UDF)

aggregationByRegion.lua (stream UDF)

I try to call them inside a Java Client.

No problem for aggiorna_gender.lua.

Instead, when I try to call aggregationByRegion.lua, I get this exception:

“Failed to read file: /MORENO_91/Aggregations/udf/aggregationByRegion.lua”

Lua module is looked for in a hypotetical udf subdirectory (I run Client in /MORENO_91/Aggregations directory)

instead of:

/opt/aerospike/usr/udf/lua

directory where it is (like aggiorna_gender.lua):

The strangest behaviour is that raggregationByRegion.lua file is randomly (???) looked for in correct directory (about one out of 10).

Java code when I call aggiorna_gender.lua:

String result = client.execute(null, userKey, “aggiorna_gender”, “aggiornaGender”, Value.get(gender)).toString();

Java code when I call aggregationByRegion.lua:

rs = client.queryAggregate(null, stmt, “aggregationByRegion”, “sum”);

Any help is very appreciated.

Many thanks in advance.

Moreno

I forgot a detail.

The first time I registered LUA module not with AQL but inside java code indicating that LUA module was in directory:

udf/aggregationByRegion.lua

Then I removed this module using AQL and, in a second time, using AMC

(Is it possiible that Cluster, for some reason, go on searching for LUA module in the wrong place?).

Thanks again Moreno

You should be seeing this on client side. The problem is client is not able to find it. Record UDF has no component on the client side running hence normal record UDF execution works fine but when you have aggregation last step reduce step runs at the client. Hence client is searching for the registered module on the client box.

You need udf source directory for client. Check

– R

Thanky you raj!

I put lua file in a subdirectory udf (under the directory where I run Client java).

Now there is another problem (but the “Failed to read…” is disappeared).

Is it possible to force client to search lua file in a specific directory and not in a generic “udf” subdirectory?

I ask this because node where I run client is a node of the cluster and lua files are already in

/opt/aerospike/usr/udf/lua

(I’d like to avoid duplication ot the same file in different directory).

Moreno .

Hi Moreno, As both client and server is running in one node of the cluster, the lua file will always be copied to /opt/aerospike/usr/udf/lua from client’s specified location.

jyoti,

I didn’t understand :frowning:

From AQL I gave this command:

AQL> register module ‘/opt/aerospike/usr/udf/lua/aggregationByRegion.lua’

(I previously copied lua file in '/opt/aerospike/usr/udf/lua/ dir)

After register, lua file was copied in all 3 nodes of the cluster in correct dir:

/opt/aerospike/usr/udf/lua

Then I gave these commands:

cd /MORENO_91/Aggregations

./ClientJava

with “Failed to load lua file…”.

because ClientJava searched for LUA file not in

/opt/aerospike/usr/udf/lua

but in

/MORENO_91/Aggregations/udf

To bypass the problem I created :

/MORENO_91/Aggregations/udf

directory

and copied aggregationByRegion.lua

inside it.

Question is: if I had other Clients (deployed in other directories) I should copy the same lua file in all client’s udf subdir?

In a multiclients (and multinodes) envinronment this could be not so easy to manage.

Thanks Moreno

So for your usecase you can specify source directory to search lua files in client.

//set source directory for lua files
LuaConfig.SourceDirectory = System.getProperty(“lua.dir”, “/opt/aerospike/usr/udf/lua/”);

//register lua file

RegisterTask task = client.register(params.policy, LuaConfig.SourceDirectory + “aggregationByRegion.lua”, “aggregationByRegion.lua”, Language.LUA);

Thank you jyoti, I’ll follow your suggeston.

Moreno