Aerospike Lua UDF调用报错:pb.so undefined symbol: lua_settop
Lua UDF在Docker中加载protobuf模块失败:undefined symbol: lua_settop
错误信息
ERROR lua create error: error loading module 'protobuf.pb' from file '/usr/local/lib/lua/5.1/protobuf/pb.so': /usr/local/lib/lua/5.1/protobuf/pb.so: undefined symbol: lua_settop
问题背景
在Docker中运行Aerospike的Lua UDF时,模块可正常注册,但执行聚合命令时触发上述错误。已尝试全网可查的解决方案,均无效。
相关文件及操作
Dockerfile
FROM rockylinux:8.9 # install requirements RUN dnf update -y && \ dnf install -y git gcc make findutils wget unzip readline-devel python3 python3-pip && \ ln -sf /usr/bin/python3 /usr/bin/python ## install aerospike RUN mkdir -p aerospike \ && wget -qO- "https://download.aerospike.com/artifacts/aerospike-server-enterprise/6.3.0.5/aerospike-server-enterprise_6.3.0.5_tools-8.4.0_el8_$(uname -m).tgz" | tar -xvzf - -C ./aerospike --strip-components=1 \ && cd ./aerospike && ./asinstall && cd ../ && rm -rf ./aerospike # https://aerospike.com/developer/udf/knowing_lua#lua-version ARG LUA_VERSION=5.1.4 # Use latest ARG LUAROCKS_VERSION=3.11.1 # install lua RUN mkdir -p lua && \ wget -qO- https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz | tar -xvzf - -C ./lua --strip-components=1 && \ cd ./lua && CFLAGS="-fPIC -Wall -Wextra" LIBFLAGS="-shared" make -j $(nproc) linux && make -j $(nproc) install && \ cd ../ && rm -rf ./lua && \ lua -v && \ # install luarocks mkdir -p ./luarocks && \ wget -qO- https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz | tar -xvzf - -C ./luarocks --strip-components=1 && \ cd luarocks && ./configure && make -j $(nproc) && make -j $(nproc) install && cd .. && rm -rf luarocks && \ luarocks && \ # install protobuf luarocks install protobuf && \ luarocks install lua-protobuf && \ pip3 install protobuf && \ dnf install -y protobuf-compiler && \ # clean up dnf clean all COPY ./proto /proto COPY ./udf /udf ENTRYPOINT ["asd"] CMD ["--foreground"]
Lua UDF代码
local protobuf = require 'protobuf' function count(recs) return recs : map(function(rec) return 1 end) : aggregate(0, function(count, rec) return count + 1 end) end
执行命令及报错场景
aql> REGISTER MODULE '/udf/myudf.lua' OK, 1 module added. aql> AGGREGATE myudf.count() ON test
问题原因
错误根源是系统安装的Lua与Aerospike内置的Lua环境不兼容。Aerospike自带嵌入式Lua 5.1,而手动安装的系统Lua,其编译参数、符号表与Aerospike内置Lua存在差异。用系统Lua的luarocks编译的protobuf.pb.so依赖系统Lua的符号,Aerospike加载时无法找到对应的lua_settop符号。
修复方案
方案1:移除独立Lua安装,基于Aerospike内置Lua编译模块
- 修改Dockerfile,删除独立安装Lua的步骤,改用Aerospike提供的Lua环境配置luarocks:
FROM rockylinux:8.9 # install requirements RUN dnf update -y && \ dnf install -y git gcc make findutils wget unzip readline-devel python3 python3-pip && \ ln -sf /usr/bin/python3 /usr/bin/python ## install aerospike RUN mkdir -p aerospike \ && wget -qO- "https://download.aerospike.com/artifacts/aerospike-server-enterprise/6.3.0.5/aerospike-server-enterprise_6.3.0.5_tools-8.4.0_el8_$(uname -m).tgz" | tar -xvzf - -C ./aerospike --strip-components=1 \ && cd ./aerospike && ./asinstall && cd ../ && rm -rf ./aerospike # 安装luarocks并针对Aerospike内置Lua配置 ARG LUAROCKS_VERSION=3.11.1 RUN mkdir -p ./luarocks && \ wget -qO- https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz | tar -xvzf - -C ./luarocks --strip-components=1 && \ cd luarocks && \ # 指定Aerospike的Lua头文件和库路径 ./configure --with-lua-include=/usr/local/aerospike/lua/include --with-lua-lib=/usr/local/aerospike/lua/lib && \ make -j $(nproc) && make -j $(nproc) install && \ cd .. && rm -rf luarocks && \ # 安装protobuf模块 luarocks install protobuf && \ pip3 install protobuf && \ dnf install -y protobuf-compiler && \ # clean up dnf clean all COPY ./proto /proto COPY ./udf /udf ENTRYPOINT ["asd"] CMD ["--foreground"]
方案2:使用纯Lua实现的protobuf库
- 如果不需要C扩展的性能,可替换为纯Lua的protobuf库,避免动态链接依赖:
- 修改Lua代码中的引用:
local protobuf = require 'protobuf-pure'- 在Dockerfile中替换安装命令:
luarocks install protobuf-pure
方案3:调整Aerospike Lua模块搜索路径
- 查看Aerospike的Lua模块搜索路径:
asinfo -v 'get-config:context=udf'
- 修改
/etc/aerospike/aerospike.conf,将luarocks的安装路径添加到配置中:
udf { lua_user_path /usr/local/lib/lua/5.1/?.lua; lua_user_cpath /usr/local/lib/lua/5.1/?.so; }
内容的提问来源于stack exchange,提问作者slesh
相关产品推荐
相关产品推荐

