Coder Social home page Coder Social logo

nebula-cpp's Introduction

How to use cpp client lib

Option One: Get package from github

Down package

wget https://github.com/vesoft-inc/nebula-cpp/releases/download/$release-version/nebula-graph-client-$version.$system.x86_64.rpm

Install lib to local

  • Centos
bash> sudo rpm -ivh nebula-graph-client-$version.$system.x86_64.rpm
  • Ubuntu
bash> sudo dpkg -i nebula-graph-client-$version.$system.amd64.deb

Update the dynamic library cache

bash> ldconfig

Option Two: Build by source code

clone nebula src

git clone https://github.com/vesoft-inc/nebula-cpp.git

build

bash> cd nebula-cpp && mkdir build && cd build
bash> cmake ..
bash> make && sudo make install

If your g++ can't support c++11, you need to configure building by cmake like this

bash> cmake -DDISABLE_CXX11_ABI=ON ..

after finish building, cp the lib and include files to your dir

How to use in your code

  • Step 1: init arvs(a process can only call once)
  • Step 2: init connection pool, the default connections is 10, timeout is 1000 ms (a process can only call once),
  • Step 3: get a session
  • Step 4: execute your statements
  • Step 5: release session

Please refer to the sample code on detail usage.

build and run example code If your g++ version is more than 5.0

LIBRARY_PATH=${Your Installed Library Folder}:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I${Your Installed Include folder} -lnebula_graph_client -o session_example

If your g++ version is less than 5.0

LIBRARY_PATH=${Your Installed Library Folder}:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I${Your Installed Include folder} -lnebula_graph_client -o session_example -D _GLIBCXX_USE_CXX11_ABI=0

Run the example (require a available nebula graph 2.0 server in '127.0.0.1:9669')

LD_LIBRARY_PATH=${Your Installed Library Folder}:$LD_LIBRARY_PATH ./session_example

Or if you're familiar to cmake you could try build and run by cmake directly.

Note: If you install by rpm or deb package, the default install path of rpm or deb package is /usr/local/nebula, the ${Your Installed Library Folder} is /usr/local/nebula/lib or /usr/local/nebula/lib64, the ${Your Installed Include folder} is /usr/local/nebula/include

nebula-cpp's People

Contributors

caton-hpg avatar chrischen2023 avatar dutor avatar hacky-dh avatar harrischu avatar jievince avatar laura-ding avatar panda-sheep avatar rayhuang90 avatar shinji-ikarig avatar shylock-hg avatar songqing avatar winging avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nebula-cpp's Issues

Core issue in nebula-cpp

randomly core issue, the stack is as follows:

#0  0x00007ff16aff5428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ff16aff702a in __GI_abort () at abort.c:89
#2  0x00007ff16afedbd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x7ff16c6f738c "sp >= tls_stackLimit", 
    file=file@entry=0x7ff16c6f70d8 "/usr/src/third-party/third-party/build/folly/source/folly/detail/MemoryIdler.cpp", line=line@entry=172, 
    function=function@entry=0x7ff16c6f7218 "static void folly::detail::MemoryIdler::unmapUnusedStack(size_t)") at assert.c:92
#3  0x00007ff16afedc82 in __GI___assert_fail (assertion=0x7ff16c6f738c "sp >= tls_stackLimit", 
    file=0x7ff16c6f70d8 "/usr/src/third-party/third-party/build/folly/source/folly/detail/MemoryIdler.cpp", line=172, 
    function=0x7ff16c6f7218 "static void folly::detail::MemoryIdler::unmapUnusedStack(size_t)") at assert.c:101
#4  0x00007ff16c36326e in folly::detail::MemoryIdler::unmapUnusedStack(unsigned long) () from libnebula_graph_client.so
#5  0x00007ff16bfa5131 in folly::detail::MemoryIdler::futexWaitPreIdle<std::atomic, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > (_ret=@0x7ff01c7902ec: 32753, fut=..., expected=2, deadline=..., 
    waitMask=4294967295, idleTimeout=..., stackToRetain=1024, timeoutVariationFrac=0.5) at /opt/vesoft/third-party/include/folly/detail/MemoryIdler.h:203
#6  0x00007ff16bfa2452 in folly::detail::MemoryIdler::futexWaitUntil<std::atomic, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > (fut=..., expected=2, deadline=..., waitMask=4294967295, idleTimeout=..., 
    stackToRetain=1024, timeoutVariationFrac=0.5) at /opt/vesoft/third-party/include/folly/detail/MemoryIdler.h:149
