在 C 中将 gwan 与 aerospike db 连接起来
connection gwan with aerospike db in C
你好
首先我为我的 ita-english 感到抱歉。
我想将 gwan 与 aerospike 一起使用,但是当 运行 servlet 时...出现问题。
我从这个 example.c 的 aerospike 开始。在文件 example.c 中,我输入了 gwan.h,这是输出 ./gwan:
loading
hello.cs: to use .cs scripts, install C#..
hello.lua: to use .lua scripts, install Lua
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Linking example.c: undefined symbol: g_namespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To run G-WAN, you must fix the error(s) or remove this Servlet.
里面 example.c:
#include "gwan.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <aerospike/aerospike.h>
#include <aerospike/aerospike_key.h>
#include <aerospike/aerospike_query.h>
#include <aerospike/as_error.h>
#include <aerospike/as_key.h>
#include <aerospike/as_query.h>
#include <aerospike/as_record.h>
#include <aerospike/as_status.h>
#include <aerospike/as_val.h>
#include "example_utils.h"
const char TEST_INDEX_NAME[] = "test-bin-index";
bool query_cb(const as_val* p_val, void* udata);
void cleanup(aerospike* p_as);
bool insert_records(aerospike* p_as);
int
main(int argc, char* argv[])
{
if (! example_get_opts(argc, argv, EXAMPLE_MULTI_KEY_OPTS)) {
exit(-1);
}
aerospike as;
example_connect_to_aerospike(&as);
example_remove_test_records(&as);
example_remove_index(&as, TEST_INDEX_NAME);
if (! example_create_integer_index(&as, "test-bin", TEST_INDEX_NAME))
{
cleanup(&as);
exit(-1);
}
if (! insert_records(&as)) {
cleanup(&as);
exit(-1);
}
if (! example_read_test_records(&as)) {
cleanup(&as);
exit(-1);
}
as_error err;
as_query query;
as_query_init(&query, g_namespace, g_set);
as_query_where_inita(&query, 1);
as_query_where(&query, "test-bin", as_integer_equals(7));
LOG("executing query: where test-bin = 7");
if (aerospike_query_foreach(&as, &err, NULL, &query, query_cb, NULL)
!= AEROSPIKE_OK) {
LOG("aerospike_query_foreach() returned %d - %s", err.code,
err.message);
as_query_destroy(&query);
cleanup(&as);
exit(-1);
}
LOG("query executed");
as_query_destroy(&query);
cleanup(&as);
LOG("simple query example successfully completed");
return 0;
}
bool
query_cb(const as_val* p_val, void* udata)
{
if (! p_val) {
LOG("query callback returned null - query is complete");
return true;
}
as_record* p_rec = as_record_fromval(p_val);
if (! p_rec) {
LOG("query callback returned non-as_record object");
return true;
}
LOG("query callback returned record:");
example_dump_record(p_rec);
return true;
}
void
cleanup(aerospike* p_as)
{
example_remove_test_records(p_as);
example_remove_index(p_as, TEST_INDEX_NAME);
example_cleanup(p_as);
}
bool
insert_records(aerospike* p_as)
{
set
as_record rec;
as_record_inita(&rec, 1);
for (uint32_t i = 0; i < g_n_keys; i++) {
as_error err;
as_key key;
as_key_init_int64(&key, g_namespace, g_set, (int64_t)i);
as_record_set_int64(&rec, "test-bin", (int64_t)i);
if (aerospike_key_put(p_as, &err, NULL, &key, &rec) != AEROSPIKE_OK) {
LOG("aerospike_key_put() returned %d - %s", err.code, err.message);
return false;
}
}
LOG("insert succeeded");
return true;
}
如何连接aerospike和gwan?
谢谢
您需要 #pragma link
您的 aerospike 库,并确保所有需要的头文件都在正确的位置。请参阅 G-WAN FAQ 或阅读 G-WAN tarball 中的示例代码。
另外,在G-WAN中main函数的return代码将被用作HTTP响应代码,所以避免return -1;
.
undefined symbol: g_namespace
错误信息很清楚。只要此变量未定义,您的 C servlet 就不会编译。
我不知道你的库,但这个变量可能在库包含文件中定义 - 或者必须由最终用户(你)定义。查看库文档。
使用 G-WAN 运行 Aerospike C 客户端示例的详细步骤,
- 在您的系统上下载并提取 G-WAN 服务器 tar
- 您可以使用提取文件夹中存在的
./gwan
脚本来发送 tarG-WAN 服务器,例如./gwan_linux64-bit/
- 从 https://github.com/aerospike/aerospike-client-c 获取 Aerospike C-client,并安装到您的系统上
- 复制example.c到
./gwan_linux64-bit/0.0.0.0_8080/#0.0.0.0/csp/
对 example.c、
进行以下更改
- 添加以下#pragma 指令,
#pragma include "/home/user/aerospike-client-c/examples/utils/src/include/"
这将有助于搜索 example_utils.h
,这对于 C 客户端中的所有示例脚本都是必需的。
- 添加以下#pragma 指令,
#pragma link "/home/user/aerospike-client-c/examples/utils/src/main/example_utils.c"
我们必须 link example_utils.c,因为它具有示例脚本中使用的所有实用程序函数的定义。
更改 return 值。重新调整正确的 HTTP 错误代码。
现在,您可以开始了。 运行 ./gwan
服务器并通过浏览器访问您的网络服务,http://127.0.0.1:8080/?example.c
你好
首先我为我的 ita-english 感到抱歉。
我想将 gwan 与 aerospike 一起使用,但是当 运行 servlet 时...出现问题。 我从这个 example.c 的 aerospike 开始。在文件 example.c 中,我输入了 gwan.h,这是输出 ./gwan:
loading
hello.cs: to use .cs scripts, install C#..
hello.lua: to use .lua scripts, install Lua
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Linking example.c: undefined symbol: g_namespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To run G-WAN, you must fix the error(s) or remove this Servlet.
里面 example.c:
#include "gwan.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <aerospike/aerospike.h>
#include <aerospike/aerospike_key.h>
#include <aerospike/aerospike_query.h>
#include <aerospike/as_error.h>
#include <aerospike/as_key.h>
#include <aerospike/as_query.h>
#include <aerospike/as_record.h>
#include <aerospike/as_status.h>
#include <aerospike/as_val.h>
#include "example_utils.h"
const char TEST_INDEX_NAME[] = "test-bin-index";
bool query_cb(const as_val* p_val, void* udata);
void cleanup(aerospike* p_as);
bool insert_records(aerospike* p_as);
int
main(int argc, char* argv[])
{
if (! example_get_opts(argc, argv, EXAMPLE_MULTI_KEY_OPTS)) {
exit(-1);
}
aerospike as;
example_connect_to_aerospike(&as);
example_remove_test_records(&as);
example_remove_index(&as, TEST_INDEX_NAME);
if (! example_create_integer_index(&as, "test-bin", TEST_INDEX_NAME))
{
cleanup(&as);
exit(-1);
}
if (! insert_records(&as)) {
cleanup(&as);
exit(-1);
}
if (! example_read_test_records(&as)) {
cleanup(&as);
exit(-1);
}
as_error err;
as_query query;
as_query_init(&query, g_namespace, g_set);
as_query_where_inita(&query, 1);
as_query_where(&query, "test-bin", as_integer_equals(7));
LOG("executing query: where test-bin = 7");
if (aerospike_query_foreach(&as, &err, NULL, &query, query_cb, NULL)
!= AEROSPIKE_OK) {
LOG("aerospike_query_foreach() returned %d - %s", err.code,
err.message);
as_query_destroy(&query);
cleanup(&as);
exit(-1);
}
LOG("query executed");
as_query_destroy(&query);
cleanup(&as);
LOG("simple query example successfully completed");
return 0;
}
bool
query_cb(const as_val* p_val, void* udata)
{
if (! p_val) {
LOG("query callback returned null - query is complete");
return true;
}
as_record* p_rec = as_record_fromval(p_val);
if (! p_rec) {
LOG("query callback returned non-as_record object");
return true;
}
LOG("query callback returned record:");
example_dump_record(p_rec);
return true;
}
void
cleanup(aerospike* p_as)
{
example_remove_test_records(p_as);
example_remove_index(p_as, TEST_INDEX_NAME);
example_cleanup(p_as);
}
bool
insert_records(aerospike* p_as)
{
set
as_record rec;
as_record_inita(&rec, 1);
for (uint32_t i = 0; i < g_n_keys; i++) {
as_error err;
as_key key;
as_key_init_int64(&key, g_namespace, g_set, (int64_t)i);
as_record_set_int64(&rec, "test-bin", (int64_t)i);
if (aerospike_key_put(p_as, &err, NULL, &key, &rec) != AEROSPIKE_OK) {
LOG("aerospike_key_put() returned %d - %s", err.code, err.message);
return false;
}
}
LOG("insert succeeded");
return true;
}
如何连接aerospike和gwan? 谢谢
您需要 #pragma link
您的 aerospike 库,并确保所有需要的头文件都在正确的位置。请参阅 G-WAN FAQ 或阅读 G-WAN tarball 中的示例代码。
另外,在G-WAN中main函数的return代码将被用作HTTP响应代码,所以避免return -1;
.
undefined symbol: g_namespace
错误信息很清楚。只要此变量未定义,您的 C servlet 就不会编译。
我不知道你的库,但这个变量可能在库包含文件中定义 - 或者必须由最终用户(你)定义。查看库文档。
使用 G-WAN 运行 Aerospike C 客户端示例的详细步骤,
- 在您的系统上下载并提取 G-WAN 服务器 tar
- 您可以使用提取文件夹中存在的
./gwan
脚本来发送 tarG-WAN 服务器,例如./gwan_linux64-bit/
- 从 https://github.com/aerospike/aerospike-client-c 获取 Aerospike C-client,并安装到您的系统上
- 复制example.c到
./gwan_linux64-bit/0.0.0.0_8080/#0.0.0.0/csp/
对 example.c、
进行以下更改- 添加以下#pragma 指令,
#pragma include "/home/user/aerospike-client-c/examples/utils/src/include/"
这将有助于搜索example_utils.h
,这对于 C 客户端中的所有示例脚本都是必需的。 - 添加以下#pragma 指令,
#pragma link "/home/user/aerospike-client-c/examples/utils/src/main/example_utils.c"
我们必须 link example_utils.c,因为它具有示例脚本中使用的所有实用程序函数的定义。
- 添加以下#pragma 指令,
更改 return 值。重新调整正确的 HTTP 错误代码。
现在,您可以开始了。 运行
./gwan
服务器并通过浏览器访问您的网络服务,http://127.0.0.1:8080/?example.c