#7  0x00007ff16bfa066f in folly::Baton<true, std::atomic>::tryWaitSlow<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > (
    this=0xbc7da70, deadline=..., opt=...) at /opt/vesoft/third-party/include/folly/synchronization/Baton.h:301
#8  0x00007ff16bfa4253 in folly::Baton<true, std::atomic>::wait (opt=..., this=0xbc7da70) at /opt/vesoft/third-party/include/folly/synchronization/Baton.h:176
#9  folly::futures::detail::waitImpl<folly::Future<nebula::ExecutionResponse>, nebula::ExecutionResponse> (f=...)
    at /opt/vesoft/third-party/include/folly/futures/Future-inl.h:1995
#10 0x00007ff16bfa1ac2 in folly::Future<nebula::ExecutionResponse>::wait() & (this=0x7ff01c790558) at /opt/vesoft/third-party/include/folly/futures/Future-inl.h:2150
#11 0x00007ff16bf9f7de in folly::Future<nebula::ExecutionResponse>::get() && (this=0x7ff01c790558) at /opt/vesoft/third-party/include/folly/futures/Future-inl.h:2198
#12 0x00007ff16bf9d22d in nebula::Connection::execute (this=0xa708d88, sessionId=56777298, stmt=...)
    at /home/guojun/source/bigo/dfs_nebula-clients/nebula-cpp/src/client/Connection.cpp:92
#13 0x00007ff16bfb89c0 in nebula::Session::execute (this=0xa708d80, stmt=...) at /home/guojun/source/bigo/dfs_nebula-clients/nebula-cpp/src/client/Session.cpp:13
#14 0x0000000000d191a8 in bigo::rec::push::NebulaSessionHolder::execute (this=0xa9245b0, stmt=...)

Compiled failed on centos 7

gcc 9.3
centos :CentOS Linux release 7.9.2009 (Core)
GNU ld version 2.27-44.base.el7
Copyright (C) 2016 Free Software Foundation, **Inc.**
 29%] Linking CXX shared library ../lib/libnebula_graph_client.so
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.

不确定是不是需要升级ld ?

session_test is blocked

image

gdb:
It's blocked when ping()
image

nebula-graph version: nebula-graph-2021.12.05-nightly.el7.x86_64.tar.gz

The bin/nebula-console can execute YIELD 1 successfully.

using client exception

G++ 7.5.0
CMAKE 3.15

[vesoft@cooper include]$ sudo LIBRARY_PATH=/usr/local/nebula/lib64:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I/usr/local/nebula/include  -lnebula_graph_client -o session_example
In file included from /usr/local/nebula/include/common/datatypes/DataSet.h:15:0,
                 from /usr/local/nebula/include/common/graph/Response.h:15,
                 from /usr/local/nebula/include/nebula/client/Connection.h:13,
                 from /usr/local/nebula/include/nebula/client/ConnectionPool.h:15,
                 from SessionExample.cpp:12:
/usr/local/nebula/include/common/datatypes/Value.h:418:36: 错误:expected ‘,’ before ‘)’ token
 static_assert(sizeof(Value) == 16UL);
                                    ^
/usr/local/nebula/include/common/datatypes/Value.h:418:36: 错误:expected string-literal before ‘)’ token

Memory leak in some conditions.

➜  build git:(fix/asan) ✗ ./bin/test/connection_test
[==========] Running 6 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 6 tests from ConnectionTest
[ RUN      ] ConnectionTest.Basic
I1215 17:46:28.031438 36440 ConnectionTest.cpp:120] Testing once.
E1215 17:46:28.031808 36440 Connection.cpp:217] Ping failed: Not open connection.
E1215 17:46:29.054208 36440 Connection.cpp:217] Ping failed: Not open connection.
E1215 17:46:29.054322 36440 Connection.cpp:217] Ping failed: Not open connection.
I1215 17:46:29.054392 36440 ConnectionTest.cpp:122] Testing reopen.
E1215 17:46:29.054426 36440 Connection.cpp:217] Ping failed: Not open connection.
E1215 17:46:30.066576 36440 Connection.cpp:217] Ping failed: Not open connection.
E1215 17:46:30.066687 36440 Connection.cpp:217] Ping failed: Not open connection.
[       OK ] ConnectionTest.Basic (2037 ms)
[ RUN      ] ConnectionTest.Timeout
[       OK ] ConnectionTest.Timeout (30142 ms)
[ RUN      ] ConnectionTest.SSL
[       OK ] ConnectionTest.SSL (14 ms)
[ RUN      ] ConnectionTest.JsonResult
[       OK ] ConnectionTest.JsonResult (5 ms)
[ RUN      ] ConnectionTest.InvalidPort
E1215 17:47:00.229737 36440 Connection.cpp:120] Failed to verify client version: Channel is !good()
[       OK ] ConnectionTest.InvalidPort (2 ms)
[ RUN      ] ConnectionTest.InvalidHost
E1215 17:47:00.233917 36440 Connection.cpp:86] Invalid address: Invalid Host:9669: Failed to resolve address for 'Invalid Host': Name or service not known (error=-2): Unknown error -2
[       OK ] ConnectionTest.InvalidHost (4 ms)
[----------] 6 tests from ConnectionTest (32204 ms total)

[----------] Global test environment tear-down
[==========] 6 tests from 1 test case ran. (32204 ms total)
[  PASSED  ] 6 tests.

=================================================================
==36440==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 944 byte(s) in 1 object(s) allocated from:
    #0 0xa4d867 in operator new(unsigned long) /usr/src/nebula-package/toolset-build/source/llvm-10.0.0/projects/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
    #1 0x10c80f6 in folly::AsyncSocket::newSocket(folly::EventBase*, folly::SocketAddress const&, unsigned int, bool) /home/shylock.huang/local/vesoft/2.0/third-party/include/folly/io/async/AsyncSocket.h:364:9
    #2 0x10c7946 in nebula::Connection::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, unsigned int, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::$_0::operator()() const /home/shylock.huang/nebula-cpp2/src/client/Connection.cpp:97:22
    #3 0x10c7094 in void folly::detail::function::FunctionTraits<void ()>::callBig<nebula::Connection::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, unsigned int, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::$_0>(folly::detail::function::Data&) /home/shylock.huang/local/vesoft/2.0/third-party/include/folly/Function.h:385:7
    #4 0x145abf1  (/home/shylock.huang/nebula-cpp2/build/bin/test/connection_test+0x145abf1)
    #5 0x17be1df1c23ee  (<unknown module>)

SUMMARY: AddressSanitizer: 944 byte(s) leaked in 1 allocation(s).

Not able to make nebula client work for standalone nebula graph

I have installed nebulagraph standalone for linux with the below mentioned installation steps. However I'm not able to make the client work.

Installation steps : Built from source

  1. Nebulagraph (Standalone)
    $ git clone --branch release-3.3 https://github.com/vesoft-inc/nebula.git
    $ cd nebula
    $ mkdir build && cd build
    $ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF -DENABLE_STANDALONE_VERSION=on -
    DCMAKE_BUILD_TYPE=Release ..
    $ make -j2
    $ sudo make install

  2. Nebula cpp client
    $ git clone --branch release-3.3 https://github.com/vesoft-inc/nebula-cpp.git
    $ cd nebula-cpp
    $ mkdir build && cd build
    $ cmake -DCMAKE_BUILD_TYPE=Release ..
    $ make
    $ sudo make install
    $ sudo ldconfig

  3. Start the nebula service
    $ sudo /usr/local/nebula/scripts/nebula.service start all

  4. Compile example code (SessionExample.cpp)
    $ LIBRARY_PATH=/usr/local/nebula/lib:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I/usr/local/nebula/include -lnebula_graph_client -o session_example

  5. Run session_example
    $ ./session_example

  6. I get the below log after the above step and the program doesn't terminate (gets stuck in ConnectionPool init function)
    $ Current address : 127.0.0.1:9669

multi insert statments in one session execution may cause incorrect data insertion

Hi, I want to merge small insert statments into one statment and execute it in one session execution. But it results in wrong data insertion which loses some vertexes compared to one insertion statement per one session execution.
Am I using it in the wrong way, why?

session.asyncexute(sql1);session.asyncexute(sql2);
-->
session.asyncexute(sql1;sql2);

SessionPool error

Please check the FAQ documentation before raising an issue

Describe the bug (required)

When I use SessionPool to test, I encountered some error messages, for example,
Channel got EOF. Check for server hitting connection limit, server connection idle timeout, and server crashes.bad ,
AsyncSocketException: writev failed (peer=xx:9669, local=172.17.0.2:43164), type = Internal error, errno = 104 (Connection reset by peer): Connection reset by peer

I noticed that when the client didn't send any request over 20 minutes, then did a query, the error would appear, and graphd's config option "client_idle_timeout_secs" and "session_idle_timeout_secs" is 2h.

It seems that the error has something with the idle time, but not consistent with graphd's idle time config.
So, it's weird, can someone help me?

Your Environments (required)

  • OS: uname -a :centos7
  • Commit id (e.g. a3ffc7d8) : master

How To Reproduce(required)

Steps to reproduce the behavior:

  1. Step 1
  2. Step 2
  3. Step 3

Expected behavior

Additional context

The schema statements execution returns ok but still insert failed saying no schema found

My application needs to create graph schema online everytime. The session.execute() function executes schema statments well and returns nebula::ErrorCode::SUCCEEDED. But I still fail when I invoke session.execute() to insert vertexes. If I add some delay time between the two actions , it works well. It seems that there is a delay for schema creatation, what should I do to tell when could I execute insertion commands after execution of schema statemetns?

undefined reference to `nebula::ConnectionPool::init

when i try to compile the client some errors happend

[root@xafj-palo-rpm64 examples]# ll /usr/local/nebula/include/nebula/
total 24
drwxr-xr-x 2 root root 4096 Mar 26 08:09 client
drwxr-xr-x 2 root root 4096 Feb  6 06:04 common
drwxr-xr-x 2 root root 4096 Feb  6 06:04 graph
drwxr-xr-x 2 root root 4096 Mar 26 08:09 mclient
drwxr-xr-x 2 root root 4096 Mar 26 08:09 sclient
drwxr-xr-x 2 root root 4096 Feb  6 06:04 storage

[root@xafj-palo-rpm64 examples]# ll /usr/local/nebula/lib64
total 56092
-rwxr-xr-x 1 root root 12853496 Feb  6 06:04 libnebula_graph_client.so
-rwxr-xr-x 1 root root 20857576 Feb  6 06:04 libnebula_meta_client.so
-rwxr-xr-x 1 root root 23719896 Feb  6 06:04 libnebula_storage_client.so
[root@xafj-palo-rpm64 examples]# LIBRARY_PATH=/usr/local/nebula/lib64:$LIBRARY_PATH  g++ -std=c++11 SessionExample.cpp -I/usr/local/nebula/include  -lnebula_graph_client
/tmp/ccOd1hjO.o: In function `main':
SessionExample.cpp:(.text+0x253): undefined reference to `nebula::ConnectionPool::init(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, nebula::Config const&)'
SessionExample.cpp:(.text+0x33c): undefined reference to `nebula::ConnectionPool::getSession(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
SessionExample.cpp:(.text+0x3e7): undefined reference to `nebula::Session::execute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
SessionExample.cpp:(.text+0x4ef): undefined reference to `nebula::Session::asyncExecute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (nebula::ExecutionResponse&&)>)'
/tmp/ccOd1hjO.o: In function `nebula::operator<<(std::ostream&, nebula::Value const&)':
SessionExample.cpp:(.text._ZN6nebulalsERSoRKNS_5ValueE[_ZN6nebulalsERSoRKNS_5ValueE]+0x2f): undefined reference to `nebula::Value::toString[abi:cxx11]() const'
collect2: error: ld returned 1 exit status

Compiled failed on centos 7

gcc 9.3
centos :CentOS Linux release 7.9.2009 (Core)
GNU ld version 2.27-44.base.el7
Copyright (C) 2016 Free Software Foundation, **Inc.**
 29%] Linking CXX shared library ../lib/libnebula_graph_client.so
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.

不确定是不是需要升级ld ?

nebula-cpp-client 当前是否有商用案例?

我们有一个服务想要在nebula graph上做测试是否可行,客户端是c++的,想咨询一下当前是否有基于nebula-cpp的实际用例,我看当前只实现了简单的sesssion 管理和执行?

CMake version too old causing issues.

报错:
CMake Error at CMakeLists.txt:61 (export):
export given OBJECT library "nebula_common_obj" which may not be exported.
Call Stack (most recent call first):
src/CMakeLists.txt:143 (nebula_add_library)

CMake Error at CMakeLists.txt:61 (export):
export given OBJECT library "nebula_graph_client_obj" which may not be
exported.
Call Stack (most recent call first):
src/CMakeLists.txt:148 (nebula_add_library)

CMake Error at CMakeLists.txt:61 (export):
export given OBJECT library "nebula_meta_client_obj" which may not be
exported.
Call Stack (most recent call first):
src/CMakeLists.txt:153 (nebula_add_library)

CMake Error at CMakeLists.txt:61 (export):
export given OBJECT library "nebula_storage_client_obj" which may not be
exported.
Call Stack (most recent call first):
src/CMakeLists.txt:158 (nebula_add_library)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.