├── .clang-format ├── .github ├── actions │ ├── tagname-action │ │ ├── README.md │ │ └── action.yml │ └── upload-assets-action │ │ ├── README.md │ │ └── action.yml └── workflows │ ├── check_label.yml │ ├── doxygen.yml │ ├── pull_request.yml │ └── release.yml ├── .gitignore ├── .licenserc.yaml ├── .linters └── cpp │ ├── cpplint.py │ └── hooks │ └── pre-commit.sh ├── CMakeLists.txt ├── LICENSE ├── README.md ├── SECURITY.md ├── certs ├── test.2.crt ├── test.2.csr ├── test.2.key ├── test.2.password ├── test.ca.key ├── test.ca.password ├── test.ca.pem ├── test.ca.srl ├── test.derive.crt ├── test.derive.csr └── test.derive.key ├── cmake ├── CPackage.cmake ├── ClangTidy.cmake ├── FetchModule.cmake ├── FindBreakpad.cmake ├── FindBzip2.cmake ├── FindDoubleConversion.cmake ├── FindFatal.cmake ├── FindFbthrift.cmake ├── FindFizz.cmake ├── FindFolly.cmake ├── FindGPERF.cmake ├── FindGflags.cmake ├── FindGlog.cmake ├── FindGoogletest.cmake ├── FindJemalloc.cmake ├── FindKrb5.cmake ├── FindLibevent.cmake ├── FindLibunwind.cmake ├── FindMstch.cmake ├── FindNCURSES.cmake ├── FindPCHSupport.cmake ├── FindProxygen.cmake ├── FindReadline.cmake ├── FindRocksdb.cmake ├── FindSnappy.cmake ├── FindSodium.cmake ├── FindWangle.cmake ├── FindZstd.cmake ├── ThriftGenerate.cmake └── nebula │ ├── ABIConfig.cmake │ ├── CcacheConfig.cmake │ ├── ConfigNebulaClient.cmake │ ├── GeneralCMakeConfig.cmake │ ├── GeneralCMakeOptions.cmake │ ├── GeneralCompilerConfig.cmake │ ├── GitHooksConfig.cmake │ ├── GitInfoConfig.cmake │ ├── InstallThirdParty.cmake │ ├── LinkerConfig.cmake │ ├── MakeBisonRelocatable.cmake │ ├── NebulaCMakeMacros.cmake │ ├── NebulaCustomTargets.cmake │ ├── PlatformCheck.cmake │ ├── SanitizerConfig.cmake │ └── ThirdPartyConfig.cmake ├── date.py ├── doxygen-config ├── examples ├── CMakeLists.txt ├── SessionExample.cpp ├── SessionPoolExample.cpp └── StorageClientExample.cpp ├── exported-symbols.map ├── gen-interface.sh ├── include ├── common │ ├── Init.h │ ├── datatypes │ │ ├── CommonCpp2Ops.h │ │ ├── DataSet.h │ │ ├── DataSetOps-inl.h │ │ ├── Date.h │ │ ├── DateOps-inl.h │ │ ├── Duration.h │ │ ├── DurationOps-inl.h │ │ ├── Edge.h │ │ ├── EdgeOps-inl.h │ │ ├── Geography.h │ │ ├── GeographyOps-inl.h │ │ ├── HostAddr.h │ │ ├── HostAddrOps-inl.h │ │ ├── KeyValue.h │ │ ├── KeyValueOps-inl.h │ │ ├── List.h │ │ ├── ListOps-inl.h │ │ ├── Map.h │ │ ├── MapOps-inl.h │ │ ├── Path.h │ │ ├── PathOps-inl.h │ │ ├── Set.h │ │ ├── SetOps-inl.h │ │ ├── Value.h │ │ ├── ValueOps-inl.h │ │ ├── Vertex.h │ │ └── VertexOps-inl.h │ ├── geo │ │ └── io │ │ │ ├── wkb │ │ │ ├── ByteOrder.h │ │ │ ├── ByteOrderDataIOStream.h │ │ │ └── WKBWriter.h │ │ │ └── wkt │ │ │ └── WKTWriter.h │ ├── graph │ │ ├── AuthResponseOps-inl.h │ │ ├── ExecutionResponseOps-inl.h │ │ ├── GraphCpp2Ops.h │ │ ├── PairOps-inl.h │ │ ├── PlanDescriptionOps-inl.h │ │ ├── PlanNodeBranchInfoOps-inl.h │ │ ├── PlanNodeDescriptionOps-inl.h │ │ ├── ProfilingStatsOps-inl.h │ │ ├── Response.h │ │ ├── VerifyClientVersionReqOps-inl.h │ │ └── VerifyClientVersionRespOps-inl.h │ ├── thrift │ │ ├── ThriftCpp2OpsHelper.h │ │ └── ThriftTypes.h │ ├── time │ │ ├── Constants.h │ │ └── TimeConversion.h │ └── utils │ │ └── utils.h └── nebula │ ├── client │ ├── Config.h │ ├── Connection.h │ ├── ConnectionPool.h │ ├── Session.h │ └── SessionPool.h │ ├── common │ └── .gitkeep │ ├── graph │ └── .gitkeep │ ├── mclient │ ├── MConfig.h │ └── MetaClient.h │ ├── sclient │ ├── SConfig.h │ ├── ScanEdgeIter.h │ ├── ScanVertexIter.h │ └── StorageClient.h │ └── storage │ └── .gitkeep ├── package ├── package.sh ├── postinst └── rpm_postinst ├── src ├── CMakeLists.txt ├── Init.cpp ├── SSLConfig.cpp ├── SSLConfig.h ├── client │ ├── CMakeLists.txt │ ├── Connection.cpp │ ├── ConnectionPool.cpp │ ├── Session.cpp │ ├── SessionPool.cpp │ └── tests │ │ ├── AddressTest.cpp │ │ ├── CMakeLists.txt │ │ ├── ClientTest.h │ │ ├── ConfigTest.cpp │ │ ├── ConnectionSSLTest.cpp │ │ ├── ConnectionTest.cpp │ │ ├── RegistHost.cpp │ │ ├── SessionPoolTest.cpp │ │ ├── SessionSSLTest.cpp │ │ ├── SessionTest.cpp │ │ └── TimezoneConversionTest.cpp ├── datatypes │ ├── Date.cpp │ ├── Duration.cpp │ ├── Edge.cpp │ ├── Geography.cpp │ ├── HostAddr.cpp │ ├── List.cpp │ ├── Map.cpp │ ├── Path.cpp │ ├── Set.cpp │ ├── Value.cpp │ └── Vertex.cpp ├── geo │ └── io │ │ ├── wkb │ │ ├── ByteOrderDataIOStream.cpp │ │ └── WKBWriter.cpp │ │ └── wkt │ │ └── WKTWriter.cpp ├── interface │ ├── CMakeLists.txt │ ├── common.thrift │ ├── gen-cpp2 │ │ ├── GeneralStorageService.cpp │ │ ├── GeneralStorageService.h │ │ ├── GeneralStorageService.tcc │ │ ├── GeneralStorageServiceAsyncClient.cpp │ │ ├── GeneralStorageServiceAsyncClient.h │ │ ├── GeneralStorageService_custom_protocol.h │ │ ├── GeneralStorageService_processmap_binary.cpp │ │ ├── GeneralStorageService_processmap_compact.cpp │ │ ├── GraphService.cpp │ │ ├── GraphService.h │ │ ├── GraphService.tcc │ │ ├── GraphServiceAsyncClient.cpp │ │ ├── GraphServiceAsyncClient.h │ │ ├── GraphService_custom_protocol.h │ │ ├── GraphService_processmap_binary.cpp │ │ ├── GraphService_processmap_compact.cpp │ │ ├── GraphStorageService.cpp │ │ ├── GraphStorageService.h │ │ ├── GraphStorageService.tcc │ │ ├── GraphStorageServiceAsyncClient.cpp │ │ ├── GraphStorageServiceAsyncClient.h │ │ ├── GraphStorageService_custom_protocol.h │ │ ├── GraphStorageService_processmap_binary.cpp │ │ ├── GraphStorageService_processmap_compact.cpp │ │ ├── InternalStorageService.cpp │ │ ├── InternalStorageService.h │ │ ├── InternalStorageService.tcc │ │ ├── InternalStorageServiceAsyncClient.cpp │ │ ├── InternalStorageServiceAsyncClient.h │ │ ├── InternalStorageService_custom_protocol.h │ │ ├── InternalStorageService_processmap_binary.cpp │ │ ├── InternalStorageService_processmap_compact.cpp │ │ ├── MetaService.cpp │ │ ├── MetaService.h │ │ ├── MetaService.tcc │ │ ├── MetaServiceAsyncClient.cpp │ │ ├── MetaServiceAsyncClient.h │ │ ├── MetaService_custom_protocol.h │ │ ├── MetaService_processmap_binary.cpp │ │ ├── MetaService_processmap_compact.cpp │ │ ├── StorageAdminService.cpp │ │ ├── StorageAdminService.h │ │ ├── StorageAdminService.tcc │ │ ├── StorageAdminServiceAsyncClient.cpp │ │ ├── StorageAdminServiceAsyncClient.h │ │ ├── StorageAdminService_custom_protocol.h │ │ ├── StorageAdminService_processmap_binary.cpp │ │ ├── StorageAdminService_processmap_compact.cpp │ │ ├── common_constants.cpp │ │ ├── common_constants.h │ │ ├── common_data.cpp │ │ ├── common_data.h │ │ ├── common_for_each_field.h │ │ ├── common_metadata.cpp │ │ ├── common_metadata.h │ │ ├── common_types.cpp │ │ ├── common_types.h │ │ ├── common_types.tcc │ │ ├── common_types_custom_protocol.h │ │ ├── common_visit_by_thrift_field_metadata.h │ │ ├── common_visit_union.h │ │ ├── common_visitation.h │ │ ├── graph_constants.cpp │ │ ├── graph_constants.h │ │ ├── graph_data.cpp │ │ ├── graph_data.h │ │ ├── graph_for_each_field.h │ │ ├── graph_metadata.cpp │ │ ├── graph_metadata.h │ │ ├── graph_types.cpp │ │ ├── graph_types.h │ │ ├── graph_types.tcc │ │ ├── graph_types_custom_protocol.h │ │ ├── graph_visit_by_thrift_field_metadata.h │ │ ├── graph_visit_union.h │ │ ├── graph_visitation.h │ │ ├── meta_constants.cpp │ │ ├── meta_constants.h │ │ ├── meta_data.cpp │ │ ├── meta_data.h │ │ ├── meta_for_each_field.h │ │ ├── meta_metadata.cpp │ │ ├── meta_metadata.h │ │ ├── meta_types.cpp │ │ ├── meta_types.h │ │ ├── meta_types.tcc │ │ ├── meta_types_custom_protocol.h │ │ ├── meta_visit_by_thrift_field_metadata.h │ │ ├── meta_visit_union.h │ │ ├── meta_visitation.h │ │ ├── storage_constants.cpp │ │ ├── storage_constants.h │ │ ├── storage_data.cpp │ │ ├── storage_data.h │ │ ├── storage_for_each_field.h │ │ ├── storage_metadata.cpp │ │ ├── storage_metadata.h │ │ ├── storage_types.cpp │ │ ├── storage_types.h │ │ ├── storage_types.tcc │ │ ├── storage_types_custom_protocol.h │ │ ├── storage_visit_by_thrift_field_metadata.h │ │ ├── storage_visit_union.h │ │ └── storage_visitation.h │ ├── graph.thrift │ ├── meta.thrift │ └── storage.thrift ├── mclient │ ├── CMakeLists.txt │ ├── MetaClient.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ ├── MClientTest.h │ │ ├── MetaClientSSLTest.cpp │ │ └── MetaClientTest.cpp ├── sclient │ ├── CMakeLists.txt │ ├── ScanEdgeIter.cpp │ ├── ScanVertexIter.cpp │ ├── StorageClient.cpp │ └── tests │ │ ├── CMakeLists.txt │ │ ├── SClientTest.h │ │ ├── StorageClientSSLTest.cpp │ │ └── StorageClientTest.cpp ├── thrift │ ├── ThriftClientManager-inl.h │ └── ThriftClientManager.h └── time │ └── TimeConversion.cpp └── third-party ├── cxx-compiler-abi-version.sh ├── install-cmake.sh ├── install-gcc.sh └── install-third-party.sh /.github/actions/tagname-action/README.md: -------------------------------------------------------------------------------- 1 | # Extract tag name 2 | 3 | Extract tag name from release branch 4 | 5 | ## Outputs 6 | 7 | ### `tag` 8 | 9 | tag name 10 | 11 | ## Example usage 12 | 13 | ```yaml 14 | - uses: ./.github/actions/tagname-action 15 | id: tag 16 | 17 | - name: Other step 18 | run: echo ${{ steps.tag.outputs.tag }} 19 | ``` 20 | -------------------------------------------------------------------------------- /.github/actions/tagname-action/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Extract tag name' 2 | description: 'Extract tag name' 3 | outputs: 4 | tag: 5 | description: 'tag name' 6 | value: ${{ steps.tag.outputs.tag }} 7 | runs: 8 | using: "composite" 9 | steps: 10 | - id: tag 11 | run: | 12 | tag=$(echo ${{ github.ref }} | rev | cut -d/ -f1 | rev) 13 | echo "::set-output name=tag::$tag" 14 | shell: bash 15 | -------------------------------------------------------------------------------- /.github/actions/upload-assets-action/README.md: -------------------------------------------------------------------------------- 1 | # Upload file to release assets 2 | 3 | Upload file to release assets 4 | 5 | ## Inputs 6 | 7 | ### `tag` 8 | 9 | **Required** tag name of release branch. Default `${{ github.ref }}`. 10 | 11 | ### `file-path` 12 | 13 | **Required** file path to be uploaded. Default `''`. 14 | 15 | ## Example usage 16 | 17 | ```yaml 18 | uses: ./.github/actions/upload-assets-action 19 | with: 20 | file-path: ${{ steps.pkg.outputs.filepath }} 21 | tag: ${{ steps.tag.outputs.tag }} 22 | ``` 23 | -------------------------------------------------------------------------------- /.github/actions/upload-assets-action/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Upload release assets' 2 | description: 'Upload file to release assets' 3 | inputs: 4 | tag: 5 | description: 'git tag' 6 | required: true 7 | default: ${{ github.ref }} 8 | file-path: 9 | description: 'file path to be uploaded' 10 | required: true 11 | default: '' 12 | runs: 13 | using: "composite" 14 | steps: 15 | - run: | 16 | GH_RELEASE="https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.tag }}" 17 | upload_url=$(curl -s --request GET --url $GH_RELEASE | grep -oP '(?<="upload_url": ")[^"]*' | cut -d'{' -f1) 18 | content_type=$(file -b --mime-type ${{ inputs.file-path }}) 19 | filename=$(basename "${{ inputs.file-path }}") 20 | echo "Uploading asset... " 21 | curl --silent \ 22 | --request POST \ 23 | --url "$upload_url?name=$filename" \ 24 | --header "authorization: Bearer ${{ github.token }}" \ 25 | --header "content-type: $content_type" \ 26 | --data-binary @"${{ inputs.file-path }}" 27 | shell: bash 28 | -------------------------------------------------------------------------------- /.github/workflows/check_label.yml: -------------------------------------------------------------------------------- 1 | name: Auto label 2 | 3 | on: 4 | issues: 5 | types: 6 | - reopened 7 | - opened 8 | - labeled 9 | - unlabeled 10 | - closed 11 | 12 | env: 13 | GH_PAT: ${{ secrets.GITHUB_TOKEN }} 14 | EVENT: ${{ toJSON(github.event)}} 15 | EVENT_NAME: ${{ github.event_name}} 16 | 17 | jobs: 18 | sync: 19 | name: auto label 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: HarrisChu/auto_label@v1 23 | -------------------------------------------------------------------------------- /.github/workflows/doxygen.yml: -------------------------------------------------------------------------------- 1 | name: Generate API reference via Doxygen and push to GitHub Pages 2 | env: 3 | # Specify the doc version to which the API reference belongs 4 | doc_version: 3.6.0 5 | on: 6 | push: 7 | branches: 8 | # Remember to update the branch name when you create a new branch 9 | - master 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v4 18 | with: 19 | fetch-depth: 0 # fetch all commits/branches for gitversion 20 | 21 | - name: Extract branch name 22 | run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV 23 | 24 | - name: Install Doxygen 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install -y doxygen graphviz 28 | 29 | # Generate HTML files 30 | - name: Generate Documentation 31 | run: | 32 | echo "OUTPUT_DIRECTORY=$BRANCH_NAME" >> doxygen-config 33 | doxygen doxygen-config 34 | 35 | # Deploy the generated HTML files to the gh-pages branch 36 | - name: Deploy to gh-pages 37 | uses: JamesIves/github-pages-deploy-action@v4 38 | with: 39 | folder: ${{ env.BRANCH_NAME }}/html 40 | target-folder: ${{ env.BRANCH_NAME }} 41 | 42 | # - name: show gh-pages branch 43 | # run: | 44 | # git branch 45 | # git checkout . 46 | # git checkout gh-pages 47 | 48 | # # Compresses HTML files into a tar.gz file 49 | # - name: compress api reference 50 | # run: | 51 | # tar -zcvf $BRANCH_NAME.tar.gz $BRANCH_NAME 52 | 53 | # - name: transfer api reference 54 | # uses: appleboy/scp-action@master 55 | # with: 56 | # host: 20.163.77.63 57 | # username: azureuser 58 | # password: ${{ secrets.ENSITE_PASSWORD }} 59 | # port: 404 60 | # source: $BRANCH_NAME.tar.gz 61 | # # Return error if the target doc version does not already exist 62 | # target: /var/www/ent-docs/${{ env.doc_version }}/ 63 | 64 | # - name: uncompress ap reference 65 | # uses: appleboy/ssh-action@master 66 | # with: 67 | # host: 20.163.77.63 68 | # username: azureuser 69 | # password: ${{ secrets.ENSITE_PASSWORD }} 70 | # port: 404 71 | # script: | 72 | # mkdir -p /var/www/ent-docs/${{ env.doc_version}}/api/python/ 73 | # tar -zxf /var/www/ent-docs/${{ env.doc_version}}/$BRANCH_NAME.tar.gz -C /var/www/ent-docs/${{ env.doc_version}}/api/python/ -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: cpp_release 2 | 3 | on: 4 | release: 5 | types: 6 | - published 7 | 8 | defaults: 9 | run: 10 | shell: bash 11 | 12 | jobs: 13 | cpp-package: 14 | name: package 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | os: 20 | - ubuntu1604 21 | - ubuntu1804 22 | - ubuntu2004 23 | - centos6 24 | - centos7 25 | - centos8 26 | container: 27 | image: vesoft/nebula-dev:${{ matrix.os }} 28 | steps: 29 | - uses: actions/checkout@v1 30 | - uses: ./.github/actions/tagname-action 31 | id: tag 32 | - name: package 33 | if: ${{ contains(fromJson('["centos6", "centos7"]'), matrix.os) }} 34 | run: ./package/package.sh -b ${{ steps.tag.outputs.tag }} -a ON 35 | - name: package abi 11 36 | if: ${{ contains(fromJson('["centos8", "ubuntu1604", "ubuntu1804", "ubuntu2004"]'), matrix.os) }} 37 | run: ./package/package.sh -b ${{ steps.tag.outputs.tag }} 38 | - name: Get package name 39 | id: pkg 40 | run: | 41 | echo "::set-output name=filepath::$(find build/cpack_output -type f \( -iname \*.deb -o -iname \*.rpm \))" 42 | - uses: ./.github/actions/upload-assets-action 43 | with: 44 | file-path: ${{ steps.pkg.outputs.filepath }} 45 | tag: ${{ steps.tag.outputs.tag }} 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | # Prerequisites 3 | *.d 4 | 5 | # Compiled Object files 6 | *.slo 7 | *.lo 8 | *.o 9 | *.obj 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Compiled Dynamic libraries 16 | *.so 17 | *.dylib 18 | *.dll 19 | 20 | # Fortran module files 21 | *.mod 22 | *.smod 23 | 24 | # Compiled Static libraries 25 | *.lai 26 | *.la 27 | *.a 28 | *.lib 29 | 30 | # Executables 31 | *.exe 32 | *.out 33 | *.app 34 | 35 | _build 36 | build 37 | modules 38 | 39 | # IDE 40 | .vscode/ 41 | 42 | # Coredump 43 | core.* 44 | 45 | .cache 46 | -------------------------------------------------------------------------------- /.licenserc.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 vesoft inc. All rights reserved. 3 | # 4 | # This source code is licensed under Apache 2.0 License. 5 | header: 6 | license: 7 | spdx-id: Apache-2.0 8 | copyright-owner: vesoft inc 9 | content: | 10 | Copyright (c) 2020 vesoft inc. All rights reserved. 11 | This source code is licensed under Apache 2.0 License. 12 | pattern: | 13 | Copyright (c) \d{4} vesoft inc. All rights reserved. 14 | This source code is licensed under Apache 2.0 License. 15 | paths-ignore: 16 | - '.licenserc.yaml' 17 | - '.clang-tidy' 18 | - '.dockerignore' 19 | - '**/.gitignore' 20 | - 'cmake' 21 | - 'package' 22 | - 'src/**/*.thrift' 23 | - 'src/**/*.lex' 24 | - 'src/**/*.yy' 25 | - 'src/**/*.dict' 26 | - 'src/**/*.in' 27 | - '.github' 28 | - '.linters' 29 | - '**/*.md' 30 | - 'third-party' 31 | - 'LICENSE' 32 | - 'NOTICE' 33 | - 'certs' 34 | - 'src/interface/gen-cpp2' 35 | - '.gitkeep' 36 | - 'include/common/datatypes/ValueOps-inl.h' 37 | 38 | comment: on-failure 39 | -------------------------------------------------------------------------------- /.linters/cpp/hooks/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2018 vesoft inc. All rights reserved. 4 | # 5 | # This source code is licensed under Apache 2.0 License. 6 | 7 | CPPLINT=`dirname $0`/../../.linters/cpp/cpplint.py 8 | 9 | if [ $# -eq 0 ];then 10 | # Since cpplint.py could only apply on our working tree, 11 | # so we forbid committing with unstaged changes present. 12 | # Otherwise, lints can be bypassed via changing without commit. 13 | if ! git diff-files --exit-code --quiet 14 | then 15 | echo "You have unstaged changes, please stage or stash them first." 16 | exit 1 17 | fi 18 | CHECK_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | egrep '.*\.cpp$|.*\.h$|.*\.inl$' | grep -v 'com_vesoft_client_NativeClient.h' | grep -v 'com_vesoft_nebula_NebulaCodec.h' | grep -v 'interface') 19 | else 20 | CHECK_FILES=$(find $@ -not \( -path src/CMakeFiles -prune \) \ 21 | -not \( -path src/interface/gen-cpp2 -prune \) \ 22 | -name "*.[h]" -o -name "*.cpp" -o -name '*.inl' \ 23 | | grep -v 'GraphScanner.*' | grep -v 'GraphParser.*' \ 24 | | grep -v 'com_vesoft_client_NativeClient.h' \ 25 | | grep -v 'com_vesoft_nebula_NebulaCodec.h') 26 | fi 27 | 28 | # No changes on interested files 29 | if [[ -z $CHECK_FILES ]]; then 30 | echo "There's no source files to perform C++ linters..." 31 | exit 0 32 | fi 33 | 34 | echo "Performing C++ linters..." 35 | 36 | CPPLINT_EXTENS=cpp,h,inl 37 | CPPLINT_FILTER=-whitespace/indent,-build/include_what_you_use,-readability/todo,-build/include,-build/header_guard,-runtime/references,-build/c++11 38 | 39 | python3 $CPPLINT --quiet --extensions=$CPPLINT_EXTENS \ 40 | --filter=$CPPLINT_FILTER --linelength=100 $CHECK_FILES 2>&1 41 | 42 | result=$? 43 | if [ $result -eq 0 ] 44 | then 45 | exit 0 46 | else 47 | echo "cpplint code style check failed, please fix and recommit." 48 | exit 1 49 | fi 50 | 51 | echo "Performing C++ code format check..." 52 | 53 | CLANG_HOME=/opt/vesoft/toolset/clang/10.0.0/ 54 | 55 | if [ ! -d "$CLANG_HOME" ]; then 56 | echo "The $CLANG_HOME directory is not found, and the source changes cannot be automatically formatted." 57 | exit 0 58 | fi 59 | 60 | git diff -U0 --no-color --staged | $CLANG_HOME/share/clang/clang-format-diff.py -i -p1 -binary $CLANG_HOME/bin/clang-format 61 | git add $CHECK_FILES 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | How to use cpp client lib 2 | -------------------------------------------- 3 | 4 | ## Option One: Get package from github 5 | 6 | ### Down package 7 | 8 | ```bash 9 | wget https://github.com/vesoft-inc/nebula-cpp/releases/download/$release-version/nebula-graph-client-$version.$system.x86_64.rpm 10 | ``` 11 | 12 | ### Install lib to local 13 | 14 | - Centos 15 | 16 | ```bash 17 | bash> sudo rpm -ivh nebula-graph-client-$version.$system.x86_64.rpm 18 | ``` 19 | 20 | - Ubuntu 21 | 22 | ```bash 23 | bash> sudo dpkg -i nebula-graph-client-$version.$system.amd64.deb 24 | ``` 25 | 26 | ### Update the dynamic library cache 27 | 28 | ```bash 29 | bash> ldconfig 30 | ``` 31 | 32 | ## Option Two: Build by source code 33 | 34 | ### clone nebula src 35 | 36 | ``` 37 | git clone https://github.com/vesoft-inc/nebula-cpp.git 38 | ``` 39 | 40 | ### build 41 | 42 | ```bash 43 | bash> cd nebula-cpp && mkdir build && cd build 44 | bash> cmake .. 45 | bash> make && sudo make install 46 | ``` 47 | 48 | If your g++ can't support c++11, you need to configure building by cmake like this 49 | 50 | ```bash 51 | bash> cmake -DDISABLE_CXX11_ABI=ON .. 52 | ``` 53 | 54 | 55 | after finish building, cp the lib and include files to your dir 56 | 57 | ## How to use in your code 58 | 59 | - Step 1: init arvs(a process can only call once) 60 | - Step 2: init connection pool, the default connections is 10, timeout is 1000 ms (a process can only call once), 61 | - Step 3: get a session 62 | - Step 4: execute your statements 63 | - Step 5: release session 64 | 65 | Please refer to the [sample code](examples/SessionExample.cpp) on detail usage. 66 | 67 | build and run example code 68 | If your g++ version is more than 5.0 69 | 70 | ```bash 71 | 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 72 | ``` 73 | 74 | If your g++ version is less than 5.0 75 | 76 | ```bash 77 | 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 78 | ``` 79 | 80 | Run the example (require a available nebula graph 2.0 server in '127.0.0.1:9669') 81 | 82 | ```bash 83 | LD_LIBRARY_PATH=${Your Installed Library Folder}:$LD_LIBRARY_PATH ./session_example 84 | ``` 85 | 86 | Or if you're familiar to cmake you could try build and run by cmake directly. 87 | 88 | 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` 89 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting New Security Issues with thr Nebula-cpp 4 | 5 | 6 | **We strongly encourage folks to report such security problems to our private security mailing list first, 7 | before disclosing them in a public forum**. 8 | 9 | 10 | ``` 11 | All mail sent to this address that does not relate to security problems in the Nebula-cpp source code will be ignored 12 | ``` 13 | 14 | 15 | 16 | The mailing address is: [security@vesoft.com] 17 | -------------------------------------------------------------------------------- /certs/test.2.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDszCCApsCFHDGB6747rJE8+MWP2IQdEfrONurMA0GCSqGSIb3DQEBCwUAMIGV 3 | MQswCQYDVQQGEwJDTjERMA8GA1UECAwIWmhlamlhbmcxETAPBgNVBAcMCEhhbmd6 4 | aG91MRQwEgYDVQQKDAtWZXNvZnQgSW5jLjEMMAoGA1UECwwDRGV2MRMwEQYDVQQD 5 | DApTaHlsb2NrIEhnMScwJQYJKoZIhvcNAQkBFhhzaHlsb2NrLmh1YW5nQHZlc29m 6 | dC5jb20wHhcNMjMwMTEyMDgyMTA1WhcNMzMwMTA5MDgyMTA1WjCBlTELMAkGA1UE 7 | BhMCQ04xETAPBgNVBAgMCFpoZWppYW5nMREwDwYDVQQHDAhIYW5nemhvdTEUMBIG 8 | A1UECgwLVmVzb2Z0IEluYy4xDDAKBgNVBAsMA0RldjETMBEGA1UEAwwKU2h5bG9j 9 | ayBIZzEnMCUGCSqGSIb3DQEJARYYc2h5bG9jay5odWFuZ0B2ZXNvZnQuY29tMIIB 10 | IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1WFQaXCffwmjwyUJhogVlHdZ 11 | P1PkT/cY6uzQMfiMZibjdsxUrIeNcZU6CGGbS1a+s+BTwuqnOaIWre7qCRtHdzlk 12 | ZaMqFW424WUPCgQxYAekIpw1N8H0gFoj3GqmV+580Ar9Y4L7vUwYwdzMPaFh7AgN 13 | rWDMGOUFXTUW64st2IEIR6M6y0CwFvZMfbIgBrV1oyxfxQnb1OXQQS/Aq0MImstI 14 | fCB+hNhefeGarvJI83O6y0wGXIohTUPKZgkRq+etIw1NzWS3bmCfAt3cwFkvkcMV 15 | GW85OvD1wKCR5vPbTKTs46Nwqoj58+avqwzWvnzYADDRBZBV9/+94ljZ5RbDLwID 16 | AQABMA0GCSqGSIb3DQEBCwUAA4IBAQCxAe7T3POLX16IgQrx416uXunpMBZVEmC/ 17 | 0cr/tX/ZVr1D94pZBDbNBplvrIYM0oGUAlzWuOnGhGONzKMTtsyf1JwG0/I/dg7/ 18 | ng6uhiwDjUuB+dJ+CpoBtFNKr9u+Imw6ApDjcbvaN+ycwHwjBy1XX1SIN5bo+xfk 19 | 2K+dTAxSI1Zlsqs3spGVIc3IqdfUVnbYkNM3Nx3UYxIjgVfVW1WLf7BgsjvStZKF 20 | pqixpST485YibWVxET3GKOJ4/fZwSl3DUGAMIVBZw4l1juZgG2IL5rFB2PPkNybk 21 | 0Xkw4r+RS92NK+CWtfjzQTLGdqxJpLVLt8Ed+q9aA/ugZqT8J3BX 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /certs/test.2.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIC9zCCAd8CAQAwgZUxCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzER 3 | MA8GA1UEBwwISGFuZ3pob3UxFDASBgNVBAoMC1Zlc29mdCBJbmMuMQwwCgYDVQQL 4 | DANEZXYxEzARBgNVBAMMClNoeWxvY2sgSGcxJzAlBgkqhkiG9w0BCQEWGHNoeWxv 5 | Y2suaHVhbmdAdmVzb2Z0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 6 | ggEBALgj6VJTBk7GlbaMW+lwyKjfW+ardnClLbNU+fh0gQGOAffRBz2RiTERzpva 7 | 3gpmG+JuxLOz4mUtcssGYkdX5p2Wpt3r2ne0h15UVth7sovyvmTQrS6opD+IZ9dm 8 | 7lbDxcZBnf+91gXmEB8f9pSc15eIwaUeqGH8s4YiPjVpM7/8VtRfhk5ps4RE2OiW 9 | 1k7vNhxEeBiW9bU5GmY/e8zN4YNJnSo3sXH47KlDekQeA4uZpJkM37GMEmvFImOP 10 | 11OvTIKEbPSuFDEvUKQMDB6xbTe83NUMV7tgMcTzoWbsPH/2GcSVTc32Kf1600tl 11 | as6rl8gU2yrzjesEMOGxnDfFD1sCAwEAAaAcMBoGCSqGSIb3DQEJAjENDAtWZXNv 12 | ZnQgSW5jLjANBgkqhkiG9w0BAQsFAAOCAQEASQzHAVdh3KqljVtxKtKvN2RyKhht 13 | iMYS5YICC7ESLhcZhE4jp/XQ00jYs1tXRIczcmvstY/od9VmPX+ycL4OGUqzRaRF 14 | Y4INCSy2/JIEz8aBoApuFzE5OZe/QS6ihwlZTSVW/Q/lTJeZ2N84Rj6ftlp4ZWLx 15 | 4NtyPuXWXIY/QOHp6rjbUYVcAvhFio2OIgfGFlV5E3rkmb/R2nU3vQ6BNK2sTpt7 16 | 5ovXXbx7UrvS7/YVoP5+fg7iCSPOSA2t9yrD/N5htWSMiUJHp31EaTbNN8yxtVwb 17 | ieAWLAuPrI0xoy6TLh2tDZX4HBw8ZwpBTDyi+tVdJdcsUzRM+w6xoTpjQg== 18 | -----END CERTIFICATE REQUEST----- 19 | -------------------------------------------------------------------------------- /certs/test.2.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQINtWdG0nk//kCAggA 3 | MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECER/BYBcGn8fBIIEyMtKPrObru3d 4 | AS+3X4f0dSRErHSNUMOaiRe82RmklGX6Jrhn6C7C5nUA7poM+FBrbJYX6j9txcY8 5 | 6MhskOXPtDYq4o7T0VQ0w9GIxS13nPEFz0zdRvimDKJPH5+rUhAv6DTM7YqZAf1D 6 | oQmVPCpWRoYWOtA4NKYZFqv4kIUQQybPclr2vv7Q0pbKdqTvkyK46DRqozgLREj3 7 | iNRIU2xa5nMGrL8M+AjOKTjMJP5fbJXFr1ZezrPRdNg3EWaMAk+9zMfsluYsx6zZ 8 | 60rEHdCStYj4Gisc/FIGDf/CMGiuENrdO6gw5wsZU0MaqbgjUAbCMTngtrAciQiA 9 | Q4bFcu33NOAhcnmiMpBFE3QMHBm1e0aAIR3sSqlJoIdxeD64b6D2+HtHQCvm8dsm 10 | +nDDJVWimbieXQrki0GH/rHZzeDXTkMgMKvjRvpSb/Ksfio9IlPrNu88EMLmN9CC 11 | cxwEPVxJheISyguZwMxlvz4sSsuxz3Msfujc5IJ4t6K4N2LtLqu4LB4WrTMZVGuG 12 | 56rHO2AbrEWKDRywwsm9x6gXppM/IMMKOddUlk02nKxd+oqeQQx2ZwbC2VeydAok 13 | eXbhq8ccus2zZtLE/l6zhM0BCd6eJRp1rrTcx27bSf+KeE/GoYCabi3+ZI4xICW2 14 | pDPSbM0Hg0Ma09FRHYs/Fevmy3VfAZ8VR0zCVvCOku8avfIN5fZBRDaNmu1Fa2CP 15 | WPTkpH3WBlsKyWO73aHVk1h94XI63hPY/5PIQJsgSCg7479nG57nFxjJQCOJzcN1 16 | SjkiXWFmOhLtBrAFc5YAypE+NDDWHKs5EsvUZZ4Xo4uSKtdJDISOZIHqpmp8Ntdp 17 | z2ospT9CGwiVjjefmS6kgwRs+Ky6k6U89hOrdF08LSRM13OCeKQPUu6FuWmqlcBe 18 | U0Pzh4Yxg+VVslbudIfLnlembY6lS5/jp1LFo3tH3wAFG64vdPlpaU16Xqc+rRCw 19 | Ntdjt2v4Ju+S5WImLZO7DOMN93lyg6CYt/yLflMoZdKE7zIAon24U/RjrKn/z0KF 20 | G8I022tll7ahrN7c28M9olzSqEgJMg8+tX1Bn6nxJZuLoTCd2AP47Dzw4rVpYFqh 21 | HAQisNFAzlUntW9TUdMAVHEQY58/dAwZxEWXUMvgizn/3T6eRN4H1zw8BK+ae1ni 22 | nGjlSfhvQJ7CwEhcSwCfYFSN72vkGv42g13CN1bik2aeajqbvS8H4plyHkTzQF44 23 | rqoLdqQTapm0JUU+h1OBApYI/ryM/VQiZr+6onXhlFzc+dl8bmDMpdswM4tWnU+T 24 | BGAyet5DjKanLoz8rWvrm2F+feLbZeepfMK8pI+5mcfZk6B43xjcDYMZcXlt6Crl 25 | 3DyIsVzFGVN7nhtUk1VoQgCOO2aLpa9CjGM6Gb6ugsVqHF7z91XLLHLEc+/qVPWu 26 | UJBXvvnj7H3HBAeOc5Uz1jUdNS+kPPVlQiyQBP++ggpThRL9whsgakSemUy7xtW2 27 | nzYJJhNxkFLEX1fMYucS74+ArI7MFnbuBLbeG/lfjkCl6ErOYCnaIsjK4+Z74Ros 28 | odYQxGYMobvHWzxT12WYUGpbpDslTFqIuULRsRBxeGzF4Ud9e0YI2vnjB4RA5daH 29 | G2KzjFNOtKdl1ng/1UoKIQ== 30 | -----END ENCRYPTED PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /certs/test.2.password: -------------------------------------------------------------------------------- 1 | vesoft -------------------------------------------------------------------------------- /certs/test.ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | Proc-Type: 4,ENCRYPTED 3 | DEK-Info: DES-EDE3-CBC,6D12ED8559E80FA3 4 | 5 | tv9epnwlt4dP6Q5ee0dACOyFA5BTwYTdoMykQRJrKGwfaNeXUXn+sQ/U/oFHp1Wx 6 | O8VZE+z2aHpiFSTw+Eh6MPt86X5yVG3tpeVO6dErvr8Kd+NpuI8zn7rNoOFRh8wD 7 | 33EFcQMLQPneDl10O18hooIoi0qwp1pd63hYZPwEhB3eOrM5Mnv9OVJs65bzYfyf 8 | Wku33YWYxeqlDvMCsou8PZnv/M2wYsr7+QoTcNmGKP45igMthMDBzwgF+q0p9ZZU 9 | N11c6ojAs01kfuqFf3vKfHNYe6zsBiNhnUuEy8enXSxD5E7tR/OI8aEzPLdk7fmN 10 | /UsMK2LE0Yd5iS3O1x/1ZjSBxJ+M/UzzCO692GTAiD6Hc13iJOavq/vt1mEPjfCD 11 | neF38Bhb5DfFi+UAHrz6EHMreamGCzP82us2maIs7mSTq7nXDZfbBc7mBDLAUUnT 12 | J6tlrTyc+DQXzkJa6jmbxJhcsWm6XvjIBEzSXVHxEDPLnZICQk3VXODjCXTD75Rg 13 | 0WaS78Ven7DW8wn07q3VzWAFDKaet3VI+TVTv7EfIavlfiA6LSshaENdFLeHahNE 14 | s/V/j5K3Pg6+WQcZRgOsfqIwUCSQxY13R6TTdaaCkLay5BggF5iiAO3pkqsJiadf 15 | w843Ak4USBptymJxoZgJyFtQHpQyNiFfsAbs9BaYbg2evvE7/VQhLk0gQ7HgQMeJ 16 | wgxEQqZQKDCCSugSzY1YEGXKnrZYCKyipzyyH936mE15zNwhYp/Pi2020+gmtP3h 17 | CDfcPs1yeLI2/1JuimafbuKsv9xchWa6ASU8p8Q7wTLtUj9ylLKyA4A/75pK0DXG 18 | Hv/q0O+UfhAMD438SoPBle7RSvIsDU1VjUqstlNybBglBZxGIME7/18+Ms7U32wh 19 | 4xFkZwxT2nqFgyk37tXMdMz9UBh12/AXR9NU4XY37C3Ao2TDT7/0DvU6KdJhsDpv 20 | rGcaC2zzhko+0CPrLlk52KbqP003JXiWvOSI+FylyPPDB/YGitmndJUuQblf3u/E 21 | l+tGi9MeSBQeWKV6D3AVnO05AZjfTUzSK0vw4DgNh5YPNJvLy31B7kDAS88vyGI1 22 | t6MBwjW4/tz/nS/p1Go3mSzBhPkIsCrZE+ar7lH8p8JqkLl4fXIMaVKIfyfJdzyS 23 | lkh3K7bOGDPegxxxaWdb+EnC7k+1R3EOU7uJFW61HyrGI3q6Y7kOl5aYSJ5Ge1Uv 24 | PycFWHWVTHq/R7HRE6HIJzGe/PnLIbStXLDFeivjfcYq1YaSaF8Vl+xg+0u3ULOl 25 | P6IuPTph6dlcgttRZVl3ETcF0T+2wfbUwgjf0ZiguCJfR2jLGhPl1KBg0Kd9cTSY 26 | zI3YMMd2G8hApt/QFlm4Ry8CqaJUmDcjDNIJT3M+RldUgfz37NsX05cA5e9+I1AL 27 | 2406F/v5U9gWsYx7HuwJtQrDzYYDbl1GD4H+qHFJE5JYhPP4AyWYxJ1NR5dqyvrt 28 | +3r5+xlwZrS76c10RsBWL7th8ZEzRxOZxbtLwbf4bG/tIGfQP2sTnWwA+qym6b2S 29 | sRduqOTP+xwnhOq/ZKn8lfsDfhT8CPnKHBsd09kM9y/UWuxFe0upLydRLE/Wsb9s 30 | -----END RSA PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /certs/test.ca.password: -------------------------------------------------------------------------------- 1 | vesoft -------------------------------------------------------------------------------- /certs/test.ca.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEGzCCAwOgAwIBAgIUDcmZFpL4PcdCXfLRBK8bR2vb39cwDQYJKoZIhvcNAQEL 3 | BQAwgZwxCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwI 4 | SGFuZ3pob3UxFDASBgNVBAoMC1Zlc29mdCBJbmMuMRAwDgYDVQQLDAdzZWN0aW9u 5 | MRYwFAYDVQQDDA1zaHlsb2NrIGh1YW5nMScwJQYJKoZIhvcNAQkBFhhzaHlsb2Nr 6 | Lmh1YW5nQHZlc29mdC5jb20wHhcNMjEwODE5MDkyNDQ3WhcNMjUwODE4MDkyNDQ3 7 | WjCBnDELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFpoZWppYW5nMREwDwYDVQQHDAhI 8 | YW5nemhvdTEUMBIGA1UECgwLVmVzb2Z0IEluYy4xEDAOBgNVBAsMB3NlY3Rpb24x 9 | FjAUBgNVBAMMDXNoeWxvY2sgaHVhbmcxJzAlBgkqhkiG9w0BCQEWGHNoeWxvY2su 10 | aHVhbmdAdmVzb2Z0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 11 | AMEAgpamCQHl+8JnUHI6/VmJHjDLYJLTliN/CwpFrhMqIVjJ8wG57WYLpXpn91Lz 12 | eHu52LkVzcikybIJ2a+LOTvnhNFdbmTbqDtrb+s6wM/sO+nF6tU2Av4e5zhyKoeR 13 | LL+rHMk3nymohbdN4djySFmOOU5A1O/4b0bZz4Ylu995kUawdiaEo13BzxxOC7Ik 14 | Gge5RyDcm0uLXZqTAPy5Sjv/zpOyj0AqL1CJUH7XBN9OMRhVU0ZX9nHWl1vgLRld 15 | J6XT17Y9QbbHhCNEdAmFE5kEFgCvZc+MungUYABlkvoj86TLmC/FMV6fWdxQssyd 16 | hS+ssfJFLaTDaEFz5a/Tr48CAwEAAaNTMFEwHQYDVR0OBBYEFK0GVrQx+wX1GCHy 17 | e+6fl4X+prmYMB8GA1UdIwQYMBaAFK0GVrQx+wX1GCHye+6fl4X+prmYMA8GA1Ud 18 | EwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAHqP8P+ZUHmngviHLSSN1ln5 19 | Mx4BCkVeFRUaFx0yFXytV/iLXcG2HpFg3A9rAFoYgCDwi1xpsERnBZ/ShTv/eFOc 20 | IxBY5yggx3/lGi8tAgvUdarhd7mQO67UJ0V4YU3hAkbnZ8grHHXj+4hfgUpY4ok6 21 | yaed6HXwknBb9W8N1jZI8ginhkhjaeRCHdMiF+fBvNCtmeR1bCml1Uz7ailrpcaT 22 | Mf84+5VYuFEnaRZYWFNsWNCOBlJ/6/b3V10vMXzMmYHqz3xgAq0M3fVTFTzopnAX 23 | DLSzorL/dYVdqEDCQi5XI9YAlgWN4VeGzJI+glkLOCNzHxRNP6Qev+YI+7Uxz6I= 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /certs/test.ca.srl: -------------------------------------------------------------------------------- 1 | 4AF2EBB941EA7EE8358ECC7E51C2F1A38EE18873 2 | -------------------------------------------------------------------------------- /certs/test.derive.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDvjCCAqYCFEry67lB6n7oNY7MflHC8aOO4YhzMA0GCSqGSIb3DQEBCwUAMIGc 3 | MQswCQYDVQQGEwJDTjERMA8GA1UECAwIWmhlamlhbmcxETAPBgNVBAcMCEhhbmd6 4 | aG91MRQwEgYDVQQKDAtWZXNvZnQgSW5jLjEQMA4GA1UECwwHc2VjdGlvbjEWMBQG 5 | A1UEAwwNc2h5bG9jayBodWFuZzEnMCUGCSqGSIb3DQEJARYYc2h5bG9jay5odWFu 6 | Z0B2ZXNvZnQuY29tMB4XDTIxMDgyNDEwNTExMloXDTIzMTEyNzEwNTExMlowgZkx 7 | CzAJBgNVBAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzERMA8GA1UEBwwISGFuZ3po 8 | b3UxFDASBgNVBAoMC1Zlc29mdCBJbmMuMRAwDgYDVQQLDAdzZWN0aW9uMRMwEQYD 9 | VQQDDApTaHlsb2NrIEhnMScwJQYJKoZIhvcNAQkBFhhzaHlsb2NrLmh1YW5nQHZl 10 | c29mdC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDHk1PQtaCG 11 | S31nvxKuT6pzVQuOsA2hEIDzBZuoBK3blezBB16fjUWG2wHG/r9Oss5YzOly4viL 12 | 1oFLsNdYg27EFH7pcGfdSUmZa6LHILegJTmLa1aB4lRG9EsvPIxNuo637CW2z6EW 13 | ElVKXn2N1G1vW3fpKGxJ+d1ovaFfBliO0sK+myW+vYdKrNg70WqKKCoCIlIjEWw3 14 | vQdrmvhuhIBbG1bXkXbJwIepBdb4wGSx8qsgs93I6/je/K/iJaPJIqdH8loo6fSo 15 | DBUiNA87ZsQdtbBeuk7QuF71SxD5+E8wCMtFMwRGmL0vYMPwkaurKxwEs49e8eTz 16 | RvIrNtyYgVo7AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGBpm5OLXn02kWr1ENU5 17 | FOOVryD41SCmPy8hLwQ2MCXd446UfTXc5TTlllksaePn373ZANLUe78vUCoVPjOh 18 | dU5GxyOKtubXovI+yuvMS11u00KtgiAd5qa+IhX3c/P60bh4+fdKZ9ViyLsG+IpQ 19 | +XDYT2uekLyjXXJU6h1raW7M1VY9FcDC63moXz0WgWJ/9tJgB0ZQkVcL+2UpveoZ 20 | Whf9P0xAzCmNSrR7CMhdeRN2vBQQaHXk/64wkHncdkz/NglVl00rh4MtBKZ6Cqze 21 | uZvgrxOJNzB4aXBMHO7sWzw1VSfS79CZm4H39hBWGiVEkr3yZYQbboDRY6F5dQyc 22 | BZc= 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /certs/test.derive.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIDEjCCAfoCAQAwgZkxCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhaaGVqaWFuZzER 3 | MA8GA1UEBwwISGFuZ3pob3UxFDASBgNVBAoMC1Zlc29mdCBJbmMuMRAwDgYDVQQL 4 | DAdzZWN0aW9uMRMwEQYDVQQDDApTaHlsb2NrIEhnMScwJQYJKoZIhvcNAQkBFhhz 5 | aHlsb2NrLmh1YW5nQHZlc29mdC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw 6 | ggEKAoIBAQDHk1PQtaCGS31nvxKuT6pzVQuOsA2hEIDzBZuoBK3blezBB16fjUWG 7 | 2wHG/r9Oss5YzOly4viL1oFLsNdYg27EFH7pcGfdSUmZa6LHILegJTmLa1aB4lRG 8 | 9EsvPIxNuo637CW2z6EWElVKXn2N1G1vW3fpKGxJ+d1ovaFfBliO0sK+myW+vYdK 9 | rNg70WqKKCoCIlIjEWw3vQdrmvhuhIBbG1bXkXbJwIepBdb4wGSx8qsgs93I6/je 10 | /K/iJaPJIqdH8loo6fSoDBUiNA87ZsQdtbBeuk7QuF71SxD5+E8wCMtFMwRGmL0v 11 | YMPwkaurKxwEs49e8eTzRvIrNtyYgVo7AgMBAAGgMzAVBgkqhkiG9w0BCQcxCAwG 12 | dmVzb2Z0MBoGCSqGSIb3DQEJAjENDAtWZXNvZnQgSW5jLjANBgkqhkiG9w0BAQsF 13 | AAOCAQEAjmyCyxziJMR8NILRAwmfYcBB90CbTFMMEyWy402KxoXcyVZBGO2eukIq 14 | gaF2ywuh6yuTPtGsdVMVTWDQ4RLYpoQoR5Blu+M8Or8rhZSfMYXi79Ne3abSF28E 15 | eWjBmh2Ys0GtaThlufJBWE+vWPH2iEGrSRTg1fvBLBzAW6nXU2svoTrKfDcEoY5z 16 | xB0CKhBoewoIZ2FPBmBAnIWHfXR/vQ76QIoNdfQ4nT8iXuLRoNjRlvVU4AUDwKtu 17 | keRDrnmJ7A5eqTlleCMzra2MAp9Na9gojXlGQP9q9V8nFtSvbjYAoH0ezWpdWj4+ 18 | Rtu9EK4JkDymmmZcneFapExZrRLt0A== 19 | -----END CERTIFICATE REQUEST----- 20 | -------------------------------------------------------------------------------- /certs/test.derive.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAx5NT0LWghkt9Z78Srk+qc1ULjrANoRCA8wWbqASt25XswQde 3 | n41FhtsBxv6/TrLOWMzpcuL4i9aBS7DXWINuxBR+6XBn3UlJmWuixyC3oCU5i2tW 4 | geJURvRLLzyMTbqOt+wlts+hFhJVSl59jdRtb1t36ShsSfndaL2hXwZYjtLCvpsl 5 | vr2HSqzYO9FqiigqAiJSIxFsN70Ha5r4boSAWxtW15F2ycCHqQXW+MBksfKrILPd 6 | yOv43vyv4iWjySKnR/JaKOn0qAwVIjQPO2bEHbWwXrpO0Lhe9UsQ+fhPMAjLRTME 7 | Rpi9L2DD8JGrqyscBLOPXvHk80byKzbcmIFaOwIDAQABAoIBAEZ50URHjzs9VziW 8 | sdsaSN/XbXBi3T0+Xbr0BQatOFPtuqBjoNeJBL9dgWArP5Vj8RhMrDekzQ5cnmYD 9 | OdiI+UmGz1ZSGmt7YOErsFzPQejsnEiOjArryMURqacxo34jXhi27I6E/aaUrMfJ 10 | XF8EX+zOCSct3ie1c6l0JZMv43/zbzP2vMFEdfnVfZA2Kxo5l3I4rjuxHUEWHzrb 11 | EgM4a2+y7LQrut75zP9zWEZAqim/VEIEj24Gqj+Vocb6cHlc31KzKaEz7Ra5ha2J 12 | kN2CQRKCzoMupVL5E6dWMiDVjUyUXdUgjSCIW2H+E1ONgvxA78jJx7+Dzj+/bWxH 13 | h/vr3dkCgYEA9Aev7PGoGF0eapZY3crehvtCn1v4YLheh0dk4EpbpbEx0rQaG3h7 14 | YYCf7euxMvoTsKPETHAUG/s/RZV1DNOjxs8GKgEIVaRYEf1VZeDXudtnyKBwCMAL 15 | 5CKHRBvfmNG9n+PpQQlrIAZGej7HU+/IzEVsrD2A5DeH9IVpMNvrX10CgYEA0V1r 16 | aydbBP+Ma/fiG5UDa8l4GdLzvAoW2cY6ZhQX4NiLTK91MwA/QOQcVMvJAN2KpPHC 17 | kGDRT7IhMs66cMxl0ImIJ2QSnv8HRNmBBSdUtJx1S6nV2u0VfgP61oNT/YbLR/Jk 18 | CAIl1qe7Q8IsrMbPxCbt8g+D8Wr9C3pdYYqFvncCgYEAicGdKmDwx3Apr3nYCLxx 19 | CjnkzhkZCWCK3EsNQyA2xD5XJd7NrhxBajU2ExUuHtzVKK4KLixG7dTTTvCj9u2y 20 | UpSjoiqbDd2MaftcrfpTTXPyDmujUw02qT5kpaomexpLtWrvTeuHMbjZKEEwPM3r 21 | yISYaFL/49UFRp/ZVd+P63ECgYAX1B0ctf77A6bUxwK6Buy7wNNlhQful+tf39rX 22 | sWPCWIMKOFILevS4Cv5afFMlQRG9kjKFwi8wdeKnaLX5jpnr8StI6G/iHr6SDHtN 23 | vds7Ly9+bBcF8sPmcseC0LGngkbyqljOPIhX9QEwRhJVm88b0R511WQ7/uRMASJN 24 | rrloIwKBgCxYlu1xvvEuQNoIux/yKAEJ1h4Ta2zc5upjw0uDKMi0UNIbNhgdFOvj 25 | LuVbxTRU8WktrLNk3T0rsopKsTbEZVg6Yuv8ZLkEiNYTzhUbn2Y5yM3bnoVwyOns 26 | pTtqmBtvDZxaRCYdIQG3b09IvrewDk26AOtNHdeKw883G2muP/vA 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /cmake/ClangTidy.cmake: -------------------------------------------------------------------------------- 1 | if (ENABLE_CLANG_TIDY) 2 | if (${CMAKE_VERSION} VERSION_LESS "3.6.0") 3 | message(FATAL_ERROR "clang-tidy requires CMake version at least 3.6.") 4 | endif() 5 | 6 | find_program (CLANG_TIDY_PATH NAMES "clang-tidy") 7 | if (CLANG_TIDY_PATH) 8 | message(STATUS "Using clang-tidy: ${CLANG_TIDY_PATH}.") 9 | set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PATH} --config=) 10 | else () 11 | message(STATUS "clang-tidy is not found.") 12 | endif () 13 | endif () 14 | -------------------------------------------------------------------------------- /cmake/FetchModule.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | # 5 | 6 | find_package(Git) 7 | macro(nebula_fetch_module) 8 | cmake_parse_arguments( 9 | module # 10 | "" # 11 | "URL;TAG;UPDATE;NAME;CHECKOUT" # 12 | "" # 13 | ${ARGN} 14 | ) 15 | set(module_dir ${CMAKE_SOURCE_DIR}/modules/${module_NAME}) 16 | if(NOT EXISTS ${module_dir}/.git) 17 | message(STATUS "Cloning from ${module_URL}:${module_TAG}") 18 | execute_process( 19 | COMMAND 20 | ${GIT_EXECUTABLE} clone 21 | --single-branch 22 | --branch ${module_TAG} 23 | ${module_URL} ${module_dir} 24 | RESULT_VARIABLE fetch_status 25 | ERROR_VARIABLE ERROR_MESSAGE 26 | ) 27 | if(NOT ${fetch_status} EQUAL 0) 28 | message(FATAL_ERROR "Cloning failed") 29 | endif() 30 | else() 31 | if (${module_CHECKOUT}) 32 | execute_process( 33 | COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD 34 | WORKING_DIRECTORY ${module_dir} 35 | OUTPUT_VARIABLE branch_name 36 | ) 37 | string(REPLACE "\n" "" branch_name "${branch_name}") 38 | if(NOT ${branch_name} STREQUAL ${module_TAG}) 39 | message(STATUS "The branch of ${module_NAME} is ${branch_name}, need to change to ${module_TAG}") 40 | execute_process( 41 | COMMAND ${GIT_EXECUTABLE} remote set-branches origin --add ${module_TAG} 42 | WORKING_DIRECTORY ${module_dir} 43 | ) 44 | execute_process( 45 | COMMAND ${GIT_EXECUTABLE} config remote.origin.fetch 46 | WORKING_DIRECTORY ${module_dir} 47 | ) 48 | execute_process( 49 | COMMAND ${GIT_EXECUTABLE} fetch 50 | WORKING_DIRECTORY ${module_dir} 51 | ) 52 | execute_process( 53 | COMMAND ${GIT_EXECUTABLE} checkout ${module_TAG} 54 | WORKING_DIRECTORY ${module_dir} 55 | RESULT_VARIABLE checkout_status 56 | ERROR_VARIABLE error_msg 57 | ) 58 | if(NOT ${checkout_status} EQUAL 0) 59 | message(FATAL_ERROR "Checkout to branch ${module_TAG} failed: ${error_msg}, error_code: ${checkout_status}") 60 | endif() 61 | endif() 62 | endif() 63 | if(${module_UPDATE}) 64 | message(STATUS "Updating from ${module_URL}") 65 | execute_process( 66 | COMMAND ${GIT_EXECUTABLE} pull 67 | WORKING_DIRECTORY ${module_dir} 68 | RESULT_VARIABLE fetch_status 69 | ) 70 | if(NOT ${fetch_status} EQUAL 0) 71 | message(FATAL_ERROR "Updating failed") 72 | endif() 73 | endif() 74 | endif() 75 | endmacro() 76 | -------------------------------------------------------------------------------- /cmake/FindBreakpad.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Breakpad includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Breakpad) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Breakpad_FOUND System has breakpad, include and lib dirs found 13 | # Breakpad_INCLUDE_DIR The breakpad includes directories. 14 | # Breakpad_LIBRARY The breakpad library. 15 | 16 | find_path(Breakpad_INCLUDE_DIR NAMES breakpad) 17 | find_library(Breakpad_LIBRARY NAMES libbreakpad_client.a) 18 | 19 | message(STATUS "BREAKPAD: ${Breakpad_INCLUDE_DIR}") 20 | 21 | if(Breakpad_INCLUDE_DIR AND Breakpad_LIBRARY) 22 | set(Breakpad_FOUND TRUE) 23 | mark_as_advanced( 24 | Breakpad_INCLUDE_DIR 25 | Breakpad_LIBRARY 26 | ) 27 | endif() 28 | 29 | if(NOT Breakpad_FOUND) 30 | message(FATAL_ERROR "Breakpad doesn't exist") 31 | endif() 32 | 33 | 34 | -------------------------------------------------------------------------------- /cmake/FindBzip2.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Bzip2 includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Bzip2) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Bzip2_FOUND System has bzip2, include and lib dirs found. 13 | # Bzip2_INCLUDE_DIR The bzip2 includes directories. 14 | # Bzip2_LIBRARY The bzip2 library. 15 | # Bzip2_BIN The bzip2 binary. 16 | 17 | find_path(Bzip2_INCLUDE_DIR NAMES bzlib.h) 18 | find_library(Bzip2_LIBRARY NAMES libbz2.a) 19 | find_program(Bzip2_BIN NAMES bzip2) 20 | 21 | if(Bzip2_INCLUDE_DIR AND Bzip2_LIBRARY AND Bzip2_BIN) 22 | set(Bzip2_FOUND TRUE) 23 | mark_as_advanced( 24 | Bzip2_INCLUDE_DIR 25 | Bzip2_LIBRARY 26 | Bzip2_BIN 27 | ) 28 | endif() 29 | 30 | if(NOT Bzip2_FOUND) 31 | message(FATAL_ERROR "Bzip2 doesn't exist") 32 | endif() 33 | 34 | 35 | -------------------------------------------------------------------------------- /cmake/FindDoubleConversion.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libdouble-conversion includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(DoubleConversion) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # DoubleConversion_FOUND System has double-conversion, include and lib dirs found 13 | # DoubleConversion_INCLUDE_DIR The double-conversion includes directories. 14 | # DoubleConversion_LIBRARY The double-conversion library. 15 | 16 | find_path(DoubleConversion_INCLUDE_DIR NAMES double-conversion/double-conversion.h) 17 | find_library(DoubleConversion_LIBRARY NAMES libdouble-conversion.a) 18 | 19 | if(DoubleConversion_INCLUDE_DIR AND DoubleConversion_LIBRARY) 20 | set(DoubleConversion_FOUND TRUE) 21 | mark_as_advanced( 22 | DoubleConversion_INCLUDE_DIR 23 | DoubleConversion_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT DoubleConversion_FOUND) 28 | message(FATAL_ERROR "Double-conversion doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindFatal.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Fatal includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Fatal) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Fatal_FOUND System has readline, include and lib dirs found 13 | # Fatal_INCLUDE_DIR The readline includes directories. 14 | 15 | find_path(Fatal_INCLUDE_DIR NAMES fatal) 16 | 17 | if(Fatal_INCLUDE_DIR) 18 | set(Fatal_FOUND TRUE) 19 | mark_as_advanced( 20 | Fatal_INCLUDE_DIR 21 | ) 22 | endif() 23 | 24 | if(NOT Fatal_FOUND) 25 | message(FATAL_ERROR "Fatal doesn't exist") 26 | endif() 27 | 28 | -------------------------------------------------------------------------------- /cmake/FindFbthrift.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Fbthrift includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Fbthrift) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Fbthrift_FOUND System has fbthrift, thrift1 and include and lib dirs found. 13 | # Fbthrift_INCLUDE_DIR The fbthrift includes directories. 14 | # Fbthrift_LIBRARY The fbthrift library. 15 | # Fbthrift_BIN The fbthrift binary. 16 | 17 | find_path(Fbthrift_INCLUDE_DIR NAMES thrift) 18 | find_library(Fbthrift_LIBRARY NAMES libthriftcpp2.a) 19 | find_program(Fbthrift_BIN NAMES thrift1) 20 | 21 | if(Fbthrift_INCLUDE_DIR AND Fbthrift_LIBRARY AND Fbthrift_BIN) 22 | set(Fbthrift_FOUND TRUE) 23 | mark_as_advanced( 24 | Fbthrift_INCLUDE_DIR 25 | Fbthrift_LIBRARY 26 | Fbthrift_BIN 27 | ) 28 | endif() 29 | 30 | if(NOT Fbthrift_FOUND) 31 | message(FATAL_ERROR "Fbthrift doesn't exist") 32 | endif() 33 | 34 | -------------------------------------------------------------------------------- /cmake/FindFizz.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Fizz includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Fizz) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Fizz_FOUND System has fizz, include and lib dirs found 13 | # Fizz_INCLUDE_DIR The fizz includes directories. 14 | # Fizz_LIBRARY The fizz library. 15 | 16 | find_path(Fizz_INCLUDE_DIR NAMES fizz) 17 | find_library(Fizz_LIBRARY NAMES libfizz.a) 18 | 19 | if(Fizz_INCLUDE_DIR AND Fizz_LIBRARY) 20 | set(Fizz_FOUND TRUE) 21 | mark_as_advanced( 22 | Fizz_INCLUDE_DIR 23 | Fizz_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Fizz_FOUND) 28 | message(FATAL_ERROR "Fizz doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindFolly.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Folly includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Folly) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Folly_FOUND System has folly, include and lib dirs found 13 | # Folly_INCLUDE_DIR The folly includes directories. 14 | # Folly_LIBRARY The folly library. 15 | 16 | find_path(Folly_INCLUDE_DIR NAMES folly) 17 | find_library(Folly_LIBRARY NAMES libfolly.a libfollybenchmark.a) 18 | 19 | if(Folly_INCLUDE_DIR AND Folly_LIBRARY) 20 | set(Folly_FOUND TRUE) 21 | mark_as_advanced( 22 | Folly_INCLUDE_DIR 23 | Folly_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Folly_FOUND) 28 | message(FATAL_ERROR "Folly doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindGPERF.cmake: -------------------------------------------------------------------------------- 1 | # FindGPERF 2 | # --------- 3 | # 4 | # Find ``gperf`` executable 5 | # 6 | # The module defines the following variables: 7 | # 8 | # ``GPERF_EXECUTABLE_DIR`` 9 | # path to search the gperf binary 10 | # 11 | # ``GPERF_EXECUTABLE`` 12 | # path to the ``gperf`` program 13 | # 14 | # ``GPERF_BIN_DIR`` 15 | # path to the directory that holds ``gperf`` program 16 | # 17 | # ``GPERF_VERSION`` 18 | # version of ``gperf`` 19 | # 20 | # ``GPERF_FOUND`` 21 | # true if the program was found 22 | # 23 | # The minimum required version of ``gperf`` can be specified using the 24 | # standard CMake syntax, e.g. ``find_package(GPERF 3.0)``. 25 | 26 | find_program(GPERF_EXECUTABLE 27 | NAMES gperf 28 | PATHS ${GPERF_EXECUTABLE_DIR} 29 | DOC "path to the gperf executable") 30 | 31 | if(GPERF_EXECUTABLE) 32 | # Extract the path 33 | STRING(REGEX REPLACE "/gperf$" "" GPERF_BIN_DIR ${GPERF_EXECUTABLE}) 34 | 35 | # the gperf commands should be executed with the C locale, otherwise 36 | # the message (which is parsed) may be translated 37 | set(_gperf_SAVED_LC_ALL "$ENV{LC_ALL}") 38 | set(ENV{LC_ALL} C) 39 | 40 | execute_process(COMMAND ${GPERF_EXECUTABLE} --version 41 | OUTPUT_VARIABLE GPERF_version_output 42 | ERROR_VARIABLE GPERF_version_error 43 | RESULT_VARIABLE GPERF_version_result 44 | OUTPUT_STRIP_TRAILING_WHITESPACE) 45 | 46 | set(ENV{LC_ALL} ${_gperf_SAVED_LC_ALL}) 47 | 48 | if(NOT ${GPERF_version_result} EQUAL 0) 49 | message(SEND_ERROR "Command \"${GPERF_EXECUTABLE} --version\" failed with output:\n${GPERF_version_error}") 50 | else() 51 | if("${GPERF_version_output}" MATCHES "^GNU gperf ([^\n]+)") 52 | set(GPERF_VERSION "${CMAKE_MATCH_1}") 53 | endif() 54 | endif() 55 | 56 | endif() 57 | mark_as_advanced(GPERF_EXECUTABLE GPERF_BIN_DIR) 58 | 59 | include(FindPackageHandleStandardArgs) 60 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GPERF REQUIRED_VARS GPERF_EXECUTABLE 61 | VERSION_VAR GPERF_VERSION) 62 | -------------------------------------------------------------------------------- /cmake/FindGflags.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Gflags includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Gflags) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Gflags_FOUND System has Gflags, include and lib dirs found 13 | # Gflags_INCLUDE_DIR The Gflags includes directories. 14 | # Gflags_LIBRARY The Gflags library. 15 | 16 | find_path(Gflags_INCLUDE_DIR NAMES gflags) 17 | find_library(Gflags_LIBRARY NAMES libgflags.a) 18 | 19 | if(Gflags_INCLUDE_DIR AND Gflags_LIBRARY) 20 | set(Gflags_FOUND TRUE) 21 | mark_as_advanced( 22 | Gflags_INCLUDE_DIR 23 | Gflags_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Gflags_FOUND) 28 | message(FATAL_ERROR "Gflags doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Glog includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Glog) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Glog_FOUND System has Glog, include and lib dirs found 13 | # Glog_INCLUDE_DIR The Glog includes directories. 14 | # Glog_LIBRARY The Glog library. 15 | 16 | find_path(Glog_INCLUDE_DIR NAMES glog) 17 | find_library(Glog_LIBRARY NAMES libglog.a) 18 | 19 | if(Glog_INCLUDE_DIR AND Glog_LIBRARY) 20 | set(Glog_FOUND TRUE) 21 | mark_as_advanced( 22 | Glog_INCLUDE_DIR 23 | Glog_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Glog_FOUND) 28 | message(FATAL_ERROR "Glog doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindGoogletest.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Googletest includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Googletest) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Googletest_FOUND System has Googletest, include and lib dirs found 13 | # Googletest_INCLUDE_DIR The Googletest includes directories. 14 | # Googletest_LIBRARY The Googletest library. 15 | 16 | find_path(Googletest_INCLUDE_DIR NAMES gmock gtest) 17 | find_library(Googletest_LIBRARY NAMES libgmock.a libgmock_main.a libgtest.a libgtest_main.a) 18 | 19 | if(Googletest_INCLUDE_DIR AND Googletest_LIBRARY) 20 | set(Googletest_FOUND TRUE) 21 | mark_as_advanced( 22 | Googletest_INCLUDE_DIR 23 | Googletest_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Googletest_FOUND) 28 | message(FATAL_ERROR "Googletest doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindJemalloc.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Jemalloc includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Jemalloc) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Jemalloc_FOUND System has Jemalloc, include and lib dirs found 13 | # Jemalloc_INCLUDE_DIR The Jemalloc includes directories. 14 | # Jemalloc_LIBRARY The Jemalloc library. 15 | 16 | find_path(Jemalloc_INCLUDE_DIR NAMES jemalloc) 17 | find_library(Jemalloc_LIBRARY NAMES libjemalloc.a) 18 | 19 | if(Jemalloc_INCLUDE_DIR AND Jemalloc_LIBRARY) 20 | set(Jemalloc_FOUND TRUE) 21 | mark_as_advanced( 22 | Jemalloc_INCLUDE_DIR 23 | Jemalloc_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Jemalloc_FOUND) 28 | message(FATAL_ERROR "Jemalloc doesn't exist") 29 | endif() 30 | -------------------------------------------------------------------------------- /cmake/FindLibevent.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Libevent includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Libevent) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Libevent_FOUND System has Libevent, include and lib dirs found 13 | # Libevent_INCLUDE_DIR The Libevent includes directories. 14 | # Libevent_LIBRARY The Libevent library. 15 | 16 | find_path(Libevent_INCLUDE_DIR NAMES event.h) 17 | find_library(Libevent_LIBRARY NAMES libevent.a) 18 | 19 | if(Libevent_INCLUDE_DIR AND Libevent_LIBRARY) 20 | set(Libevent_FOUND TRUE) 21 | mark_as_advanced( 22 | Libevent_INCLUDE_DIR 23 | Libevent_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Libevent_FOUND) 28 | message(FATAL_ERROR "Libevent doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindLibunwind.cmake: -------------------------------------------------------------------------------- 1 | # FindLibunwind 2 | # ------------- 3 | # 4 | # Find Libunwind 5 | # 6 | # Find LibUnwind library 7 | # 8 | # :: 9 | # 10 | # LIBUNWIND_LIBRARY_DIR - Can be provided to advise the search 11 | # 12 | # Libunwind_FOUND - True if libunwind is found. 13 | # LIBUNWIND_LIBRARIES - libunwind libraries to link against. 14 | 15 | find_library(LIBUNWIND_LIBRARY NAMES unwind libunwind.so.8 PATHS ${LIBUNWIND_LIBRARY_DIR}) 16 | 17 | include(FindPackageHandleStandardArgs) 18 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libunwind REQUIRED_VARS LIBUNWIND_LIBRARY) 19 | 20 | if (Libunwind_FOUND) 21 | set(LIBUNWIND_LIBRARIES ${LIBUNWIND_LIBRARY}) 22 | endif () 23 | 24 | mark_as_advanced( LIBUNWIND_LIBRARY ) 25 | -------------------------------------------------------------------------------- /cmake/FindMstch.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Mstch includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Mstch) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Mstch_FOUND System has Mstch, include and lib dirs found 13 | # Mstch_INCLUDE_DIR The Mstch includes directories. 14 | # Mstch_LIBRARY The Mstch library. 15 | 16 | find_path(Mstch_INCLUDE_DIR NAMES mstch) 17 | find_library(Mstch_LIBRARY NAMES libmstch.a) 18 | 19 | if(Mstch_INCLUDE_DIR AND Mstch_LIBRARY) 20 | set(Mstch_FOUND TRUE) 21 | mark_as_advanced( 22 | Mstch_INCLUDE_DIR 23 | Mstch_LIBRARY 24 | ) 25 | message(STATUS "Mstch_INCLUDE_DIR : ${Mstch_INCLUDE_DIR}") 26 | message(STATUS "Mstch_LIBRARY : ${Mstch_LIBRARY}") 27 | endif() 28 | 29 | if(NOT Mstch_FOUND) 30 | message(FATAL_ERROR "Mstch doesn't exist") 31 | endif() 32 | 33 | -------------------------------------------------------------------------------- /cmake/FindNCURSES.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find ncurses include dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(NCURSES) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # NCURSES_ROOT_DIR Set this variable to the root installation of 11 | # ncurses if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # NCURSES_FOUND ncurses is found, include and lib dir 17 | # NCURSES_INCLUDE_DIR The ncurses include directory 18 | # NCURSES_LIBRARY The ncurses library 19 | 20 | find_path( 21 | NCURSES_ROOT_DIR 22 | NAMES include/ncurses/curses.h 23 | ) 24 | 25 | find_path( 26 | NCURSES_INCLUDE_DIR 27 | NAMES ncurses.h curses.h ncurses/curses.h 28 | HINTS ${NCURSES_ROOT_DIR}/include 29 | ) 30 | 31 | find_library( 32 | NCURSES_LIBRARY 33 | NAMES ncurses 34 | HINTS ${NCURSES_ROOT_DIR}/lib 35 | ) 36 | 37 | if(NCURSES_INCLUDE_DIR AND NCURSES_LIBRARY_DIR) 38 | set(NCURSES_FOUND TRUE) 39 | else() 40 | FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses) 41 | include(FindPackageHandleStandardArgs) 42 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(ncurses DEFAULT_MSG NCURSES_INCLUDE_DIR NCURSES_LIBRARY) 43 | endif() 44 | 45 | mark_as_advanced( 46 | NCURSES_ROOT_DIR 47 | NCURSES_INCLUDE_DIR 48 | NCURSES_LIBRARY 49 | ) 50 | -------------------------------------------------------------------------------- /cmake/FindProxygen.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Proxygen includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Proxygen) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Proxygen_FOUND System has Proxygen, include and lib dirs found 13 | # Proxygen_INCLUDE_DIR The Proxygen includes directories. 14 | # Proxygen_LIBRARY The Proxygen library. 15 | 16 | find_path(Proxygen_INCLUDE_DIR NAMES proxygen) 17 | find_library(Proxygen_LIBRARY NAMES libproxygen.a) 18 | 19 | if(Proxygen_INCLUDE_DIR AND Proxygen_LIBRARY) 20 | set(Proxygen_FOUND TRUE) 21 | mark_as_advanced( 22 | Proxygen_INCLUDE_DIR 23 | Proxygen_LIBRARY 24 | ) 25 | endif(Proxygen_INCLUDE_DIR AND Proxygen_LIBRARY) 26 | 27 | if(NOT Proxygen_FOUND) 28 | message(FATAL_ERROR "Proxygen doesn't exist") 29 | endif() 30 | 31 | 32 | -------------------------------------------------------------------------------- /cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find readline includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Readline) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Readline_ROOT_DIR Set this variable to the root installation of 11 | # readline if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # READLINE_FOUND System has readline, include and lib dirs found 17 | # Readline_INCLUDE_DIR The readline includes directories. 18 | # Readline_LIBRARY The readline library. 19 | 20 | find_path(Readline_ROOT_DIR 21 | NAMES include/readline/readline.h 22 | ) 23 | 24 | find_path(Readline_INCLUDE_DIR 25 | NAMES readline/readline.h 26 | HINTS ${Readline_ROOT_DIR}/include 27 | ) 28 | 29 | find_library(Readline_LIBRARY 30 | NAMES readline 31 | HINTS ${Readline_ROOT_DIR}/lib 32 | ) 33 | 34 | if(Readline_INCLUDE_DIR AND Readline_LIBRARY) 35 | set(READLINE_FOUND TRUE) 36 | else(Readline_INCLUDE_DIR AND Readline_LIBRARY) 37 | FIND_LIBRARY(Readline_LIBRARY NAMES readline) 38 | include(FindPackageHandleStandardArgs) 39 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY ) 40 | MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY) 41 | endif(Readline_INCLUDE_DIR AND Readline_LIBRARY) 42 | 43 | mark_as_advanced( 44 | Readline_ROOT_DIR 45 | Readline_INCLUDE_DIR 46 | Readline_LIBRARY 47 | ) 48 | -------------------------------------------------------------------------------- /cmake/FindRocksdb.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Rocksdb includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Rocksdb) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Rocksdb_FOUND System has Rocksdb, include and lib dirs found 13 | # Rocksdb_INCLUDE_DIR The Rocksdb includes directories. 14 | # Rocksdb_LIBRARY The Rocksdb library. 15 | 16 | find_path(Rocksdb_INCLUDE_DIR NAMES rocksdb) 17 | find_library(Rocksdb_LIBRARY NAMES librocksdb.a) 18 | 19 | if(Rocksdb_INCLUDE_DIR AND Rocksdb_LIBRARY) 20 | set(Rocksdb_FOUND TRUE) 21 | mark_as_advanced( 22 | Rocksdb_INCLUDE_DIR 23 | Rocksdb_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Rocksdb_FOUND) 28 | message(FATAL_ERROR "Rocksdb doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindSnappy.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Snappy includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Snappy) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Snappy_FOUND System has Snappy, include and lib dirs found 13 | # Snappy_INCLUDE_DIR The Snappy includes directories. 14 | # Snappy_LIBRARY The Snappy library. 15 | 16 | find_path(Snappy_INCLUDE_DIR NAMES snappy.h) 17 | find_library(Snappy_LIBRARY NAMES libsnappy.a) 18 | 19 | if(Snappy_INCLUDE_DIR AND Snappy_LIBRARY) 20 | set(Snappy_FOUND TRUE) 21 | mark_as_advanced( 22 | Snappy_INCLUDE_DIR 23 | Snappy_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Snappy_FOUND) 28 | message(FATAL_ERROR "Snappy doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindSodium.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Sodium includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Sodium) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Sodium_FOUND System has Sodium, include and lib dirs found 13 | # Sodium_INCLUDE_DIR The Sodium includes directories. 14 | # Sodium_LIBRARY The Sodium library. 15 | 16 | find_path(Sodium_INCLUDE_DIR NAMES sodium) 17 | find_library(Sodium_LIBRARY NAMES libsodium.a) 18 | 19 | if(Sodium_INCLUDE_DIR AND Sodium_LIBRARY) 20 | set(Sodium_FOUND TRUE) 21 | mark_as_advanced( 22 | Sodium_INCLUDE_DIR 23 | Sodium_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Sodium_FOUND) 28 | message(FATAL_ERROR "Sodium doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindWangle.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Wangle includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Wangle) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Wangle_FOUND System has Wangle, include and lib dirs found 13 | # Wangle_INCLUDE_DIR The Wangle includes directories. 14 | # Wangle_LIBRARY The Wangle library. 15 | 16 | find_path(Wangle_INCLUDE_DIR NAMES wangle) 17 | find_library(Wangle_LIBRARY NAMES libwangle.a) 18 | 19 | if(Wangle_INCLUDE_DIR AND Wangle_LIBRARY) 20 | set(Wangle_FOUND TRUE) 21 | mark_as_advanced( 22 | Wangle_INCLUDE_DIR 23 | Wangle_LIBRARY 24 | ) 25 | endif() 26 | 27 | if(NOT Wangle_FOUND) 28 | message(FATAL_ERROR "Wangle doesn't exist") 29 | endif() 30 | 31 | -------------------------------------------------------------------------------- /cmake/FindZstd.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Zstd includes dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Zstd) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Variables defined by this module: 11 | # 12 | # Zstd_FOUND System has Zstd, include and lib dirs found 13 | # Zstd_INCLUDE_DIR The Zstd includes directories. 14 | # Zstd_LIBRARY The Zstd library. 15 | # Zstd_BIN The Zstd binary. 16 | 17 | find_path(Zstd_INCLUDE_DIR NAMES zstd.h) 18 | find_library(Zstd_LIBRARY NAMES libzstd.a) 19 | 20 | if(Zstd_INCLUDE_DIR AND Zstd_LIBRARY) 21 | set(Zstd_FOUND TRUE) 22 | mark_as_advanced( 23 | Zstd_INCLUDE_DIR 24 | Zstd_LIBRARY 25 | ) 26 | endif() 27 | 28 | if(NOT Zstd_FOUND) 29 | message(FATAL_ERROR "Zstd doesn't exist") 30 | endif() 31 | 32 | 33 | -------------------------------------------------------------------------------- /cmake/nebula/ABIConfig.cmake: -------------------------------------------------------------------------------- 1 | # Is abi 11 2 | if (${DISABLE_CXX11_ABI}) 3 | message(STATUS "Set D_GLIBCXX_USE_CXX11_ABI to 0") 4 | add_compile_options(-D_GLIBCXX_USE_CXX11_ABI=0) 5 | else() 6 | message(STATUS "Set D_GLIBCXX_USE_CXX11_ABI to 1") 7 | add_compile_options(-D_GLIBCXX_USE_CXX11_ABI=1) 8 | endif() 9 | -------------------------------------------------------------------------------- /cmake/nebula/CcacheConfig.cmake: -------------------------------------------------------------------------------- 1 | # To detect if ccache is available 2 | find_program(ccache_program_found "ccache") 3 | if (ENABLE_CCACHE AND ccache_program_found) 4 | if (NOT $ENV{CCACHE_DIR} STREQUAL "") 5 | message(STATUS "CCACHE_DIR : $ENV{CCACHE_DIR}") 6 | else() 7 | message(STATUS "CCACHE_DIR : $ENV{HOME}/.ccache") 8 | endif() 9 | set(CMAKE_CXX_COMPILER_LAUNCHER "ccache") 10 | elseif (ENABLE_CCACHE) 11 | message(STATUS "CCACHE : Enabled but not found") 12 | set(CMAKE_CXX_COMPILER_LAUNCHER) 13 | else () 14 | message(STATUS "CCACHE : OFF") 15 | set(CMAKE_CXX_COMPILER_LAUNCHER) 16 | endif() 17 | -------------------------------------------------------------------------------- /cmake/nebula/ConfigNebulaClient.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | # 5 | 6 | macro(config_nebula_client) 7 | message(">>>> Configuring Nebula Client <<<<") 8 | cmake_parse_arguments( 9 | client 10 | "" 11 | "SOURCE_DIR;BUILD_DIR" 12 | "" 13 | ${ARGN} 14 | ) 15 | set(client_source_dir ${client_SOURCE_DIR}) 16 | set(client_build_dir ${client_BUILD_DIR}) 17 | if(NOT EXISTS ${client_build_dir}) 18 | file(MAKE_DIRECTORY ${client_build_dir}) 19 | endif() 20 | 21 | option(DISABLE_CLONE_COMMON "Automatically disable clone common module" OFF) 22 | 23 | execute_process( 24 | COMMAND 25 | ${CMAKE_COMMAND} 26 | -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} 27 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} 28 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 29 | -DNEBULA_THIRDPARTY_ROOT=${NEBULA_THIRDPARTY_ROOT} 30 | -DNEBULA_OTHER_ROOT=${NEBULA_OTHER_ROOT} 31 | -DENABLE_JEMALLOC=${ENABLE_JEMALLOC} 32 | -DENABLE_TESTING=OFF 33 | -DENABLE_CCACHE=${ENABLE_CCACHE} 34 | -DENABLE_ASAN=${ENABLE_ASAN} 35 | -DENABLE_UBSAN=${ENABLE_UBSAN} 36 | -DENABLE_FRAME_POINTER=${ENABLE_FRAME_POINTER} 37 | -DENABLE_PIC=${ENABLE_PIC} 38 | -DENABLE_COMPRESSED_DEBUG_INFO=${ENABLE_COMPRESSED_DEBUG_INFO} 39 | -DNEBULA_USE_LINKER=${NEBULA_USE_LINKER} 40 | -DENABLE_GDB_SCRIPT_SECTION=${ENABLE_GDB_SCRIPT_SECTION} 41 | -DDISABLE_CXX11_ABI=${DISABLE_CXX11_ABI} 42 | -DDISABLE_CLONE_COMMON=ON 43 | ${client_source_dir} 44 | WORKING_DIRECTORY ${client_build_dir} 45 | RESULT_VARIABLE cmake_status 46 | ) 47 | 48 | if(NOT ${cmake_result} EQUAL 0) 49 | message(FATAL_ERROR "Failed to configure nebula-client") 50 | endif() 51 | 52 | add_custom_target( 53 | client_project ALL 54 | COMMAND +${CMAKE_COMMAND} --build ${client_build_dir} 55 | ) 56 | 57 | add_custom_target( 58 | clean-client 59 | COMMAND $(MAKE) clean 60 | WORKING_DIRECTORY ${client_build_dir} 61 | ) 62 | 63 | set(nebula-client_DIR ${client_build_dir}) 64 | find_package(nebula-client REQUIRED) 65 | 66 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_BUILD_DIR}/modules/common) 67 | set(nebula-common_DIR ${client_build_dir}/modules/common) 68 | find_package(nebula-common) 69 | 70 | include_directories(AFTER ${client_source_dir}/include) 71 | include_directories(AFTER ${client_build_dir}/include) 72 | include_directories(AFTER ${client_source_dir}/src) 73 | include_directories(AFTER ${client_build_dir}/src) 74 | 75 | include_directories(AFTER ${client_source_dir}/modules/common/src) 76 | include_directories(AFTER ${client_build_dir}/modules/common/src) 77 | message(">>>> Configuring Nebula Client done <<<<") 78 | endmacro() 79 | -------------------------------------------------------------------------------- /cmake/nebula/GeneralCMakeConfig.cmake: -------------------------------------------------------------------------------- 1 | # By default, all dynamic and static libraries will be placed at ${CMAKE_BINARY_DIR}/lib, 2 | # while all executables at ${CMAKE_BINARY_DIR}/bin. 3 | # But for the sake of cleanliness, all executables ending with `_test' will be placed 4 | # at ${CMAKE_BINARY_DIR}/bin/test, while those ending with `_bm' at ${CMAKE_BINARY_DIR}/bin/bench. 5 | # Please see `nebula_add_executable' for this rule. 6 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 7 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 9 | 10 | if(ENABLE_TESTING) 11 | enable_testing() 12 | endif() 13 | 14 | if(NOT CMAKE_BUILD_TYPE) 15 | set(CMAKE_BUILD_TYPE Debug) 16 | endif() 17 | print_config(CMAKE_BUILD_TYPE) 18 | 19 | if (${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local") 20 | set(CMAKE_INSTALL_PREFIX "/usr/local/nebula") 21 | endif() 22 | print_config(CMAKE_INSTALL_PREFIX) 23 | 24 | 25 | set(CMAKE_SKIP_RPATH TRUE) 26 | -------------------------------------------------------------------------------- /cmake/nebula/GeneralCMakeOptions.cmake: -------------------------------------------------------------------------------- 1 | ############ Nebula defined options immutable during configure stage ############# 2 | message(">>>> Options of ${PROJECT_NAME} <<<<") 3 | option(ENABLE_TESTING "Build unit tests" ON) 4 | option(ENABLE_CCACHE "Use ccache to speed up compiling" ON) 5 | option(ENABLE_WERROR "Regard warnings as errors" ON) 6 | option(ENABLE_JEMALLOC "Use jemalloc as memory allocator" ON) 7 | option(ENABLE_ASAN "Build with AddressSanitizer" OFF) 8 | option(ENABLE_UBSAN "Build with UndefinedBehaviourSanitizer" OFF) 9 | option(ENABLE_TSAN "Build with ThreadSanitizer" OFF) 10 | option(ENABLE_STATIC_ASAN "Statically link against libasan" OFF) 11 | option(ENABLE_STATIC_UBSAN "Statically link against libubsan" OFF) 12 | option(ENABLE_FUZZY_TESTING "Enable Fuzzy tests" OFF) 13 | option(ENABLE_FRAME_POINTER "Build with frame pointer" OFF) 14 | option(ENABLE_STRICT_ALIASING "Build with -fstrict-aliasing" OFF) 15 | option(ENABLE_COVERAGE "Build with coverage report" OFF) 16 | option(ENABLE_PIC "Build with -fPIC" OFF) 17 | option(ENABLE_COMPRESSED_DEBUG_INFO "Compress debug info to reduce binary size" ON) 18 | option(ENABLE_CLANG_TIDY "Enable clang-tidy if present" OFF) 19 | option(ENABLE_GDB_SCRIPT_SECTION "Add .debug_gdb_scripts section" OFF) 20 | option(DISABLE_CXX11_ABI "Whether to disable cxx11 abi" OFF) 21 | 22 | get_cmake_property(variable_list VARIABLES) 23 | foreach(_varname ${variable_list}) 24 | string(REGEX MATCH "^ENABLE" matched ${_varname}) 25 | if(matched) 26 | print_option(${_varname}) 27 | endif() 28 | endforeach() 29 | -------------------------------------------------------------------------------- /cmake/nebula/GeneralCompilerConfig.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD 17) 2 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 3 | set(CMAKE_CXX_EXTENSIONS OFF) 4 | 5 | print_config(CMAKE_CXX_STANDARD) 6 | print_config(CMAKE_CXX_COMPILER) 7 | print_config(CMAKE_CXX_COMPILER_ID) 8 | 9 | if (!CMAKE_CXX_COMPILER) 10 | message(FATAL_ERROR "No C++ compiler found") 11 | endif() 12 | 13 | include(CheckCXXCompilerFlag) 14 | 15 | add_compile_options(-Wall) 16 | add_compile_options(-Wextra) 17 | add_compile_options(-Wpedantic) 18 | add_compile_options(-Wunused-parameter) 19 | add_compile_options(-Wshadow) 20 | add_compile_options(-Wnon-virtual-dtor) 21 | add_compile_options(-Woverloaded-virtual) 22 | add_compile_options(-Wignored-qualifiers) 23 | 24 | # For s2 25 | add_definitions(-DS2_USE_GLOG) 26 | add_definitions(-DS2_USE_GFLAGS) 27 | # For breakpad 28 | add_definitions(-D__STDC_FORMAT_MACROS) 29 | 30 | include_directories(AFTER ${CMAKE_SOURCE_DIR}/src) 31 | include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR}/src) 32 | 33 | 34 | if(ENABLE_WERROR) 35 | add_compile_options(-Werror) 36 | endif() 37 | 38 | if(NOT ENABLE_STRICT_ALIASING) 39 | add_compile_options(-fno-strict-aliasing) 40 | else() 41 | add_compile_options(-fstrict-aliasing) 42 | endif() 43 | 44 | if(ENABLE_FRAME_POINTER) 45 | add_compile_options(-fno-omit-frame-pointer) 46 | else() 47 | add_compile_options(-fomit-frame-pointer) 48 | endif() 49 | 50 | if(ENABLE_PIC) 51 | add_compile_options(-fPIC) 52 | endif() 53 | 54 | if(ENABLE_TESTING AND ENABLE_COVERAGE) 55 | add_compile_options(--coverage) 56 | add_compile_options(-g) 57 | add_compile_options(-O0) 58 | nebula_add_exe_linker_flag(-coverage) 59 | nebula_add_exe_linker_flag(-lgcov) 60 | endif() 61 | 62 | # TODO(doodle) Add option suggest-override for gnu 63 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 64 | # Here we need to specify the path of libstdc++ used by Clang 65 | if(NOT ${NEBULA_CLANG_USE_GCC_TOOLCHAIN} STREQUAL "") 66 | print_config(NEBULA_CLANG_USE_GCC_TOOLCHAIN) 67 | execute_process( 68 | COMMAND ${NEBULA_CLANG_USE_GCC_TOOLCHAIN}/bin/gcc -dumpmachine 69 | OUTPUT_VARIABLE gcc_target_triplet 70 | OUTPUT_STRIP_TRAILING_WHITESPACE 71 | ) 72 | add_compile_options("--gcc-toolchain=${NEBULA_CLANG_USE_GCC_TOOLCHAIN}") 73 | nebula_add_exe_linker_flag(--gcc-toolchain=${NEBULA_CLANG_USE_GCC_TOOLCHAIN}) 74 | nebula_add_shared_linker_flag(--gcc-toolchain=${NEBULA_CLANG_USE_GCC_TOOLCHAIN}) 75 | if(NOT "${gcc_target_triplet}" STREQUAL "") 76 | add_compile_options(--target=${gcc_target_triplet}) 77 | nebula_add_exe_linker_flag(--target=${gcc_target_triplet}) 78 | nebula_add_shared_linker_flag(--target=${gcc_target_triplet}) 79 | endif() 80 | endif() 81 | #add_compile_options(-Wno-mismatched-tags) 82 | add_compile_options(-Wno-self-assign-overloaded) 83 | add_compile_options(-Wno-self-move) 84 | add_compile_options(-Wno-format-pedantic) 85 | add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) 86 | set(libatomic_link_flags "-Wl,-Bstatic -latomic -Wl,-Bdynamic") 87 | set(CMAKE_REQUIRED_FLAGS "${libatomic_link_flags}") 88 | check_cxx_compiler_flag("${libatomic_link_flags}" has_static_libatomic) 89 | if(NOT has_static_libatomic) 90 | set(libatomic_link_flags "-latomic") 91 | endif() 92 | endif() 93 | -------------------------------------------------------------------------------- /cmake/nebula/GitHooksConfig.cmake: -------------------------------------------------------------------------------- 1 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/") 2 | # Create the pre-commit hook every time we run cmake 3 | message(STATUS "Create the pre-commit hook") 4 | set(PRE_COMMIT_HOOK ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit) 5 | execute_process( 6 | COMMAND 7 | "rm" "-f" ${PRE_COMMIT_HOOK} 8 | ) 9 | execute_process( 10 | COMMAND 11 | "ln" "-s" ${CMAKE_CURRENT_SOURCE_DIR}/.linters/cpp/hooks/pre-commit.sh ${PRE_COMMIT_HOOK} 12 | RESULT_VARIABLE retcode 13 | ) 14 | if(${retcode} EQUAL 0) 15 | MESSAGE(STATUS "Creating pre-commit hook done") 16 | else() 17 | MESSAGE(FATAL_ERROR "Creating pre-commit hook failed: ${retcode}") 18 | endif() 19 | endif() 20 | -------------------------------------------------------------------------------- /cmake/nebula/GitInfoConfig.cmake: -------------------------------------------------------------------------------- 1 | find_package(Git) 2 | if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") 3 | execute_process( 4 | COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD 5 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 6 | OUTPUT_VARIABLE GIT_INFO_SHA 7 | ) 8 | endif() 9 | 10 | if (GIT_INFO_SHA) 11 | string(REGEX REPLACE "[^0-9a-f]+" "" GIT_INFO_SHA "${GIT_INFO_SHA}") 12 | endif() 13 | -------------------------------------------------------------------------------- /cmake/nebula/InstallThirdParty.cmake: -------------------------------------------------------------------------------- 1 | set(third_party_install_prefix ${CMAKE_BINARY_DIR}/third-party/install) 2 | message(STATUS "Downloading prebuilt third party automatically...") 3 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 4 | if(NOT ${NEBULA_CLANG_USED_GCC_TOOLCHAIN} STREQUAL "") 5 | set(cxx_cmd ${NEBULA_CLANG_USED_GCC_TOOLCHAIN}/bin/g++) 6 | else() 7 | set(cxx_cmd ${CMAKE_CXX_COMPILER}) 8 | endif() 9 | else() 10 | set(cxx_cmd ${CMAKE_CXX_COMPILER}) 11 | endif() 12 | if(${DISABLE_CXX11_ABI}) 13 | set(cxx_cmd "${cxx_cmd} -D_GLIBCXX_USE_CXX11_ABI=0") 14 | else() 15 | set(cxx_cmd "${cxx_cmd} -D_GLIBCXX_USE_CXX11_ABI=1") 16 | endif() 17 | message(STATUS "cxx_cmd: ${cxx_cmd}") 18 | execute_process( 19 | COMMAND 20 | env CXX=${cxx_cmd} version=${NEBULA_THIRDPARTY_VERSION} ${CMAKE_SOURCE_DIR}/third-party/install-third-party.sh --prefix=${third_party_install_prefix} 21 | WORKING_DIRECTORY 22 | ${CMAKE_BINARY_DIR} 23 | ) 24 | 25 | if(EXISTS ${third_party_install_prefix}) 26 | set(NEBULA_THIRDPARTY_ROOT ${third_party_install_prefix}) 27 | endif() 28 | unset(third_party_install_prefix) 29 | -------------------------------------------------------------------------------- /cmake/nebula/LinkerConfig.cmake: -------------------------------------------------------------------------------- 1 | execute_process( 2 | COMMAND 3 | ld --version 4 | COMMAND 5 | head -1 6 | COMMAND 7 | cut -d " " -f2 8 | OUTPUT_VARIABLE default_linker_type 9 | OUTPUT_STRIP_TRAILING_WHITESPACE 10 | ) 11 | 12 | if ("${default_linker_type}" STREQUAL "ld") 13 | set(default_linker_type "bfd") 14 | endif() 15 | 16 | if (NOT DEFINED NEBULA_USE_LINKER) 17 | set(NEBULA_USE_LINKER ${default_linker_type}) 18 | endif() 19 | print_config(NEBULA_USE_LINKER) 20 | 21 | nebula_add_exe_linker_flag(-fuse-ld=${NEBULA_USE_LINKER}) 22 | nebula_add_shared_linker_flag(-fuse-ld=${NEBULA_USE_LINKER}) 23 | nebula_add_exe_linker_flag(-static-libstdc++) 24 | nebula_add_exe_linker_flag(-static-libgcc) 25 | nebula_add_exe_linker_flag(-no-pie) 26 | nebula_add_exe_linker_flag(-rdynamic) 27 | 28 | if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") 29 | add_definitions(-D_FORTIFY_SOURCE=2) 30 | else() 31 | # The mips need to add it when build Debug to lift the usual restrictions on the size of the global offset table. 32 | if (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "mips64") 33 | add_compile_options(-mxgot) 34 | endif() 35 | 36 | if (NOT ${NEBULA_USE_LINKER} STREQUAL "gold" AND NOT ENABLE_GDB_SCRIPT_SECTION) 37 | # `gold' linker is buggy for `--gc-sections', disabled for it 38 | # `gc-sections' will discard the `.debug_gdb_scripts' section if enabled 39 | add_compile_options(-ffunction-sections) 40 | add_compile_options(-fdata-sections) 41 | nebula_add_exe_linker_flag(-Wl,--gc-sections) 42 | endif() 43 | endif() 44 | 45 | if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") 46 | # The mips not supported 47 | if (NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "mips64") 48 | if(ENABLE_COMPRESSED_DEBUG_INFO) 49 | nebula_add_exe_linker_flag(-Wl,--compress-debug-sections=zlib) 50 | else() 51 | nebula_remove_exe_linker_flag(-Wl,--compress-debug-sections=zlib) 52 | endif() 53 | endif() 54 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 55 | add_compile_options(-fno-limit-debug-info) 56 | endif() 57 | endif() 58 | -------------------------------------------------------------------------------- /cmake/nebula/MakeBisonRelocatable.cmake: -------------------------------------------------------------------------------- 1 | set(BISON_EXECUTE_ENV "") 2 | execute_process( 3 | COMMAND ${BISON_EXECUTABLE} --print-datadir 4 | OUTPUT_VARIABLE bison_encoded_data_dir 5 | OUTPUT_STRIP_TRAILING_WHITESPACE 6 | ) 7 | if(NOT EXISTS ${bison_encoded_data_dir}) 8 | get_filename_component(bison_prefix ${BISON_EXECUTABLE} DIRECTORY) 9 | get_filename_component(bison_prefix ${bison_prefix} DIRECTORY) 10 | if(EXISTS ${bison_prefix}/share/bison) 11 | set(BISON_EXECUTE_ENV "BISON_PKGDATADIR=${bison_prefix}/share/bison") 12 | endif() 13 | endif() 14 | if(NOT ${BISON_EXECUTE_ENV} STREQUAL "") 15 | set(BISON_EXECUTABLE ${CMAKE_COMMAND} -E env ${BISON_EXECUTE_ENV} ${BISON_EXECUTABLE}) 16 | endif() 17 | 18 | -------------------------------------------------------------------------------- /cmake/nebula/NebulaCustomTargets.cmake: -------------------------------------------------------------------------------- 1 | set(NEBULA_CLEAN_ALL_DEPS clean-interface clean-bin) 2 | 3 | add_custom_target( 4 | clean-bin 5 | COMMAND "rm" "-fr" "bin/*" 6 | ) 7 | 8 | add_custom_target( 9 | clean-build 10 | COMMAND ${CMAKE_MAKE_PROGRAM} clean 11 | COMMAND "find" "." "-name" "Testing" "|" "xargs" "rm" "-fr" 12 | DEPENDS ${NEBULA_CLEAN_ALL_DEPS} 13 | ) 14 | 15 | add_custom_target( 16 | clean-all 17 | COMMAND ${CMAKE_MAKE_PROGRAM} clean 18 | COMMAND "find" "." "-name" "Testing" "|" "xargs" "rm" "-fr" 19 | DEPENDS ${NEBULA_CLEAN_ALL_DEPS} 20 | ) 21 | 22 | add_custom_target( 23 | distclean 24 | COMMAND "find" "." "-name" "CMakeFiles" "|" "xargs" "rm" "-fr" 25 | COMMAND "find" "." "-name" "CMakeCache.txt" "|" "xargs" "rm" "-f" 26 | COMMAND "find" "." "-name" "cmake_install.cmake" "|" "xargs" "rm" "-f" 27 | COMMAND "find" "." "-name" "CTestTestfile.cmake" "|" "xargs" "rm" "-f" 28 | COMMAND "find" "." "-name" "Makefile" "|" "xargs" "rm" "-f" 29 | DEPENDS clean-all 30 | ) 31 | -------------------------------------------------------------------------------- /cmake/nebula/PlatformCheck.cmake: -------------------------------------------------------------------------------- 1 | if(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|FreeBSD|Windows)") 2 | MESSAGE(FATAL_ERROR "Only Linux is supported") 3 | endif () 4 | -------------------------------------------------------------------------------- /cmake/nebula/SanitizerConfig.cmake: -------------------------------------------------------------------------------- 1 | if(ENABLE_ASAN OR ENABLE_UBSAN) 2 | add_definitions(-DBUILT_WITH_SANITIZER) 3 | endif() 4 | 5 | if(ENABLE_ASAN) 6 | set(CMAKE_REQUIRED_FLAGS "-fsanitize=address") 7 | check_cxx_compiler_flag("-fsanitize=address" ENABLE_ASAN_OK) 8 | if (NOT ENABLE_ASAN_OK) 9 | MESSAGE(FATAL_ERROR "The compiler does not support address sanitizer") 10 | endif() 11 | if(ENABLE_STATIC_ASAN AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 12 | add_compile_options(-static-libasan) 13 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan") 14 | endif() 15 | add_compile_options(-fsanitize=address) 16 | add_compile_options(-g) 17 | add_compile_options(-fno-omit-frame-pointer) 18 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") 19 | endif() 20 | 21 | if(ENABLE_TSAN) 22 | if (ENABLE_ASAN) 23 | MESSAGE(FATAL_ERROR "ENABLE_TSAN cannot be combined with ENABLE_ASAN") 24 | endif() 25 | set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread") 26 | check_cxx_compiler_flag("-fsanitize=thread" ENABLE_TSAN_OK) 27 | if (NOT ENABLE_TSAN_OK) 28 | MESSAGE(FATAL_ERROR "The compiler does not support thread sanitizer") 29 | endif() 30 | set(ENV{TSAN_OPTIONS} "report_atomic_races=0") 31 | add_compile_options(-fsanitize=thread) 32 | add_compile_options(-g) 33 | add_compile_options(-fno-omit-frame-pointer) 34 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") 35 | endif() 36 | 37 | if(ENABLE_UBSAN) 38 | check_cxx_compiler_flag("-fsanitize=undefined -fno-sanitize=alignment" ENABLE_UBSAN_OK) 39 | if (NOT ENABLE_UBSAN_OK) 40 | MESSAGE(FATAL_ERROR "The compiler does not support Undefined Behavior Sanitizer") 41 | endif() 42 | if(ENABLE_STATIC_UBSAN AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 43 | add_compile_options(-static-libubsan) 44 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libubsan") 45 | endif() 46 | add_compile_options(-fsanitize=undefined -fno-sanitize=alignment) 47 | add_compile_options(-fno-sanitize-recover=all) # Exit on failure 48 | # TODO(dutor) Remove the following line when RTTI-enabled RocksDB is ready 49 | add_compile_options(-fno-sanitize=vptr) 50 | if(NOT ENABLE_ASAN) 51 | add_compile_options(-g) 52 | add_compile_options(-fno-omit-frame-pointer) 53 | endif() 54 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") 55 | endif() 56 | 57 | if(ENABLE_FUZZ_TEST) 58 | check_cxx_compiler_flag("-fsanitize=fuzzer" ENABLE_FUZZ_OK) 59 | if (NOT ENABLE_FUZZ_OK) 60 | MESSAGE(FATAL_ERROR "The compiler does not support fuzz testing") 61 | endif() 62 | endif() 63 | -------------------------------------------------------------------------------- /date.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # 3 | # Copyright (c) 2021 vesoft inc. All rights reserved. 4 | # 5 | # This source code is licensed under Apache 2.0 License. 6 | 7 | import datetime 8 | import argparse 9 | 10 | parser = argparse.ArgumentParser(description='Process command line arguments.') 11 | parser.add_argument('--day_diff', dest='day_diff', action='store', type=int) 12 | 13 | args = parser.parse_args() 14 | 15 | current = datetime.date.today() 16 | day_diff = datetime.timedelta(days=args.day_diff) 17 | current = current - day_diff 18 | 19 | print(current.strftime('%Y.%m.%d')) 20 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | # 5 | 6 | # Set the project name 7 | project("Nebula C++ Client simple example" C CXX) 8 | cmake_minimum_required(VERSION 2.8.0) 9 | 10 | set(CMAKE_CXX_STANDARD 11) # specify the C++ standard 11 | 12 | if (NOT NEBULA_HOME) 13 | set(NEBULA_HOME /usr/local/nebula) 14 | endif() 15 | 16 | option(DISABLE_CXX11_ABI "Whether to disable cxx11 abi" OFF) 17 | 18 | # Is abi 11 19 | if (DISABLE_CXX11_ABI) 20 | message(STATUS "Set D_GLIBCXX_USE_CXX11_ABI to 0") 21 | add_compile_options(-D_GLIBCXX_USE_CXX11_ABI=0) 22 | else() 23 | message(STATUS "Set D_GLIBCXX_USE_CXX11_ABI to 1") 24 | add_compile_options(-D_GLIBCXX_USE_CXX11_ABI=1) 25 | endif() 26 | 27 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") 28 | 29 | # This project only depends on the nebula-client headers/library 30 | include_directories(${NEBULA_HOME}/include) 31 | link_directories(${NEBULA_HOME}/lib64) 32 | link_directories(${NEBULA_HOME}/lib) 33 | 34 | add_executable(session_example 35 | SessionExample.cpp 36 | ) 37 | 38 | add_executable(session_pool_example 39 | SessionPoolExample.cpp 40 | ) 41 | 42 | add_executable(storage_client_example 43 | StorageClientExample.cpp 44 | ) 45 | 46 | target_link_libraries(session_example 47 | PRIVATE 48 | nebula_graph_client 49 | -pthread 50 | ) 51 | 52 | target_link_libraries(session_pool_example 53 | PRIVATE 54 | nebula_graph_client 55 | -pthread 56 | ) 57 | 58 | target_link_libraries(storage_client_example 59 | PRIVATE 60 | nebula_storage_client 61 | -pthread 62 | ) 63 | -------------------------------------------------------------------------------- /examples/SessionExample.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main(int argc, char* argv[]) { 15 | nebula::init(&argc, &argv); 16 | auto address = "127.0.0.1:9669"; 17 | if (argc == 2) { 18 | address = argv[1]; 19 | } 20 | std::cout << "Current address: " << address << std::endl; 21 | nebula::ConnectionPool pool; 22 | pool.init({address}, nebula::Config{}); 23 | auto session = pool.getSession("root", "nebula"); 24 | if (!session.valid()) { 25 | return -1; 26 | } 27 | 28 | auto result = session.execute("SHOW HOSTS"); 29 | if (result.errorCode != nebula::ErrorCode::SUCCEEDED) { 30 | std::cout << "Exit with error code: " << static_cast(result.errorCode) << std::endl; 31 | return static_cast(result.errorCode); 32 | } 33 | std::cout << *result.data; 34 | 35 | std::atomic_bool complete{false}; 36 | session.asyncExecute("SHOW HOSTS", [&complete](nebula::ExecutionResponse&& cbResult) { 37 | if (cbResult.errorCode != nebula::ErrorCode::SUCCEEDED) { 38 | std::cout << "Exit with error code: " << static_cast(cbResult.errorCode) 39 | << std::endl; 40 | std::exit(static_cast(cbResult.errorCode)); 41 | } 42 | std::cout << *cbResult.data; 43 | complete.store(true); 44 | }); 45 | 46 | while (!complete.load()) { 47 | std::this_thread::sleep_for(std::chrono::seconds(1)); 48 | } 49 | 50 | session.release(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /examples/SessionPoolExample.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 vesoft inc. All rights reserved. 2 | // 3 | // This source code is licensed under Apache 2.0 License. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "nebula/client/Config.h" 13 | 14 | int main(int argc, char* argv[]) { 15 | nebula::init(&argc, &argv); 16 | { 17 | // Create space 18 | nebula::ConnectionPool pool; 19 | auto config = nebula::Config{}; 20 | config.maxConnectionPoolSize_ = 1; 21 | pool.init({"127.0.0.1:9669"}, config); 22 | auto session = pool.getSession("root", "nebula"); 23 | assert(session.valid()); 24 | 25 | auto resp = session.execute( 26 | "CREATE SPACE IF NOT EXISTS session_pool_test(vid_type = FIXED_STRING(16));"); 27 | assert(resp.errorCode == nebula::ErrorCode::SUCCEEDED); 28 | } 29 | 30 | nebula::SessionPoolConfig config; 31 | config.username_ = "root"; 32 | config.password_ = "nebula"; 33 | config.addrs_ = {"127.0.0.1:9669"}; 34 | config.spaceName_ = "session_pool_test"; 35 | config.maxSize_ = 10; 36 | nebula::SessionPool pool(config); 37 | assert(pool.init()); 38 | 39 | std::vector threads; 40 | for (std::size_t i = 0; i < config.maxSize_; ++i) { 41 | threads.emplace_back([&pool]() { 42 | auto resp = pool.execute("YIELD 1"); 43 | std::cout << "resp's error code: " << resp.errorCode << std::endl; 44 | assert(resp.errorCode == nebula::ErrorCode::SUCCEEDED); 45 | std::cout << "Result: " << *resp.data << std::endl; 46 | }); 47 | } 48 | for (auto& t : threads) { 49 | t.join(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/StorageClientExample.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "common/graph/Response.h" 16 | 17 | int main(int argc, char* argv[]) { 18 | nebula::init(&argc, &argv); 19 | 20 | nebula::StorageClient c({"127.0.0.1:9559"}); 21 | 22 | nebula::ScanEdgeIter scanEdgeIter = c.scanEdgeWithPart("nba", 23 | 1, 24 | "like", 25 | std::vector{"likeness"}, 26 | 10, 27 | 0, 28 | std::numeric_limits::max(), 29 | "", 30 | true, 31 | true); 32 | std::cout << "scan edge..." << std::endl; 33 | while (scanEdgeIter.hasNext()) { 34 | std::cout << "-------------------------" << std::endl; 35 | std::pair res = scanEdgeIter.next(); 36 | std::cout << res.first << std::endl; 37 | std::cout << res.second << std::endl; 38 | std::cout << "+++++++++++++++++++++++++" << std::endl; 39 | } 40 | 41 | nebula::ScanVertexIter scanVertexIter = 42 | c.scanVertexWithPart("nba", 43 | 1, 44 | {{"player", std::vector{"name"}}}, 45 | 10, 46 | 0, 47 | std::numeric_limits::max(), 48 | "", 49 | true, 50 | true); 51 | std::cout << "scan vertex..." << std::endl; 52 | while (scanVertexIter.hasNext()) { 53 | std::cout << "-------------------------" << std::endl; 54 | std::pair res = scanVertexIter.next(); 55 | std::cout << res.first << std::endl; 56 | std::cout << res.second << std::endl; 57 | std::cout << "+++++++++++++++++++++++++" << std::endl; 58 | } 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /exported-symbols.map: -------------------------------------------------------------------------------- 1 | 2 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 3 | * 4 | * This source code is licensed under Apache 2.0 License. 5 | */ 6 | 7 | { 8 | global: 9 | extern "C++" { 10 | nebula::Connection::*; 11 | nebula::ConnectionPool::*; 12 | "nebula::init(int*, char***)"; 13 | nebula::Session::*; 14 | nebula::SessionPool::*; 15 | nebula::Value::*; 16 | nebula::DataSet::*; 17 | nebula::Date::*; 18 | nebula::DateTime::*; 19 | nebula::Time::*; 20 | nebula::Edge::*; 21 | nebula::Vertex::*; 22 | nebula::HostAddr::*; 23 | nebula::KeyValue::*; 24 | nebula::List::*; 25 | nebula::Map::*; 26 | nebula::Path::*; 27 | nebula::Set::*; 28 | nebula::AuthResponse::*; 29 | nebula::ProfilingStats::*; 30 | nebula::PlanNodeBranchInfo::*; 31 | nebula::Pair::*; 32 | nebula::PlanNodeDescription::*; 33 | nebula::PlanDescription::*; 34 | nebula::ExecutionResponse::*; 35 | nebula::StorageClient::*; 36 | nebula::ScanEdgeIter::*; 37 | nebula::ScanVertexIter::*; 38 | *::_S_empty_rep_storage; 39 | }; 40 | local: 41 | *; 42 | }; 43 | -------------------------------------------------------------------------------- /gen-interface.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # Copyright (c) 2021 vesoft inc. All rights reserved. 4 | # 5 | # This source code is licensed under Apache 2.0 License. 6 | 7 | set -e 8 | 9 | NEBULA_THIRDPARYTY_HOME=/opt/vesoft/third-party/2.0 10 | NEBULA_INTERFACE_HOME=src/interface 11 | SYNC_REMOTE_INTERFACE=0 12 | 13 | # Parsing options from arguments 14 | while getopts "t:u" opt; do 15 | case $opt in 16 | t) 17 | NEBULA_THIRDPARYTY_HOME=${OPTARG} 18 | ;; 19 | u) 20 | SYNC_REMOTE_INTERFACE=1 21 | ;; 22 | \?) 23 | echo "Invalid option: -${OPTARG}" >&2 24 | exit 1 25 | ;; 26 | :) 27 | echo "Option -${OPTARG} requires an argument." >&2 28 | exit 1 29 | ;; 30 | esac 31 | done 32 | 33 | if [ $SYNC_REMOTE_INTERFACE -eq 1 ]; then 34 | for mod in common meta storage graph; do 35 | wget -O $NEBULA_INTERFACE_HOME/$mod.thrift https://raw.githubusercontent.com/vesoft-inc/nebula/master/src/interface/$mod.thrift 36 | done 37 | fi 38 | 39 | # Strip nebula source 40 | # for mod in common graph; do 41 | # sed -i '/cpp_include/d' $mod.thrift 42 | # sed -i 's/cpp.type = "[^"]\+"//g' $mod.thrift 43 | # done 44 | 45 | pushd $NEBULA_INTERFACE_HOME 46 | for mod in common meta storage graph; do 47 | $NEBULA_THIRDPARYTY_HOME/bin/thrift1 --strict --allow-neg-enum-vals --gen "mstch_cpp2:include_prefix=${include_prefix},stack_arguments" -o . $mod.thrift 48 | done 49 | popd 50 | -------------------------------------------------------------------------------- /include/common/Init.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace nebula { 9 | 10 | void init(int *argc, char **argv[]); 11 | 12 | } // namespace nebula 13 | -------------------------------------------------------------------------------- /include/common/datatypes/CommonCpp2Ops.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "common/thrift/ThriftCpp2OpsHelper.h" 9 | 10 | namespace nebula { 11 | struct Value; 12 | struct Vertex; 13 | struct Tag; 14 | struct Edge; 15 | struct Step; 16 | struct Path; 17 | struct HostAddr; 18 | struct KeyValue; 19 | struct Date; 20 | struct DateTime; 21 | struct Time; 22 | struct Map; 23 | struct Set; 24 | struct List; 25 | struct DataSet; 26 | struct Coordinate; 27 | struct Point; 28 | struct LineString; 29 | struct Polygon; 30 | struct Geography; 31 | struct Duration; 32 | } // namespace nebula 33 | 34 | namespace apache::thrift { 35 | 36 | SPECIALIZE_CPP2OPS(nebula::Value); 37 | SPECIALIZE_CPP2OPS(nebula::Vertex); 38 | SPECIALIZE_CPP2OPS(nebula::Tag); 39 | SPECIALIZE_CPP2OPS(nebula::Edge); 40 | SPECIALIZE_CPP2OPS(nebula::Step); 41 | SPECIALIZE_CPP2OPS(nebula::Path); 42 | SPECIALIZE_CPP2OPS(nebula::HostAddr); 43 | SPECIALIZE_CPP2OPS(nebula::KeyValue); 44 | SPECIALIZE_CPP2OPS(nebula::Date); 45 | SPECIALIZE_CPP2OPS(nebula::Time); 46 | SPECIALIZE_CPP2OPS(nebula::DateTime); 47 | SPECIALIZE_CPP2OPS(nebula::Map); 48 | SPECIALIZE_CPP2OPS(nebula::Set); 49 | SPECIALIZE_CPP2OPS(nebula::List); 50 | SPECIALIZE_CPP2OPS(nebula::DataSet); 51 | SPECIALIZE_CPP2OPS(nebula::Coordinate); 52 | SPECIALIZE_CPP2OPS(nebula::Point); 53 | SPECIALIZE_CPP2OPS(nebula::LineString); 54 | SPECIALIZE_CPP2OPS(nebula::Polygon); 55 | SPECIALIZE_CPP2OPS(nebula::Geography); 56 | SPECIALIZE_CPP2OPS(nebula::Duration); 57 | 58 | } // namespace apache::thrift 59 | -------------------------------------------------------------------------------- /include/common/datatypes/Edge.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/Value.h" 11 | #include "common/thrift/ThriftTypes.h" 12 | 13 | namespace nebula { 14 | 15 | struct Edge { 16 | Value src; 17 | Value dst; 18 | EdgeType type; 19 | std::string name; 20 | EdgeRanking ranking; 21 | std::unordered_map props; 22 | 23 | Edge() {} 24 | Edge(Edge&& v) noexcept 25 | : src(std::move(v.src)), 26 | dst(std::move(v.dst)), 27 | type(std::move(v.type)), 28 | name(std::move(v.name)), 29 | ranking(std::move(v.ranking)), 30 | props(std::move(v.props)) {} 31 | Edge(const Edge& v) 32 | : src(v.src), dst(v.dst), type(v.type), name(v.name), ranking(v.ranking), props(v.props) {} 33 | Edge(Value s, 34 | Value d, 35 | EdgeType t, 36 | std::string n, 37 | EdgeRanking r, 38 | std::unordered_map&& p) 39 | : src(std::move(s)), 40 | dst(std::move(d)), 41 | type(std::move(t)), 42 | name(std::move(n)), 43 | ranking(std::move(r)), 44 | props(std::move(p)) {} 45 | 46 | void clear(); 47 | 48 | void __clear() { 49 | clear(); 50 | } 51 | 52 | std::string toString() const; 53 | 54 | bool operator==(const Edge& rhs) const; 55 | 56 | void format() { 57 | if (type < 0) { 58 | reverse(); 59 | } 60 | } 61 | 62 | void reverse(); 63 | 64 | bool operator<(const Edge& rhs) const; 65 | 66 | bool contains(const Value& key) const; 67 | 68 | const Value& value(const std::string& key) const; 69 | }; 70 | 71 | inline std::ostream& operator<<(std::ostream& os, const Edge& v) { 72 | return os << v.toString(); 73 | } 74 | 75 | } // namespace nebula 76 | 77 | namespace std { 78 | 79 | // Inject a customized hash function 80 | template <> 81 | struct hash { 82 | std::size_t operator()(const nebula::Edge& h) const noexcept; 83 | }; 84 | 85 | } // namespace std 86 | -------------------------------------------------------------------------------- /include/common/datatypes/HostAddr.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/thrift/ThriftTypes.h" 11 | 12 | namespace nebula { 13 | 14 | // Host address type and utility functions 15 | struct HostAddr { 16 | std::string host; 17 | Port port; 18 | 19 | HostAddr() : host(), port(0) {} 20 | /* 21 | * some one may ctor HostAddr this way : HostAddr host(0, 0) 22 | * C++ will compile this successfully even we don't support an (int, int) ctor 23 | * so, add an explicit delete ctor 24 | * */ 25 | HostAddr(int h, int p) = delete; 26 | HostAddr(std::string h, Port p) : host(std::move(h)), port(p) {} 27 | 28 | void clear() { 29 | host.clear(); 30 | port = 0; 31 | } 32 | 33 | void __clear() { 34 | clear(); 35 | } 36 | 37 | std::string toString() const { 38 | std::stringstream os; 39 | os << "\"" << host << "\"" 40 | << ":" << port; 41 | return os.str(); 42 | } 43 | 44 | bool operator==(const HostAddr& rhs) const; 45 | 46 | bool operator!=(const HostAddr& rhs) const; 47 | 48 | bool operator<(const HostAddr& rhs) const; 49 | }; 50 | 51 | inline std::ostream& operator<<(std::ostream& os, const HostAddr& addr) { 52 | return os << addr.toString(); 53 | } 54 | 55 | } // namespace nebula 56 | 57 | namespace std { 58 | 59 | // Inject a customized hash function 60 | template <> 61 | struct hash { 62 | std::size_t operator()(const nebula::HostAddr& h) const noexcept; 63 | }; 64 | 65 | } // namespace std 66 | -------------------------------------------------------------------------------- /include/common/datatypes/KeyValue.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace nebula { 9 | 10 | struct KeyValue { 11 | std::string key; 12 | std::string value; 13 | 14 | KeyValue() {} 15 | KeyValue(KeyValue&& rhs) noexcept : key(std::move(rhs.key)), value(std::move(rhs.value)) {} 16 | KeyValue(const KeyValue& rhs) : key(rhs.key), value(rhs.value) {} 17 | explicit KeyValue(std::pair kv) 18 | : key(std::move(kv.first)), value(std::move(kv.second)) {} 19 | 20 | void clear() { 21 | key.clear(); 22 | value.clear(); 23 | } 24 | 25 | void __clear() { 26 | clear(); 27 | } 28 | 29 | bool operator==(const KeyValue& rhs) const { 30 | if (key != rhs.key) { 31 | return false; 32 | } 33 | return value == rhs.value; 34 | } 35 | 36 | bool operator<(const KeyValue& rhs) const { 37 | if (key != rhs.key) { 38 | return key < rhs.key; 39 | } 40 | return value < rhs.value; 41 | } 42 | }; 43 | 44 | } // namespace nebula 45 | -------------------------------------------------------------------------------- /include/common/datatypes/List.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "common/datatypes/Value.h" 12 | 13 | namespace nebula { 14 | 15 | struct List { 16 | std::vector values; 17 | 18 | List() = default; 19 | List(const List&) = default; 20 | List(List&&) noexcept = default; 21 | explicit List(std::vector&& vals) { 22 | values = std::move(vals); 23 | } 24 | explicit List(const std::vector& l) : values(l) {} 25 | 26 | bool empty() const { 27 | return values.empty(); 28 | } 29 | 30 | void reserve(std::size_t n) { 31 | values.reserve(n); 32 | } 33 | 34 | template ::value>::type> 36 | void emplace_back(T&& v) { 37 | values.emplace_back(std::forward(v)); 38 | } 39 | 40 | void clear() { 41 | values.clear(); 42 | } 43 | 44 | void __clear() { 45 | clear(); 46 | } 47 | 48 | List& operator=(const List& rhs) { 49 | if (this == &rhs) { 50 | return *this; 51 | } 52 | values = rhs.values; 53 | return *this; 54 | } 55 | List& operator=(List&& rhs) noexcept { 56 | if (this == &rhs) { 57 | return *this; 58 | } 59 | values = std::move(rhs.values); 60 | return *this; 61 | } 62 | 63 | bool operator==(const List& rhs) const { 64 | return values == rhs.values; 65 | } 66 | 67 | bool operator<(const List& rhs) const { 68 | return values < rhs.values; 69 | } 70 | 71 | const Value& operator[](size_t i) const { 72 | return values[i]; 73 | } 74 | 75 | bool contains(const Value& value) const { 76 | return std::find(values.begin(), values.end(), value) != values.end(); 77 | } 78 | 79 | size_t size() const { 80 | return values.size(); 81 | } 82 | 83 | std::string toString() const; 84 | }; 85 | 86 | inline std::ostream& operator<<(std::ostream& os, const List& l) { 87 | return os << l.toString(); 88 | } 89 | 90 | } // namespace nebula 91 | 92 | namespace std { 93 | template <> 94 | struct hash { 95 | std::size_t operator()(const nebula::List& h) const noexcept { 96 | size_t seed = 0; 97 | for (auto& v : h.values) { 98 | seed ^= hash()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 99 | } 100 | return seed; 101 | } 102 | }; 103 | } // namespace std 104 | -------------------------------------------------------------------------------- /include/common/datatypes/Map.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/Value.h" 11 | 12 | namespace nebula { 13 | 14 | struct Map { 15 | std::unordered_map kvs; 16 | 17 | Map() = default; 18 | Map(const Map&) = default; 19 | Map(Map&&) noexcept = default; 20 | explicit Map(std::unordered_map values) { 21 | kvs = std::move(values); 22 | } 23 | 24 | Map& operator=(const Map& rhs) { 25 | if (this == &rhs) { 26 | return *this; 27 | } 28 | kvs = rhs.kvs; 29 | return *this; 30 | } 31 | Map& operator=(Map&& rhs) noexcept { 32 | if (this == &rhs) { 33 | return *this; 34 | } 35 | kvs = std::move(rhs.kvs); 36 | return *this; 37 | } 38 | 39 | void clear() { 40 | kvs.clear(); 41 | } 42 | 43 | void __clear() { 44 | clear(); 45 | } 46 | 47 | // the configs of rocksdb will use the interface, so the value need modify to 48 | // string 49 | std::string toString() const; 50 | 51 | bool operator==(const Map& rhs) const { 52 | return kvs == rhs.kvs; 53 | } 54 | 55 | bool contains(const Value& value) const { 56 | if (!value.isStr()) { 57 | return false; 58 | } 59 | return kvs.count(value.getStr()) != 0; 60 | } 61 | 62 | const Value& at(const std::string& key) const { 63 | auto iter = kvs.find(key); 64 | if (iter == kvs.end()) { 65 | return Value::kNullUnknownProp; 66 | } 67 | return iter->second; 68 | } 69 | 70 | size_t size() const { 71 | return kvs.size(); 72 | } 73 | }; 74 | 75 | inline std::ostream& operator<<(std::ostream& os, const Map& m) { 76 | return os << m.toString(); 77 | } 78 | 79 | } // namespace nebula 80 | 81 | namespace std { 82 | template <> 83 | struct hash { 84 | std::size_t operator()(const nebula::Map& m) const noexcept; 85 | }; 86 | 87 | } // namespace std 88 | -------------------------------------------------------------------------------- /include/common/datatypes/Set.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/Value.h" 11 | 12 | namespace nebula { 13 | 14 | struct Set { 15 | std::unordered_set values; 16 | 17 | Set() = default; 18 | Set(const Set&) = default; 19 | Set(Set&&) noexcept = default; 20 | explicit Set(std::unordered_set value) { 21 | values = std::move(value); 22 | } 23 | 24 | void clear() { 25 | values.clear(); 26 | } 27 | 28 | void __clear() { 29 | clear(); 30 | } 31 | 32 | std::string toString() const; 33 | 34 | Set& operator=(const Set& rhs) { 35 | if (this == &rhs) { 36 | return *this; 37 | } 38 | values = rhs.values; 39 | return *this; 40 | } 41 | 42 | Set& operator=(Set&& rhs) noexcept { 43 | if (this == &rhs) { 44 | return *this; 45 | } 46 | values = std::move(rhs.values); 47 | return *this; 48 | } 49 | 50 | bool operator==(const Set& rhs) const { 51 | return values == rhs.values; 52 | } 53 | 54 | bool contains(const Value& value) const { 55 | return values.count(value) != 0; 56 | } 57 | 58 | size_t size() const { 59 | return values.size(); 60 | } 61 | }; 62 | 63 | inline std::ostream& operator<<(std::ostream& os, const Set& s) { 64 | return os << s.toString(); 65 | } 66 | 67 | } // namespace nebula 68 | 69 | namespace std { 70 | template <> 71 | struct hash { 72 | std::size_t operator()(const nebula::Set& s) const noexcept; 73 | }; 74 | 75 | } // namespace std 76 | -------------------------------------------------------------------------------- /include/common/datatypes/Vertex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common/datatypes/Value.h" 13 | #include "common/thrift/ThriftTypes.h" 14 | 15 | namespace nebula { 16 | 17 | struct Tag { 18 | std::string name; 19 | std::unordered_map props; 20 | 21 | Tag() = default; 22 | Tag(Tag&& tag) noexcept : name(std::move(tag.name)), props(std::move(tag.props)) {} 23 | Tag(const Tag& tag) : name(tag.name), props(tag.props) {} 24 | Tag(std::string tagName, std::unordered_map tagProps) 25 | : name(std::move(tagName)), props(std::move(tagProps)) {} 26 | 27 | void clear() { 28 | name.clear(); 29 | props.clear(); 30 | } 31 | 32 | void __clear() { 33 | clear(); 34 | } 35 | 36 | std::string toString() const; 37 | 38 | Tag& operator=(Tag&& rhs) noexcept { 39 | if (&rhs != this) { 40 | name = std::move(rhs.name); 41 | props = std::move(rhs.props); 42 | } 43 | return *this; 44 | } 45 | 46 | Tag& operator=(const Tag& rhs) { 47 | if (&rhs != this) { 48 | name = rhs.name; 49 | props = rhs.props; 50 | } 51 | return *this; 52 | } 53 | 54 | bool operator==(const Tag& rhs) const { 55 | return name == rhs.name && props == rhs.props; 56 | } 57 | }; 58 | 59 | struct Vertex { 60 | Value vid; 61 | std::vector tags; 62 | 63 | Vertex() = default; 64 | Vertex(const Vertex& v) : vid(v.vid), tags(v.tags) {} 65 | Vertex(Vertex&& v) noexcept : vid(std::move(v.vid)), tags(std::move(v.tags)) {} 66 | Vertex(Value id, std::vector t) : vid(std::move(id)), tags(std::move(t)) {} 67 | 68 | void clear() { 69 | vid.clear(); 70 | tags.clear(); 71 | } 72 | 73 | void __clear() { 74 | clear(); 75 | } 76 | 77 | std::string toString() const; 78 | 79 | Vertex& operator=(Vertex&& rhs) noexcept; 80 | 81 | Vertex& operator=(const Vertex& rhs); 82 | 83 | bool operator==(const Vertex& rhs) const { 84 | return vid == rhs.vid && tags == rhs.tags; 85 | } 86 | 87 | bool operator<(const Vertex& rhs) const; 88 | 89 | bool contains(const Value& key) const; 90 | 91 | const Value& value(const std::string& key) const; 92 | }; 93 | 94 | inline void swap(Vertex& a, Vertex& b) { 95 | auto temp = std::move(a); 96 | a = std::move(b); 97 | b = std::move(temp); 98 | } 99 | 100 | inline std::ostream& operator<<(std::ostream& os, const Vertex& v) { 101 | return os << v.toString(); 102 | } 103 | 104 | } // namespace nebula 105 | 106 | namespace std { 107 | 108 | // Inject a customized hash function 109 | template <> 110 | struct hash { 111 | std::size_t operator()(const nebula::Tag& h) const noexcept; 112 | }; 113 | 114 | template <> 115 | struct hash { 116 | std::size_t operator()(const nebula::Vertex& h) const noexcept; 117 | }; 118 | 119 | } // namespace std 120 | -------------------------------------------------------------------------------- /include/common/geo/io/wkb/ByteOrder.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace nebula { 9 | namespace geo { 10 | 11 | enum class ByteOrder : uint8_t { 12 | BigEndian = 0, 13 | LittleEndian = 1, 14 | }; 15 | 16 | } // namespace geo 17 | } // namespace nebula 18 | -------------------------------------------------------------------------------- /include/common/geo/io/wkb/ByteOrderDataIOStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/geo/io/wkb/ByteOrder.h" 11 | 12 | namespace nebula { 13 | namespace geo { 14 | 15 | class ByteOrderDataOutStream { 16 | public: 17 | ByteOrderDataOutStream() = default; 18 | 19 | ~ByteOrderDataOutStream() = default; 20 | 21 | std::string str() const { 22 | return stream_.str(); 23 | } 24 | 25 | void setByteOrder(ByteOrder order) { 26 | byteOrder_ = order; 27 | } 28 | 29 | void writeUint8(uint8_t v); 30 | 31 | void writeUint32(uint32_t v); 32 | 33 | void writeDouble(double v); 34 | 35 | private: 36 | ByteOrder byteOrder_; 37 | std::ostringstream stream_; 38 | unsigned char buf_[8]; 39 | }; 40 | 41 | } // namespace geo 42 | } // namespace nebula 43 | -------------------------------------------------------------------------------- /include/common/geo/io/wkb/WKBWriter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "common/datatypes/Geography.h" 9 | #include "common/geo/io/wkb/ByteOrder.h" 10 | #include "common/geo/io/wkb/ByteOrderDataIOStream.h" 11 | 12 | namespace nebula { 13 | namespace geo { 14 | 15 | class WKBWriter { 16 | public: 17 | WKBWriter() {} 18 | 19 | ~WKBWriter() {} 20 | 21 | std::string write(const Geography& geog, ByteOrder byteOrder = ByteOrder::LittleEndian); 22 | 23 | void writePoint(const Point& point); 24 | 25 | void writeLineString(const LineString& line); 26 | 27 | void writePolygon(const Polygon& polygon); 28 | 29 | void writeByteOrder(ByteOrder byteOrder); 30 | 31 | void writeShapeType(GeoShape geoShape); 32 | 33 | void writeCoordinate(const Coordinate& coord); 34 | 35 | void writeCoordinateList(const std::vector& coordList); 36 | 37 | void writeCoordinateListList(const std::vector>& coordListList); 38 | 39 | private: 40 | ByteOrderDataOutStream os_; 41 | }; 42 | 43 | } // namespace geo 44 | } // namespace nebula 45 | -------------------------------------------------------------------------------- /include/common/geo/io/wkt/WKTWriter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "common/datatypes/Geography.h" 12 | 13 | namespace nebula { 14 | namespace geo { 15 | 16 | class WKTWriter { 17 | public: 18 | WKTWriter() {} 19 | 20 | ~WKTWriter() {} 21 | 22 | std::string write(const Geography& geog) const; 23 | 24 | void writeCoordinate(std::string& wkt, const Coordinate& coord) const; 25 | 26 | void writeCoordinateList(std::string& wkt, const std::vector& coordList) const; 27 | 28 | void writeCoordinateListList(std::string& wkt, 29 | const std::vector>& coordListList) const; 30 | 31 | void writeDouble(std::string& wkt, double v) const; 32 | }; 33 | 34 | } // namespace geo 35 | } // namespace nebula 36 | -------------------------------------------------------------------------------- /include/common/graph/GraphCpp2Ops.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "common/thrift/ThriftCpp2OpsHelper.h" 9 | 10 | namespace nebula { 11 | struct AuthResponse; 12 | struct ExecutionResponse; 13 | struct Pair; 14 | struct PlanDescription; 15 | struct PlanNodeBranchInfo; 16 | struct PlanNodeDescription; 17 | struct ProfilingStats; 18 | struct VerifyClientVersionReq; 19 | struct VerifyClientVersionResp; 20 | } // namespace nebula 21 | 22 | namespace apache::thrift { 23 | 24 | SPECIALIZE_CPP2OPS(nebula::AuthResponse); 25 | SPECIALIZE_CPP2OPS(nebula::ExecutionResponse); 26 | SPECIALIZE_CPP2OPS(nebula::Pair); 27 | SPECIALIZE_CPP2OPS(nebula::PlanDescription); 28 | SPECIALIZE_CPP2OPS(nebula::PlanNodeBranchInfo); 29 | SPECIALIZE_CPP2OPS(nebula::PlanNodeDescription); 30 | SPECIALIZE_CPP2OPS(nebula::ProfilingStats); 31 | SPECIALIZE_CPP2OPS(nebula::VerifyClientVersionReq); 32 | SPECIALIZE_CPP2OPS(nebula::VerifyClientVersionResp); 33 | 34 | } // namespace apache::thrift 35 | -------------------------------------------------------------------------------- /include/common/thrift/ThriftCpp2OpsHelper.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #ifndef COMMON_THRIFT_THRIFTCPP2OPS_HELPER_H_ 7 | #define COMMON_THRIFT_THRIFTCPP2OPS_HELPER_H_ 8 | #include 9 | 10 | #define SPECIALIZE_CPP2OPS(X) \ 11 | template <> \ 12 | class Cpp2Ops { \ 13 | public: \ 14 | using Type = X; \ 15 | inline static constexpr protocol::TType thriftType(); \ 16 | template \ 17 | static uint32_t write(Protocol *proto, const Type *obj); \ 18 | template \ 19 | static void read(Protocol *proto, Type *obj); \ 20 | template \ 21 | static uint32_t serializedSize(const Protocol *proto, const Type *obj); \ 22 | template \ 23 | static uint32_t serializedSizeZC(const Protocol *proto, const Type *obj); \ 24 | } 25 | 26 | #endif // COMMON_THRIFT_THRIFTCPP2OPS_HELPER_H_ 27 | -------------------------------------------------------------------------------- /include/common/thrift/ThriftTypes.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | // Raft related types 13 | using ClusterID = int64_t; 14 | using GraphSpaceID = int32_t; 15 | using PartitionID = int32_t; 16 | using TermID = int64_t; 17 | using LogID = int64_t; 18 | using Port = int32_t; 19 | 20 | // Starting from 2.0, both string and int64 vertex ids will be supported. 21 | // 22 | // The string id must be fixed-length (the length of the id will be specified 23 | // as a Graph Space property). So the int64 id will be treated as 8-byte string 24 | // 25 | // If the length of a given id is shorter than the specified length, '\0' will 26 | // be appended to the end 27 | using VertexID = std::string; 28 | using TagID = int32_t; 29 | using TagVersion = int64_t; 30 | using EdgeType = int32_t; 31 | using EdgeRanking = int64_t; 32 | using EdgeVersion = int64_t; 33 | using EdgeVerPlaceHolder = char; 34 | using SchemaVer = int64_t; 35 | using IndexID = int32_t; 36 | using Timestamp = int64_t; 37 | 38 | using JobID = int32_t; 39 | using TaskID = int32_t; 40 | using BalanceID = int64_t; 41 | 42 | using GroupID = int32_t; 43 | using ZoneID = int32_t; 44 | 45 | using SessionID = int64_t; 46 | 47 | using ExecutionPlanID = int64_t; 48 | } // namespace nebula 49 | -------------------------------------------------------------------------------- /include/common/time/Constants.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace nebula { 9 | namespace time { 10 | 11 | static constexpr int kDayOfLeapYear = 366; 12 | static constexpr int kDayOfCommonYear = 365; 13 | 14 | static constexpr int64_t kSecondsOfMinute = 60; 15 | static constexpr int64_t kSecondsOfHour = 60 * kSecondsOfMinute; 16 | static constexpr int64_t kSecondsOfDay = 24 * kSecondsOfHour; 17 | 18 | } // namespace time 19 | } // namespace nebula 20 | -------------------------------------------------------------------------------- /include/common/utils/utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #ifndef MAYBE_UNUSED 9 | #if (__cplusplus >= 201703L) // c++17 10 | #include 11 | #define MAYBE_UNUSED FOLLY_MAYBE_UNUSED 12 | #else 13 | #define MAYBE_UNUSED __attribute__((unused)) 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /include/nebula/client/Config.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | 13 | struct Config { 14 | std::uint32_t timeout_{0}; // in ms 15 | std::uint32_t idleTime_{0}; // in ms 16 | std::uint32_t maxConnectionPoolSize_{10}; 17 | std::uint32_t minConnectionPoolSize_{0}; 18 | // Whether to enable SSL encryption 19 | bool enableSSL_{false}; 20 | // Whether to enable mTLS 21 | bool enableMTLS_{false}; 22 | // Whether to check peer CN or SAN 23 | bool checkPeerName_{false}; 24 | std::string peerName_; 25 | // Path to cert of CA 26 | std::string CAPath_; 27 | // Path to cert of client 28 | std::string certPath_; 29 | // path to private key of client 30 | std::string keyPath_; 31 | }; 32 | 33 | } // namespace nebula 34 | -------------------------------------------------------------------------------- /include/nebula/client/Connection.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common/datatypes/Value.h" 13 | #include "common/graph/Response.h" 14 | #include "nebula/client/Config.h" 15 | 16 | namespace folly { 17 | class ScopedEventBaseThread; 18 | } 19 | 20 | namespace nebula { 21 | 22 | // Wrap the thrift client. 23 | namespace graph { 24 | namespace cpp2 { 25 | class GraphServiceAsyncClient; 26 | } 27 | } // namespace graph 28 | 29 | class Connection { 30 | public: 31 | using ExecuteCallback = std::function; 32 | using ExecuteJsonCallback = std::function; 33 | 34 | Connection(); 35 | // disable copy 36 | Connection(const Connection &) = delete; 37 | Connection &operator=(const Connection &c) = delete; 38 | 39 | Connection(Connection &&c) noexcept { 40 | client_ = c.client_; 41 | c.client_ = nullptr; 42 | 43 | clientLoopThread_ = c.clientLoopThread_; 44 | c.clientLoopThread_ = nullptr; 45 | } 46 | 47 | Connection &operator=(Connection &&c); 48 | 49 | ~Connection(); 50 | 51 | bool open(const std::string &address, 52 | int32_t port, 53 | uint32_t timeout, 54 | const Config &cfg = Config{}); 55 | 56 | AuthResponse authenticate(const std::string &user, const std::string &password); 57 | 58 | ExecutionResponse execute(int64_t sessionId, const std::string &stmt); 59 | 60 | void asyncExecute(int64_t sessionId, const std::string &stmt, ExecuteCallback cb); 61 | 62 | ExecutionResponse executeWithParameter(int64_t sessionId, 63 | const std::string &stmt, 64 | const std::unordered_map ¶meters); 65 | 66 | void asyncExecuteWithParameter(int64_t sessionId, 67 | const std::string &stmt, 68 | const std::unordered_map ¶meters, 69 | ExecuteCallback cb); 70 | 71 | std::string executeJson(int64_t sessionId, const std::string &stmt); 72 | 73 | void asyncExecuteJson(int64_t sessionId, const std::string &stmt, ExecuteJsonCallback cb); 74 | 75 | std::string executeJsonWithParameter(int64_t sessionId, 76 | const std::string &stmt, 77 | const std::unordered_map ¶meters); 78 | 79 | void asyncExecuteJsonWithParameter(int64_t sessionId, 80 | const std::string &stmt, 81 | const std::unordered_map ¶meters, 82 | ExecuteJsonCallback cb); 83 | 84 | VerifyClientVersionResp verifyClientVersion(const VerifyClientVersionReq &req); 85 | 86 | bool isOpen(); 87 | 88 | void close(); 89 | 90 | bool ping(); 91 | 92 | void signout(int64_t sessionId); 93 | 94 | private: 95 | graph::cpp2::GraphServiceAsyncClient *client_{nullptr}; 96 | folly::ScopedEventBaseThread *clientLoopThread_{nullptr}; 97 | }; 98 | 99 | } // namespace nebula 100 | -------------------------------------------------------------------------------- /include/nebula/client/ConnectionPool.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "nebula/client/Config.h" 14 | #include "nebula/client/Connection.h" 15 | #include "nebula/client/Session.h" 16 | 17 | namespace nebula { 18 | 19 | class ConnectionPool { 20 | public: 21 | ~ConnectionPool(); 22 | 23 | void init(const std::vector &addresses, const Config &config); 24 | 25 | void close(); 26 | 27 | Session getSession(const std::string &username, 28 | const std::string &password, 29 | bool retryConnect = true); 30 | 31 | Connection getConnection(); 32 | 33 | void giveBack(Connection &&conn); 34 | 35 | std::size_t size() const { 36 | std::lock_guard l(lock_); 37 | return conns_.size(); 38 | } 39 | 40 | private: 41 | // The count may can't perform if can't create enough valid connection 42 | void newConnection(std::size_t cursor, std::size_t count); 43 | 44 | std::size_t nextCursor() { 45 | return cursor_ >= address_.size() ? cursor_ = 0 : cursor_++; 46 | } 47 | 48 | std::size_t cursor_{0}; 49 | // host, port 50 | std::vector> address_; 51 | Config config_; 52 | 53 | mutable std::mutex lock_; 54 | std::list conns_; 55 | }; 56 | 57 | } // namespace nebula 58 | -------------------------------------------------------------------------------- /include/nebula/client/SessionPool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 vesoft inc. All rights reserved. 2 | // 3 | // This source code is licensed under Apache 2.0 License. 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "nebula/client/Config.h" 14 | #include "nebula/client/ConnectionPool.h" 15 | #include "nebula/client/Session.h" 16 | 17 | namespace nebula { 18 | 19 | struct SessionPoolConfig { 20 | std::string username_; 21 | std::string password_; 22 | std::vector addrs_; // the list of graph addresses 23 | std::string spaceName_; 24 | // Socket timeout and Socket connection timeout, unit: milliseconds 25 | std::uint32_t timeout_{0}; 26 | // The idleTime of the connection, unit: milliseconds 27 | // If connection's idle time is longer than idleTime, it will be delete 28 | // 0 value means the connection will not expire 29 | std::uint32_t idleTime_{0}; 30 | std::uint32_t maxSize_{10}; // max size of the session pool. should be adjusted according to the 31 | // max threads will be using. 32 | std::uint32_t minSize_{1}; // min size of the session pool 33 | }; 34 | 35 | class SessionPool { 36 | public: 37 | SessionPool() = delete; 38 | explicit SessionPool(SessionPoolConfig config) 39 | : config_(std::move(config)), pool_(new ConnectionPool()) {} 40 | SessionPool(const SessionPool &) = delete; // no copy 41 | SessionPool(SessionPool &&pool) 42 | : config_(std::move(pool.config_)), pool_(std::move(pool.pool_)) {} 43 | 44 | // initialize session and context 45 | // return false when failed, otherwise return true 46 | // When return false, the pool is in invalid state, user must destruct it 47 | // instead of continue. 48 | bool init(); 49 | 50 | // Session pool use fixed space, don't switch space when execute 51 | ExecutionResponse execute(const std::string &stmt); 52 | 53 | ExecutionResponse executeWithParameter(const std::string &stmt, 54 | const std::unordered_map ¶meters); 55 | 56 | std::string executeJson(const std::string &stmt); 57 | 58 | std::string executeJsonWithParameter(const std::string &stmt, 59 | const std::unordered_map ¶meters); 60 | 61 | private: 62 | std::pair getIdleSession() { 63 | std::lock_guard l(m_); 64 | if (idleSessions_.empty()) { 65 | return std::make_pair(Session(), false); 66 | } 67 | auto session = std::move(idleSessions_.front()); 68 | idleSessions_.pop_front(); 69 | return std::make_pair(std::move(session), true); 70 | } 71 | 72 | void giveBack(Session &&session) { 73 | std::lock_guard l(m_); 74 | idleSessions_.emplace_back(std::move(session)); 75 | } 76 | 77 | SessionPoolConfig config_; 78 | std::unique_ptr pool_; 79 | // destruct session before pool 80 | std::mutex m_; 81 | std::list idleSessions_; 82 | }; 83 | 84 | } // namespace nebula 85 | -------------------------------------------------------------------------------- /include/nebula/common/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesoft-inc/nebula-cpp/ae3d38229441ebc278bdf6c32c555188d4c7bceb/include/nebula/common/.gitkeep -------------------------------------------------------------------------------- /include/nebula/graph/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesoft-inc/nebula-cpp/ae3d38229441ebc278bdf6c32c555188d4c7bceb/include/nebula/graph/.gitkeep -------------------------------------------------------------------------------- /include/nebula/mclient/MConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | 13 | struct MConfig { 14 | // It's as same as FLAGS_conn_timeout_ms in nebula 15 | int32_t connTimeoutInMs_{1000}; 16 | // It's as same as FLAG_meta_client_timeout_ms in nebula 17 | int32_t clientTimeoutInMs_{60 * 1000}; 18 | // Whether to enable SSL encryption 19 | bool enableSSL_{false}; 20 | // Whether to enable mTLS 21 | bool enableMTLS_{false}; 22 | // Whether to check peer CN or SAN 23 | bool checkPeerName_{false}; 24 | std::string peerName_; 25 | // Path to cert of CA 26 | std::string CAPath_; 27 | // Path to cert of client 28 | std::string certPath_; 29 | // path to private key of client 30 | std::string keyPath_; 31 | }; 32 | 33 | } // namespace nebula 34 | -------------------------------------------------------------------------------- /include/nebula/sclient/SConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | 13 | struct SConfig { 14 | // It's as same as FLAGS_conn_timeout_ms in nebula 15 | int32_t connTimeoutInMs_{1000}; 16 | // It's as same as FLAG_meta_client_timeout_ms in nebula 17 | int32_t clientTimeoutInMs_{60 * 1000}; 18 | // Whether to enable SSL encryption 19 | bool enableSSL_{false}; 20 | // Whether to enable mTLS 21 | bool enableMTLS_{false}; 22 | // Whether to check peer CN or SAN 23 | bool checkPeerName_{false}; 24 | std::string peerName_; 25 | // Path to cert of CA 26 | std::string CAPath_; 27 | // Path to cert of client 28 | std::string certPath_; 29 | // path to private key of client 30 | std::string keyPath_; 31 | }; 32 | 33 | } // namespace nebula 34 | -------------------------------------------------------------------------------- /include/nebula/sclient/ScanEdgeIter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "common/datatypes/DataSet.h" 12 | #include "common/graph/Response.h" 13 | 14 | namespace nebula { 15 | class StorageClient; 16 | 17 | namespace storage { 18 | namespace cpp2 { 19 | class ScanEdgeRequest; 20 | } // namespace cpp2 21 | } // namespace storage 22 | 23 | struct ScanEdgeIter { 24 | ScanEdgeIter(StorageClient* client, storage::cpp2::ScanEdgeRequest* req, bool hasNext = true); 25 | 26 | ~ScanEdgeIter(); 27 | 28 | bool hasNext(); 29 | 30 | std::pair<::nebula::ErrorCode, DataSet> next(); 31 | 32 | StorageClient* client_; 33 | storage::cpp2::ScanEdgeRequest* req_; 34 | bool hasNext_; 35 | std::string nextCursor_; 36 | }; 37 | 38 | } // namespace nebula 39 | -------------------------------------------------------------------------------- /include/nebula/sclient/ScanVertexIter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "common/datatypes/DataSet.h" 12 | #include "common/graph/Response.h" 13 | 14 | namespace nebula { 15 | class StorageClient; 16 | 17 | namespace storage { 18 | namespace cpp2 { 19 | class ScanVertexRequest; 20 | } // namespace cpp2 21 | } // namespace storage 22 | 23 | struct ScanVertexIter { 24 | ScanVertexIter(StorageClient* client, storage::cpp2::ScanVertexRequest* req, bool hasNext = true); 25 | 26 | ~ScanVertexIter(); 27 | 28 | bool hasNext(); 29 | 30 | std::pair<::nebula::ErrorCode, DataSet> next(); 31 | 32 | StorageClient* client_; 33 | storage::cpp2::ScanVertexRequest* req_; 34 | bool hasNext_; 35 | std::string nextCursor_; 36 | }; 37 | 38 | } // namespace nebula 39 | -------------------------------------------------------------------------------- /include/nebula/storage/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesoft-inc/nebula-cpp/ae3d38229441ebc278bdf6c32c555188d4c7bceb/include/nebula/storage/.gitkeep -------------------------------------------------------------------------------- /package/postinst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesoft-inc/nebula-cpp/ae3d38229441ebc278bdf6c32c555188d4c7bceb/package/postinst -------------------------------------------------------------------------------- /package/rpm_postinst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesoft-inc/nebula-cpp/ae3d38229441ebc278bdf6c32c555188d4c7bceb/package/rpm_postinst -------------------------------------------------------------------------------- /src/Init.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | 8 | namespace nebula { 9 | 10 | void init(int *argc, char **argv[]) { folly::init(argc, argv, true); } 11 | 12 | } // namespace nebula 13 | -------------------------------------------------------------------------------- /src/SSLConfig.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "./SSLConfig.h" 7 | 8 | #include 9 | 10 | namespace nebula { 11 | 12 | std::shared_ptr createSSLContext(const SSLConfig &cfg) { 13 | if (cfg.check_peer_name && cfg.peer_name.empty()) { 14 | throw std::runtime_error("peer name checking enabled but not provied"); 15 | } 16 | 17 | if (cfg.enable_mtls && (cfg.cert_path.empty() || cfg.key_path.empty())) { 18 | throw std::runtime_error("mTLS enabled but cert/key not provided"); 19 | } 20 | 21 | auto context = std::make_shared(); 22 | 23 | if (!cfg.ca_path.empty()) { 24 | context->loadTrustedCertificates(cfg.ca_path.c_str()); 25 | if (cfg.check_peer_name) { 26 | context->authenticate(true, true, cfg.peer_name); 27 | } else { 28 | context->authenticate(true, false); 29 | } 30 | context->setVerificationOption(folly::SSLContext::SSLVerifyPeerEnum::VERIFY); 31 | } 32 | 33 | if (cfg.enable_mtls) { 34 | context->loadCertKeyPairFromFiles(cfg.cert_path.c_str(), cfg.key_path.c_str()); 35 | } 36 | 37 | folly::ssl::setSignatureAlgorithms(*context); 38 | 39 | return context; 40 | } 41 | 42 | } // namespace nebula 43 | -------------------------------------------------------------------------------- /src/SSLConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace nebula { 11 | 12 | struct SSLConfig final { 13 | // Whether to enable mTLS(mutual TLS authentication) 14 | bool enable_mtls{false}; 15 | // Check whether the given peername matches the CN or SAN in the certificate 16 | bool check_peer_name{false}; 17 | std::string peer_name; 18 | // Path to certificate(s) of the CA used to authenticate the cert of server 19 | std::string ca_path; 20 | // Path to the client cert, must be present if mTLS enabled 21 | std::string cert_path; 22 | // Path to the client private key, must be present if mTLS enabled 23 | std::string key_path; 24 | }; 25 | 26 | std::shared_ptr createSSLContext(const SSLConfig &cfg); 27 | 28 | } // namespace nebula 29 | -------------------------------------------------------------------------------- /src/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | 5 | nebula_add_subdirectory(tests) 6 | -------------------------------------------------------------------------------- /src/client/ConnectionPool.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "nebula/client/ConnectionPool.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | 14 | ConnectionPool::~ConnectionPool() { 15 | close(); 16 | } 17 | 18 | void ConnectionPool::init(const std::vector &addresses, const Config &config) { 19 | for (const auto &addr : addresses) { 20 | std::vector splits; 21 | folly::split(':', addr, splits, true); 22 | if (splits.size() != 2) { 23 | // ignore error 24 | continue; 25 | } 26 | address_.emplace_back(std::make_pair(splits[0], folly::to(splits[1]))); 27 | } 28 | if (address_.empty()) { 29 | // no valid address 30 | return; 31 | } 32 | config_ = config; 33 | newConnection(0, config.maxConnectionPoolSize_); 34 | } 35 | 36 | void ConnectionPool::close() { 37 | std::lock_guard l(lock_); 38 | for (auto &conn : conns_) { 39 | conn.close(); 40 | } 41 | } 42 | 43 | Session ConnectionPool::getSession(const std::string &username, 44 | const std::string &password, 45 | bool retryConnect) { 46 | Connection conn = getConnection(); 47 | auto resp = conn.authenticate(username, password); 48 | if (resp.errorCode != ErrorCode::SUCCEEDED || resp.sessionId == nullptr) { 49 | return Session(); 50 | } 51 | return Session(*resp.sessionId, 52 | std::move(conn), 53 | this, 54 | username, 55 | password, 56 | *resp.timeZoneName, 57 | *resp.timeZoneOffsetSeconds, 58 | retryConnect); 59 | } 60 | 61 | Connection ConnectionPool::getConnection() { 62 | std::lock_guard l(lock_); 63 | // check connection 64 | for (auto c = conns_.begin(); c != conns_.end();) { 65 | if (!c->isOpen()) { 66 | c = conns_.erase(c); 67 | newConnection(nextCursor(), 1); 68 | } else { 69 | c++; 70 | } 71 | } 72 | if (conns_.empty()) { 73 | return Connection(); 74 | } 75 | Connection conn = std::move(conns_.front()); 76 | conns_.pop_front(); 77 | return conn; 78 | } 79 | 80 | void ConnectionPool::giveBack(Connection &&conn) { 81 | std::lock_guard l(lock_); 82 | conns_.emplace_back(std::move(conn)); 83 | } 84 | 85 | void ConnectionPool::newConnection(std::size_t cursor, std::size_t count) { 86 | for (std::size_t connectionCount = 0, addrCursor = cursor, loopCount = 0; connectionCount < count; 87 | ++addrCursor, ++loopCount) { 88 | if (loopCount > count * address_.size()) { 89 | // Can't get so many connections, return to avoid dead loop 90 | return; 91 | } 92 | if (addrCursor >= address_.size()) { 93 | addrCursor = 0; 94 | } 95 | Connection conn; 96 | if (conn.open(address_[addrCursor].first, 97 | address_[addrCursor].second, 98 | config_.timeout_, 99 | config_)) { 100 | ++connectionCount; 101 | conns_.emplace_back(std::move(conn)); 102 | } 103 | // ignore error 104 | } 105 | } 106 | 107 | } // namespace nebula 108 | -------------------------------------------------------------------------------- /src/client/tests/AddressTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "./ClientTest.h" 14 | 15 | // Require a nebula server could access 16 | 17 | #define kServerHost "graphd" 18 | 19 | class AddressTest : public ClientTest {}; 20 | 21 | TEST_F(AddressTest, One) { 22 | nebula::ConnectionPool pool; 23 | pool.init({kServerHost ":9669"}, nebula::Config{}); 24 | EXPECT_EQ(pool.size(), 10); 25 | } 26 | 27 | TEST_F(AddressTest, Multiple) { 28 | nebula::ConnectionPool pool; 29 | pool.init({"graphd:9669", "graphd1:9669", "graphd2:9669"}, nebula::Config{}); 30 | EXPECT_EQ(pool.size(), 10); 31 | } 32 | 33 | int main(int argc, char** argv) { 34 | testing::InitGoogleTest(&argc, argv); 35 | nebula::init(&argc, &argv); 36 | google::SetStderrLogging(google::INFO); 37 | 38 | return RUN_ALL_TESTS(); 39 | } 40 | -------------------------------------------------------------------------------- /src/client/tests/ClientTest.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/DataSet.h" 11 | #include "common/graph/Response.h" 12 | class ClientTest : public ::testing::Test { 13 | protected: 14 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::DataSet& resp, 15 | const nebula::DataSet& expect) { 16 | nebula::DataSet respCopy = resp; 17 | nebula::DataSet expectCopy = expect; 18 | std::sort(respCopy.rows.begin(), respCopy.rows.end()); 19 | std::sort(expectCopy.rows.begin(), expectCopy.rows.end()); 20 | if (respCopy != expectCopy) { 21 | return ::testing::AssertionFailure() << "Resp is : " << resp << std::endl 22 | << "Expect : " << expect; 23 | } 24 | return ::testing::AssertionSuccess(); 25 | } 26 | 27 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::ExecutionResponse& resp, 28 | const nebula::DataSet& expect) { 29 | auto result = succeeded(resp); 30 | if (!result) { 31 | return result; 32 | } 33 | const auto& data = *resp.data; 34 | return verifyResultWithoutOrder(data, expect); 35 | } 36 | 37 | static ::testing::AssertionResult succeeded(const nebula::ExecutionResponse& resp) { 38 | if (resp.errorCode != nebula::ErrorCode::SUCCEEDED) { 39 | return ::testing::AssertionFailure() 40 | << "Execution Failed with error: " << resp.errorCode << "," << *resp.errorMsg; 41 | } 42 | return ::testing::AssertionSuccess(); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/client/tests/ConnectionSSLTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "./ClientTest.h" 14 | 15 | // Require a nebula server could access 16 | 17 | static constexpr char kServerHost[] = "graphd"; 18 | 19 | class ConnectionTest : public ClientTest {}; 20 | 21 | TEST_F(ConnectionTest, SSL) { 22 | nebula::Connection c; 23 | nebula::Config cfg; 24 | cfg.enableSSL_ = true; 25 | 26 | ASSERT_TRUE(c.open(kServerHost, 9669, 10, cfg)); 27 | 28 | // auth 29 | auto authResp = c.authenticate("root", "nebula"); 30 | ASSERT_EQ(authResp.errorCode, nebula::ErrorCode::SUCCEEDED) << *authResp.errorMsg; 31 | 32 | // execute 33 | auto resp = c.execute(*authResp.sessionId, "YIELD 1"); 34 | ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED); 35 | nebula::DataSet expected({"1"}); 36 | expected.emplace_back(nebula::List({1})); 37 | EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expected)); 38 | } 39 | 40 | TEST_F(ConnectionTest, SSCA) { 41 | { 42 | nebula::Connection c; 43 | nebula::Config cfg; 44 | cfg.enableSSL_ = true; 45 | cfg.CAPath_ = "./test.ca.pem"; 46 | ASSERT_TRUE(c.open(kServerHost, 9669, 10, cfg)); 47 | 48 | // auth 49 | auto authResp = c.authenticate("root", "nebula"); 50 | ASSERT_EQ(authResp.errorCode, nebula::ErrorCode::SUCCEEDED) << *authResp.errorMsg; 51 | 52 | // execute 53 | auto resp = c.execute(*authResp.sessionId, "YIELD 1"); 54 | ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED); 55 | nebula::DataSet expected({"1"}); 56 | expected.emplace_back(nebula::List({1})); 57 | EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expected)); 58 | } 59 | 60 | { 61 | // mismatch 62 | nebula::Connection c; 63 | nebula::Config cfg; 64 | cfg.enableSSL_ = true; 65 | cfg.CAPath_ = "./test.2.crt"; 66 | ASSERT_FALSE(c.open(kServerHost, 9669, 10, cfg)); 67 | } 68 | } 69 | 70 | int main(int argc, char **argv) { 71 | testing::InitGoogleTest(&argc, argv); 72 | nebula::init(&argc, &argv); 73 | google::SetStderrLogging(google::INFO); 74 | 75 | return RUN_ALL_TESTS(); 76 | } 77 | -------------------------------------------------------------------------------- /src/client/tests/RegistHost.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | // Require a nebula server could access 18 | 19 | DEFINE_string(host, "", "Register host address."); 20 | DEFINE_string(server, "127.0.0.1:9669", "Nebula server address."); 21 | DEFINE_bool(enable_ssl, false, "Enable SSL."); 22 | 23 | int main(int argc, char** argv) { 24 | nebula::init(&argc, &argv); 25 | google::SetStderrLogging(google::INFO); 26 | 27 | nebula::ConnectionPool pool; 28 | nebula::Config c{10, 0, 300, 0, FLAGS_enable_ssl, false, false, "", "", "", ""}; 29 | pool.init({FLAGS_server}, c); 30 | auto session = pool.getSession("root", "nebula"); 31 | CHECK(session.valid()); 32 | 33 | auto resp = session.execute(folly::format("ADD HOSTS {}", FLAGS_host).str()); 34 | CHECK_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED) << *resp.errorMsg; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/client/tests/SessionSSLTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "./ClientTest.h" 22 | 23 | // Require a nebula server could access 24 | 25 | #define kServerHost "graphd" 26 | 27 | class SessionTest : public ClientTest {}; 28 | 29 | TEST_F(SessionTest, SSL) { 30 | nebula::ConnectionPool pool; 31 | nebula::Config c{10, 0, 10, 0, true, false, false, "", "", "", ""}; 32 | pool.init({kServerHost ":9669"}, c); 33 | auto session = pool.getSession("root", "nebula"); 34 | ASSERT_TRUE(session.valid()); 35 | 36 | // execute 37 | auto result = session.execute("YIELD 1"); 38 | ASSERT_EQ(result.errorCode, nebula::ErrorCode::SUCCEEDED); 39 | nebula::DataSet expected({"1"}); 40 | expected.emplace_back(nebula::List({1})); 41 | EXPECT_TRUE(verifyResultWithoutOrder(*result.data, expected)); 42 | } 43 | 44 | int main(int argc, char** argv) { 45 | testing::InitGoogleTest(&argc, argv); 46 | nebula::init(&argc, &argv); 47 | google::SetStderrLogging(google::INFO); 48 | 49 | return RUN_ALL_TESTS(); 50 | } 51 | -------------------------------------------------------------------------------- /src/client/tests/TimezoneConversionTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "./ClientTest.h" 19 | 20 | // Require a nebula server could access 21 | 22 | #define kServerHost "graphd" 23 | 24 | class SessionTest : public ClientTest {}; 25 | 26 | TEST_F(SessionTest, Basic) { 27 | nebula::ConnectionPool pool; 28 | pool.init({kServerHost ":9669"}, nebula::Config{}); 29 | auto session = pool.getSession("root", "nebula"); 30 | ASSERT_TRUE(session.valid()); 31 | { 32 | auto resp = session.execute( 33 | "YIELD datetime(\"2019-03-22T22:04:30\") as dt," 34 | "date(\"2019-03-22\") as d, " 35 | "time(\"22:04:30\") as t"); 36 | nebula::DataSet data({"dt", "d", "t"}); 37 | data.emplace_back(nebula::Row({nebula::DateTime(2019, 3, 22, 22, 4, 30, 0), 38 | nebula::Date(2019, 3, 22), 39 | nebula::Time(22, 4, 30, 0)})); 40 | EXPECT_TRUE(verifyResultWithoutOrder(resp, data)); 41 | 42 | // conversion 43 | session.toLocal(*resp.data); 44 | EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, data)); 45 | } 46 | { 47 | auto resp = session.execute( 48 | "YIELD datetime(\"2019-03-22T22:04:30\") as dt," 49 | "date(\"2019-03-22\") as d, " 50 | "time(\"22:04:30\") as t"); 51 | nebula::DataSet data({"dt", "d", "t"}); 52 | data.emplace_back(nebula::Row({nebula::DateTime(2019, 3, 22, 22, 4, 30, 0), 53 | nebula::Date(2019, 3, 22), 54 | nebula::Time(22, 4, 30, 0)})); 55 | EXPECT_TRUE(verifyResultWithoutOrder(resp, data)); 56 | 57 | // conversion 58 | session.toLocal(*resp.data, 30); 59 | nebula::DataSet expectLocal({"dt", "d", "t"}); 60 | expectLocal.emplace_back(nebula::Row({nebula::DateTime(2019, 3, 22, 22, 5, 0, 0), 61 | nebula::Date(2019, 3, 22), 62 | nebula::Time(22, 5, 0, 0)})); 63 | EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expectLocal)); 64 | } 65 | } 66 | 67 | int main(int argc, char** argv) { 68 | testing::InitGoogleTest(&argc, argv); 69 | nebula::init(&argc, &argv); 70 | google::SetStderrLogging(google::INFO); 71 | 72 | return RUN_ALL_TESTS(); 73 | } 74 | -------------------------------------------------------------------------------- /src/datatypes/Duration.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/Duration.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace nebula { 15 | 16 | std::string Duration::toString() const { 17 | return folly::format( 18 | "P{}MT{}.{:0>6}000S", months, seconds + microseconds / 1000000, microseconds % 1000000) 19 | .str(); 20 | } 21 | 22 | } // namespace nebula 23 | 24 | namespace std { 25 | 26 | // Inject a customized hash function 27 | std::size_t hash::operator()(const nebula::Duration& d) const noexcept { 28 | size_t hv = folly::hash::fnv64_buf(reinterpret_cast(&d.months), sizeof(d.months)); 29 | hv = folly::hash::fnv64_buf(reinterpret_cast(d.seconds), sizeof(d.seconds), hv); 30 | return folly::hash::fnv64_buf( 31 | reinterpret_cast(d.microseconds), sizeof(d.microseconds), hv); 32 | } 33 | 34 | } // namespace std 35 | -------------------------------------------------------------------------------- /src/datatypes/Edge.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | 14 | std::string Edge::toString() const { 15 | std::stringstream os; 16 | os << "(" << src << ")" 17 | << "-" 18 | << "[" << name << "(" << type << ")]" 19 | << "->" 20 | << "(" << dst << ")" 21 | << "@" << ranking; 22 | if (!props.empty()) { 23 | std::vector value(props.size()); 24 | std::transform(props.begin(), props.end(), value.begin(), [](const auto& iter) -> std::string { 25 | std::stringstream out; 26 | out << iter.first << ":" << iter.second; 27 | return out.str(); 28 | }); 29 | os << " " << folly::join(",", value); 30 | } 31 | return os.str(); 32 | } 33 | 34 | bool Edge::contains(const Value& key) const { 35 | if (!key.isStr()) { 36 | return false; 37 | } 38 | return props.find(key.getStr()) != props.end(); 39 | } 40 | 41 | const Value& Edge::value(const std::string& key) const { 42 | auto find = props.find(key); 43 | if (find != props.end()) { 44 | return find->second; 45 | } else { 46 | return Value::kNullValue; 47 | } 48 | } 49 | 50 | bool Edge::operator<(const Edge& rhs) const { 51 | if (src != rhs.src) { 52 | return src < rhs.src; 53 | } 54 | if (dst != rhs.dst) { 55 | return dst < rhs.dst; 56 | } 57 | if (type != rhs.type) { 58 | return type < rhs.type; 59 | } 60 | if (ranking != rhs.ranking) { 61 | return ranking < rhs.ranking; 62 | } 63 | if (props.size() != rhs.props.size()) { 64 | return props.size() < rhs.props.size(); 65 | } 66 | return false; 67 | } 68 | 69 | bool Edge::operator==(const Edge& rhs) const { 70 | if (type != rhs.type && type != -rhs.type) { 71 | return false; 72 | } 73 | if (type == rhs.type) { 74 | return src == rhs.src && dst == rhs.dst && ranking == rhs.ranking && props == rhs.props; 75 | } 76 | return src == rhs.dst && dst == rhs.src && ranking == rhs.ranking && props == rhs.props; 77 | } 78 | 79 | void Edge::reverse() { 80 | type = -type; 81 | auto tmp = std::move(src); 82 | src = std::move(dst); 83 | dst = std::move(tmp); 84 | } 85 | 86 | void Edge::clear() { 87 | src.clear(); 88 | dst.clear(); 89 | type = 0; 90 | name.clear(); 91 | ranking = 0; 92 | props.clear(); 93 | } 94 | 95 | } // namespace nebula 96 | 97 | namespace std { 98 | 99 | // Inject a customized hash function 100 | std::size_t hash::operator()(const nebula::Edge& h) const noexcept { 101 | const auto& src = h.type > 0 ? h.src.toString() : h.dst.toString(); 102 | const auto& dst = h.type > 0 ? h.dst.toString() : h.src.toString(); 103 | auto type = h.type > 0 ? h.type : -h.type; 104 | size_t hv = folly::hash::fnv64(src); 105 | hv = folly::hash::fnv64(dst, hv); 106 | hv = folly::hash::fnv64_buf(reinterpret_cast(&type), sizeof(type), hv); 107 | return folly::hash::fnv64_buf(reinterpret_cast(&h.ranking), sizeof(h.ranking), hv); 108 | } 109 | 110 | } // namespace std 111 | -------------------------------------------------------------------------------- /src/datatypes/HostAddr.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/HostAddr.h" 7 | 8 | #include 9 | 10 | namespace nebula { 11 | 12 | bool HostAddr::operator==(const HostAddr& rhs) const { 13 | return host == rhs.host && port == rhs.port; 14 | } 15 | 16 | bool HostAddr::operator!=(const HostAddr& rhs) const { 17 | return !(*this == rhs); 18 | } 19 | 20 | bool HostAddr::operator<(const HostAddr& rhs) const { 21 | if (host == rhs.host) { 22 | return port < rhs.port; 23 | } 24 | return host < rhs.host; 25 | } 26 | 27 | } // namespace nebula 28 | 29 | namespace std { 30 | 31 | // Inject a customized hash function 32 | std::size_t hash::operator()(const nebula::HostAddr& h) const noexcept { 33 | int64_t code = folly::hash::fnv32_buf(h.host.data(), h.host.size()); 34 | code <<= 32; 35 | code |= folly::hash::fnv32_buf(&(h.port), sizeof(nebula::Port)); 36 | return code; 37 | } 38 | 39 | } // namespace std 40 | -------------------------------------------------------------------------------- /src/datatypes/List.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/List.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | 14 | std::string List::toString() const { 15 | std::vector value(values.size()); 16 | std::transform(values.begin(), values.end(), value.begin(), [](const auto& v) -> std::string { 17 | return v.toString(); 18 | }); 19 | std::stringstream os; 20 | os << "[" << folly::join(",", value) << "]"; 21 | return os.str(); 22 | } 23 | 24 | } // namespace nebula 25 | -------------------------------------------------------------------------------- /src/datatypes/Map.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/Map.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | 14 | std::string Map::toString() const { 15 | std::vector value(kvs.size()); 16 | std::transform(kvs.begin(), kvs.end(), value.begin(), [](const auto& iter) -> std::string { 17 | std::stringstream out; 18 | out << iter.first << ":" << iter.second; 19 | return out.str(); 20 | }); 21 | 22 | std::stringstream os; 23 | os << "{" << folly::join(",", value) << "}"; 24 | return os.str(); 25 | } 26 | 27 | } // namespace nebula 28 | 29 | namespace std { 30 | std::size_t hash::operator()(const nebula::Map& m) const noexcept { 31 | size_t seed = 0; 32 | for (auto& v : m.kvs) { 33 | seed ^= hash()(v.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 34 | } 35 | return seed; 36 | } 37 | 38 | } // namespace std 39 | -------------------------------------------------------------------------------- /src/datatypes/Path.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/Path.h" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace nebula { 16 | void Path::reverse() { 17 | if (steps.empty()) { 18 | return; 19 | } 20 | std::reverse(steps.begin(), steps.end()); 21 | swap(src, steps.front().dst); 22 | for (size_t i = 0; i < steps.size() - 1; ++i) { 23 | swap(steps[i].dst, steps[i + 1].dst); 24 | steps[i].type = -steps[i].type; 25 | } 26 | steps.back().type = -steps.back().type; 27 | } 28 | 29 | bool Path::append(Path path) { 30 | if (src != path.src && steps.back().dst != path.src) { 31 | return false; 32 | } 33 | steps.reserve(steps.size() + path.steps.size()); 34 | steps.insert(steps.end(), 35 | std::make_move_iterator(path.steps.begin()), 36 | std::make_move_iterator(path.steps.end())); 37 | return true; 38 | } 39 | 40 | bool Path::hasDuplicateVertices() const { 41 | if (steps.empty()) { 42 | return false; 43 | } 44 | std::unordered_set uniqueVid; 45 | uniqueVid.reserve(steps.size() + 1); 46 | uniqueVid.emplace(src.vid); 47 | for (const auto& step : steps) { 48 | auto ret = uniqueVid.emplace(step.dst.vid); 49 | if (!ret.second) { 50 | return true; 51 | } 52 | } 53 | return false; 54 | } 55 | 56 | bool Path::hasDuplicateEdges() const { 57 | if (steps.size() < 2) { 58 | return false; 59 | } 60 | using Key = std::tuple; 61 | std::unordered_set uniqueSet; 62 | uniqueSet.reserve(steps.size()); 63 | auto srcVid = src.vid; 64 | for (const auto& step : steps) { 65 | const auto& dstVid = step.dst.vid; 66 | bool ret = true; 67 | if (step.type > 0) { 68 | ret = uniqueSet.emplace(srcVid, dstVid, step.type, step.ranking).second; 69 | } else { 70 | ret = uniqueSet.emplace(dstVid, srcVid, -step.type, step.ranking).second; 71 | } 72 | if (!ret) { 73 | return true; 74 | } 75 | srcVid = dstVid; 76 | } 77 | return false; 78 | } 79 | 80 | } // namespace nebula 81 | 82 | namespace std { 83 | 84 | std::size_t hash::operator()(const nebula::Step& h) const noexcept { 85 | size_t hv = hash()(h.dst); 86 | hv = folly::hash::fnv64_buf(reinterpret_cast(&h.type), sizeof(h.type), hv); 87 | return folly::hash::fnv64_buf(reinterpret_cast(&h.ranking), sizeof(h.ranking), hv); 88 | } 89 | 90 | std::size_t hash::operator()(const nebula::Path& h) const noexcept { 91 | size_t hv = hash()(h.src); 92 | for (auto& s : h.steps) { 93 | hv += (hv << 1) + (hv << 4) + (hv << 5) + (hv << 7) + (hv << 8) + (hv << 40); 94 | hv ^= hash()(s); 95 | } 96 | 97 | return hv; 98 | } 99 | 100 | } // namespace std 101 | -------------------------------------------------------------------------------- /src/datatypes/Set.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/Set.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | 14 | std::string Set::toString() const { 15 | std::vector value(values.size()); 16 | std::transform(values.begin(), values.end(), value.begin(), [](const auto& v) -> std::string { 17 | return v.toString(); 18 | }); 19 | std::stringstream os; 20 | os << "{" << folly::join(",", value) << "}"; 21 | return os.str(); 22 | } 23 | 24 | } // namespace nebula 25 | 26 | namespace std { 27 | std::size_t hash::operator()(const nebula::Set& s) const noexcept { 28 | size_t seed = 0; 29 | for (auto& v : s.values) { 30 | seed ^= hash()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 31 | } 32 | return seed; 33 | } 34 | 35 | } // namespace std 36 | -------------------------------------------------------------------------------- /src/datatypes/Vertex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/datatypes/Vertex.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace nebula { 13 | 14 | std::string Tag::toString() const { 15 | std::vector value(props.size()); 16 | std::transform(props.begin(), props.end(), value.begin(), [](const auto& iter) -> std::string { 17 | std::stringstream out; 18 | out << iter.first << ":" << iter.second; 19 | return out.str(); 20 | }); 21 | 22 | std::stringstream os; 23 | os << "Tag: " << name << ", " << folly::join(",", value); 24 | return os.str(); 25 | } 26 | 27 | bool Vertex::contains(const Value& key) const { 28 | if (!key.isStr()) { 29 | return false; 30 | } 31 | auto& keyStr = key.getStr(); 32 | for (const auto& tag : tags) { 33 | if (tag.props.find(keyStr) != tag.props.end()) { 34 | return true; 35 | } 36 | } 37 | return false; 38 | } 39 | 40 | const Value& Vertex::value(const std::string& key) const { 41 | for (const auto& tag : tags) { 42 | auto find = tag.props.find(key); 43 | if (find != tag.props.end()) { 44 | return find->second; 45 | } 46 | } 47 | return Value::kNullValue; 48 | } 49 | 50 | std::string Vertex::toString() const { 51 | std::stringstream os; 52 | os << "(" << vid << ")"; 53 | if (!tags.empty()) { 54 | os << " "; 55 | for (const auto& tag : tags) { 56 | os << tag.toString(); 57 | } 58 | } 59 | return os.str(); 60 | } 61 | 62 | Vertex& Vertex::operator=(Vertex&& rhs) noexcept { 63 | if (&rhs != this) { 64 | vid = std::move(rhs.vid); 65 | tags = std::move(rhs.tags); 66 | } 67 | return *this; 68 | } 69 | 70 | Vertex& Vertex::operator=(const Vertex& rhs) { 71 | if (&rhs != this) { 72 | vid = rhs.vid; 73 | tags = rhs.tags; 74 | } 75 | return *this; 76 | } 77 | 78 | bool Vertex::operator<(const Vertex& rhs) const { 79 | if (vid != rhs.vid) { 80 | return vid < rhs.vid; 81 | } 82 | if (tags.size() != rhs.tags.size()) { 83 | return tags.size() < rhs.tags.size(); 84 | } 85 | return false; 86 | } 87 | 88 | } // namespace nebula 89 | 90 | namespace std { 91 | 92 | // Inject a customized hash function 93 | std::size_t hash::operator()(const nebula::Tag& h) const noexcept { 94 | return folly::hash::fnv64(h.name); 95 | } 96 | 97 | std::size_t hash::operator()(const nebula::Vertex& h) const noexcept { 98 | size_t hv = folly::hash::fnv64(h.vid.toString()); 99 | for (auto& t : h.tags) { 100 | hv += (hv << 1) + (hv << 4) + (hv << 5) + (hv << 7) + (hv << 8) + (hv << 40); 101 | hv ^= hash()(t); 102 | } 103 | 104 | return hv; 105 | } 106 | 107 | } // namespace std 108 | -------------------------------------------------------------------------------- /src/geo/io/wkb/ByteOrderDataIOStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/geo/io/wkb/ByteOrderDataIOStream.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace nebula { 13 | namespace geo { 14 | 15 | struct ByteOrderData { 16 | static ByteOrder getMachineByteOrder() { 17 | static int endianCheck = 1; 18 | return static_cast( 19 | *(reinterpret_cast(&endianCheck))); // 0 for BigEndian, 1 for LittleEndian 20 | } 21 | 22 | static void putUint32(uint8_t *buf, ByteOrder byteOrder, uint32_t v) { 23 | if (byteOrder == ByteOrder::BigEndian) { 24 | boost::endian::store_big_u32(buf, v); 25 | } else { 26 | DCHECK(byteOrder == ByteOrder::LittleEndian); 27 | boost::endian::store_little_u32(buf, v); 28 | } 29 | } 30 | 31 | static void putUint64(uint8_t *buf, ByteOrder byteOrder, uint64_t v) { 32 | if (byteOrder == ByteOrder::BigEndian) { 33 | boost::endian::store_big_u64(buf, v); 34 | } else { 35 | DCHECK(byteOrder == ByteOrder::LittleEndian); 36 | boost::endian::store_little_u64(buf, v); 37 | } 38 | } 39 | 40 | static void putDouble(uint8_t *buf, ByteOrder byteOrder, double v) { 41 | const char *c = reinterpret_cast(&v); 42 | uint64_t v2 = *reinterpret_cast(c); 43 | putUint64(buf, byteOrder, v2); 44 | } 45 | }; 46 | 47 | void ByteOrderDataOutStream::writeUint8(uint8_t v) { 48 | buf_[0] = v; 49 | stream_.write(reinterpret_cast(buf_), 1); 50 | } 51 | 52 | void ByteOrderDataOutStream::writeUint32(uint32_t v) { 53 | ByteOrderData::putUint32(buf_, byteOrder_, v); 54 | stream_.write(reinterpret_cast(buf_), 4); 55 | } 56 | 57 | void ByteOrderDataOutStream::writeDouble(double v) { 58 | ByteOrderData::putDouble(buf_, byteOrder_, v); 59 | stream_.write(reinterpret_cast(buf_), 8); 60 | } 61 | 62 | } // namespace geo 63 | } // namespace nebula 64 | -------------------------------------------------------------------------------- /src/geo/io/wkb/WKBWriter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/geo/io/wkb/WKBWriter.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | namespace geo { 13 | 14 | std::string WKBWriter::write(const Geography& geog, ByteOrder byteOrder) { 15 | os_.setByteOrder(byteOrder); 16 | os_.writeUint8(folly::to(byteOrder)); 17 | 18 | GeoShape shape = geog.shape(); 19 | uint32_t shapeType = folly::to(shape); 20 | os_.writeUint32(shapeType); 21 | switch (shape) { 22 | case GeoShape::POINT: { 23 | const Point& point = geog.point(); 24 | writePoint(point); 25 | return os_.str(); 26 | } 27 | case GeoShape::LINESTRING: { 28 | const LineString& line = geog.lineString(); 29 | writeLineString(line); 30 | return os_.str(); 31 | } 32 | case GeoShape::POLYGON: { 33 | const Polygon& polygon = geog.polygon(); 34 | writePolygon(polygon); 35 | return os_.str(); 36 | } 37 | default: 38 | LOG(FATAL) 39 | << "Geomtry shapes other than Point/LineString/Polygon are not currently supported"; 40 | return ""; 41 | } 42 | } 43 | 44 | void WKBWriter::writePoint(const Point& point) { 45 | writeCoordinate(point.coord); 46 | } 47 | 48 | void WKBWriter::writeLineString(const LineString& line) { 49 | auto coordList = line.coordList; 50 | uint32_t numCoord = coordList.size(); 51 | os_.writeUint32(numCoord); 52 | writeCoordinateList(coordList); 53 | } 54 | 55 | void WKBWriter::writePolygon(const Polygon& polygon) { 56 | auto coordListList = polygon.coordListList; 57 | uint32_t numCoordList = coordListList.size(); 58 | os_.writeUint32(numCoordList); 59 | writeCoordinateListList(coordListList); 60 | } 61 | 62 | void WKBWriter::writeCoordinate(const Coordinate& coord) { 63 | os_.writeDouble(coord.x); 64 | os_.writeDouble(coord.y); 65 | } 66 | 67 | void WKBWriter::writeCoordinateList(const std::vector& coordList) { 68 | for (size_t i = 0; i < coordList.size(); ++i) { 69 | writeCoordinate(coordList[i]); 70 | } 71 | } 72 | 73 | void WKBWriter::writeCoordinateListList(const std::vector>& coordListList) { 74 | for (size_t i = 0; i < coordListList.size(); ++i) { 75 | const auto& coordList = coordListList[i]; 76 | uint32_t numCoord = coordList.size(); 77 | os_.writeUint32(numCoord); 78 | writeCoordinateList(coordList); 79 | } 80 | } 81 | 82 | } // namespace geo 83 | } // namespace nebula 84 | -------------------------------------------------------------------------------- /src/geo/io/wkt/WKTWriter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "common/geo/io/wkt/WKTWriter.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace nebula { 12 | namespace geo { 13 | 14 | std::string WKTWriter::write(const Geography& geog) const { 15 | std::string wkt = ""; 16 | 17 | auto shape = geog.shape(); 18 | switch (shape) { 19 | case GeoShape::POINT: { 20 | wkt.append("POINT"); 21 | const Point& point = geog.point(); 22 | wkt.append("("); 23 | writeCoordinate(wkt, point.coord); 24 | wkt.append(")"); 25 | return wkt; 26 | } 27 | case GeoShape::LINESTRING: { 28 | wkt.append("LINESTRING"); 29 | const LineString& line = geog.lineString(); 30 | auto coordList = line.coordList; 31 | uint32_t numCoord = coordList.size(); 32 | (void)(numCoord); 33 | wkt.append("("); 34 | writeCoordinateList(wkt, coordList); 35 | wkt.append(")"); 36 | return wkt; 37 | } 38 | case GeoShape::POLYGON: { 39 | wkt.append("POLYGON"); 40 | const Polygon& polygon = geog.polygon(); 41 | auto coordListList = polygon.coordListList; 42 | uint32_t numCoordList = coordListList.size(); 43 | (void)(numCoordList); 44 | wkt.append("("); 45 | writeCoordinateListList(wkt, coordListList); 46 | wkt.append(")"); 47 | return wkt; 48 | } 49 | default: 50 | LOG(ERROR) 51 | << "Geomtry shapes other than Point/LineString/Polygon are not currently supported"; 52 | return ""; 53 | } 54 | } 55 | 56 | void WKTWriter::writeCoordinate(std::string& wkt, const Coordinate& coord) const { 57 | writeDouble(wkt, coord.x); 58 | wkt.append(" "); 59 | writeDouble(wkt, coord.y); 60 | } 61 | 62 | void WKTWriter::writeCoordinateList(std::string& wkt, 63 | const std::vector& coordList) const { 64 | for (size_t i = 0; i < coordList.size(); ++i) { 65 | writeCoordinate(wkt, coordList[i]); 66 | wkt.append(", "); 67 | } 68 | wkt.pop_back(); 69 | wkt.pop_back(); 70 | } 71 | 72 | void WKTWriter::WKTWriter::writeCoordinateListList( 73 | std::string& wkt, const std::vector>& coordListList) const { 74 | for (size_t i = 0; i < coordListList.size(); ++i) { 75 | const auto& coordList = coordListList[i]; 76 | uint32_t numCoord = coordList.size(); 77 | (void)(numCoord); 78 | wkt.append("("); 79 | writeCoordinateList(wkt, coordList); 80 | wkt.append(")"); 81 | wkt.append(", "); 82 | } 83 | wkt.pop_back(); 84 | wkt.pop_back(); 85 | } 86 | 87 | void WKTWriter::writeDouble(std::string& wkt, double v) const { 88 | wkt.append(folly::to(v)); 89 | } 90 | 91 | } // namespace geo 92 | } // namespace nebula 93 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GeneralStorageService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "GeneralStorageService.tcc" 17 | #include "storage_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | #include "meta_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GeneralStorageService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GeneralStorageService.h" 9 | #include "GeneralStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GeneralStorageService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GeneralStorageService.h" 9 | #include "GeneralStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "GraphService.tcc" 17 | #include "graph_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GraphService.h" 9 | #include "GraphService.tcc" 10 | 11 | namespace nebula { namespace graph { namespace cpp2 { 12 | }}} // nebula::graph::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GraphService.h" 9 | #include "GraphService.tcc" 10 | 11 | namespace nebula { namespace graph { namespace cpp2 { 12 | }}} // nebula::graph::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphStorageService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "GraphStorageService.tcc" 17 | #include "storage_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | #include "meta_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphStorageService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GraphStorageService.h" 9 | #include "GraphStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/GraphStorageService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "GraphStorageService.h" 9 | #include "GraphStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/InternalStorageService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "InternalStorageService.tcc" 17 | #include "storage_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | #include "meta_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/InternalStorageService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "InternalStorageService.h" 9 | #include "InternalStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/InternalStorageService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "InternalStorageService.h" 9 | #include "InternalStorageService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/MetaService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "MetaService.tcc" 17 | #include "meta_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/MetaService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "MetaService.h" 9 | #include "MetaService.tcc" 10 | 11 | namespace nebula { namespace meta { namespace cpp2 { 12 | }}} // nebula::meta::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/MetaService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "MetaService.h" 9 | #include "MetaService.tcc" 10 | 11 | namespace nebula { namespace meta { namespace cpp2 { 12 | }}} // nebula::meta::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/StorageAdminService_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | /** 10 | * This header file includes the tcc files of the corresponding header file 11 | * and the header files of its dependent types. Include this header file 12 | * only when you need to use custom protocols (e.g. DebugProtocol, 13 | * VirtualProtocol) to read/write thrift structs. 14 | */ 15 | 16 | #include "StorageAdminService.tcc" 17 | #include "storage_types_custom_protocol.h" 18 | #include "common_types_custom_protocol.h" 19 | #include "meta_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/StorageAdminService_processmap_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "StorageAdminService.h" 9 | #include "StorageAdminService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/StorageAdminService_processmap_compact.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "StorageAdminService.h" 9 | #include "StorageAdminService.tcc" 10 | 11 | namespace nebula { namespace storage { namespace cpp2 { 12 | }}} // nebula::storage::cpp2 13 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/common_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for common.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | 8 | #include "common_constants.h" 9 | 10 | #include 11 | 12 | 13 | namespace nebula { namespace cpp2 { 14 | 15 | constexpr char const * const common_constants::version_; 16 | 17 | }} // nebula::cpp2 18 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/common_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for common.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "common_types.h" 12 | 13 | namespace nebula { namespace cpp2 { 14 | 15 | struct common_constants { 16 | 17 | static constexpr char const * const version_ = "3.0.0"; 18 | 19 | static constexpr char const * version() { 20 | return version_; 21 | } 22 | 23 | }; 24 | 25 | }} // nebula::cpp2 26 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/common_types_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for common.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | 10 | /** 11 | * This header file includes the tcc files of the corresponding header file 12 | * and the header files of its dependent types. Include this header file 13 | * only when you need to use custom protocols (e.g. DebugProtocol, 14 | * VirtualProtocol) to read/write thrift structs. 15 | */ 16 | 17 | #include "common_types.tcc" 18 | 19 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/common_visit_union.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for common.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include "common_metadata.h" 10 | #include 11 | 12 | namespace apache { 13 | namespace thrift { 14 | namespace detail { 15 | 16 | template <> 17 | struct VisitUnion<::nebula::cpp2::SchemaID> { 18 | template 19 | void operator()(FOLLY_MAYBE_UNUSED F&& f, T&& t) const { 20 | using Union = std::remove_reference_t; 21 | switch (t.getType()) { 22 | case Union::Type::tag_id: 23 | return f(0, *static_cast(t).tag_id_ref()); 24 | case Union::Type::edge_type: 25 | return f(1, *static_cast(t).edge_type_ref()); 26 | case Union::Type::__EMPTY__: ; 27 | } 28 | } 29 | }; 30 | template <> 31 | struct VisitUnion<::nebula::cpp2::Value> { 32 | template 33 | void operator()(FOLLY_MAYBE_UNUSED F&& f, T&& t) const { 34 | using Union = std::remove_reference_t; 35 | switch (t.getType()) { 36 | case Union::Type::nVal: 37 | return f(0, *static_cast(t).nVal_ref()); 38 | case Union::Type::bVal: 39 | return f(1, *static_cast(t).bVal_ref()); 40 | case Union::Type::iVal: 41 | return f(2, *static_cast(t).iVal_ref()); 42 | case Union::Type::fVal: 43 | return f(3, *static_cast(t).fVal_ref()); 44 | case Union::Type::sVal: 45 | return f(4, *static_cast(t).sVal_ref()); 46 | case Union::Type::dVal: 47 | return f(5, *static_cast(t).dVal_ref()); 48 | case Union::Type::tVal: 49 | return f(6, *static_cast(t).tVal_ref()); 50 | case Union::Type::dtVal: 51 | return f(7, *static_cast(t).dtVal_ref()); 52 | case Union::Type::vVal: 53 | return f(8, *static_cast(t).vVal_ref()); 54 | case Union::Type::eVal: 55 | return f(9, *static_cast(t).eVal_ref()); 56 | case Union::Type::pVal: 57 | return f(10, *static_cast(t).pVal_ref()); 58 | case Union::Type::lVal: 59 | return f(11, *static_cast(t).lVal_ref()); 60 | case Union::Type::mVal: 61 | return f(12, *static_cast(t).mVal_ref()); 62 | case Union::Type::uVal: 63 | return f(13, *static_cast(t).uVal_ref()); 64 | case Union::Type::gVal: 65 | return f(14, *static_cast(t).gVal_ref()); 66 | case Union::Type::ggVal: 67 | return f(15, *static_cast(t).ggVal_ref()); 68 | case Union::Type::duVal: 69 | return f(16, *static_cast(t).duVal_ref()); 70 | case Union::Type::__EMPTY__: ; 71 | } 72 | } 73 | }; 74 | template <> 75 | struct VisitUnion<::nebula::cpp2::Geography> { 76 | template 77 | void operator()(FOLLY_MAYBE_UNUSED F&& f, T&& t) const { 78 | using Union = std::remove_reference_t; 79 | switch (t.getType()) { 80 | case Union::Type::ptVal: 81 | return f(0, *static_cast(t).ptVal_ref()); 82 | case Union::Type::lsVal: 83 | return f(1, *static_cast(t).lsVal_ref()); 84 | case Union::Type::pgVal: 85 | return f(2, *static_cast(t).pgVal_ref()); 86 | case Union::Type::__EMPTY__: ; 87 | } 88 | } 89 | }; 90 | } // namespace detail 91 | } // namespace thrift 92 | } // namespace apache 93 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/common_visitation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for common.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | #include "common_for_each_field.h" 9 | #include "common_visit_union.h" 10 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "graph_types.h" 12 | 13 | namespace nebula { namespace graph { namespace cpp2 { 14 | 15 | struct graph_constants { 16 | 17 | }; 18 | 19 | }}} // nebula::graph::cpp2 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_metadata.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include 10 | #include "graph_types.h" 11 | #include "common_metadata.h" 12 | 13 | namespace nebula { 14 | namespace graph { 15 | namespace cpp2 { 16 | class GraphServiceSvIf; 17 | }}} // namespace nebula::graph::cpp2 18 | 19 | namespace apache { 20 | namespace thrift { 21 | namespace detail { 22 | namespace md { 23 | 24 | template <> 25 | class StructMetadata<::nebula::graph::cpp2::ProfilingStats> { 26 | public: 27 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 28 | }; 29 | template <> 30 | class StructMetadata<::nebula::graph::cpp2::PlanNodeBranchInfo> { 31 | public: 32 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 33 | }; 34 | template <> 35 | class StructMetadata<::nebula::graph::cpp2::Pair> { 36 | public: 37 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 38 | }; 39 | template <> 40 | class StructMetadata<::nebula::graph::cpp2::PlanNodeDescription> { 41 | public: 42 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 43 | }; 44 | template <> 45 | class StructMetadata<::nebula::graph::cpp2::PlanDescription> { 46 | public: 47 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 48 | }; 49 | template <> 50 | class StructMetadata<::nebula::graph::cpp2::ExecutionResponse> { 51 | public: 52 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 53 | }; 54 | template <> 55 | class StructMetadata<::nebula::graph::cpp2::AuthResponse> { 56 | public: 57 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 58 | }; 59 | template <> 60 | class StructMetadata<::nebula::graph::cpp2::VerifyClientVersionResp> { 61 | public: 62 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 63 | }; 64 | template <> 65 | class StructMetadata<::nebula::graph::cpp2::VerifyClientVersionReq> { 66 | public: 67 | static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); 68 | }; 69 | template <> 70 | class ServiceMetadata<::nebula::graph::cpp2::GraphServiceSvIf> { 71 | public: 72 | static void gen(ThriftMetadata& metadata, ThriftServiceContext& context); 73 | private: 74 | static void gen_authenticate(ThriftMetadata& metadata, ThriftService& context); 75 | static void gen_signout(ThriftMetadata& metadata, ThriftService& context); 76 | static void gen_execute(ThriftMetadata& metadata, ThriftService& context); 77 | static void gen_executeWithParameter(ThriftMetadata& metadata, ThriftService& context); 78 | static void gen_executeJson(ThriftMetadata& metadata, ThriftService& context); 79 | static void gen_executeJsonWithParameter(ThriftMetadata& metadata, ThriftService& context); 80 | static void gen_verifyClientVersion(ThriftMetadata& metadata, ThriftService& context); 81 | }; 82 | } // namespace md 83 | } // namespace detail 84 | } // namespace thrift 85 | } // namespace apache 86 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_types_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | 10 | /** 11 | * This header file includes the tcc files of the corresponding header file 12 | * and the header files of its dependent types. Include this header file 13 | * only when you need to use custom protocols (e.g. DebugProtocol, 14 | * VirtualProtocol) to read/write thrift structs. 15 | */ 16 | 17 | #include "graph_types.tcc" 18 | 19 | #include "common_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_visit_union.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include "graph_metadata.h" 10 | #include 11 | 12 | namespace apache { 13 | namespace thrift { 14 | namespace detail { 15 | 16 | } // namespace detail 17 | } // namespace thrift 18 | } // namespace apache 19 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/graph_visitation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for graph.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | #include "common_visitation.h" 9 | #include "graph_for_each_field.h" 10 | #include "graph_visit_union.h" 11 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/meta_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/meta_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "meta_types.h" 12 | 13 | namespace nebula { namespace meta { namespace cpp2 { 14 | 15 | struct meta_constants { 16 | 17 | }; 18 | 19 | }}} // nebula::meta::cpp2 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/meta_types_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | 10 | /** 11 | * This header file includes the tcc files of the corresponding header file 12 | * and the header files of its dependent types. Include this header file 13 | * only when you need to use custom protocols (e.g. DebugProtocol, 14 | * VirtualProtocol) to read/write thrift structs. 15 | */ 16 | 17 | #include "meta_types.tcc" 18 | 19 | #include "common_types_custom_protocol.h" 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/meta_visit_union.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include "meta_metadata.h" 10 | #include 11 | 12 | namespace apache { 13 | namespace thrift { 14 | namespace detail { 15 | 16 | template <> 17 | struct VisitUnion<::nebula::meta::cpp2::ID> { 18 | template 19 | void operator()(FOLLY_MAYBE_UNUSED F&& f, T&& t) const { 20 | using Union = std::remove_reference_t; 21 | switch (t.getType()) { 22 | case Union::Type::space_id: 23 | return f(0, *static_cast(t).space_id_ref()); 24 | case Union::Type::tag_id: 25 | return f(1, *static_cast(t).tag_id_ref()); 26 | case Union::Type::edge_type: 27 | return f(2, *static_cast(t).edge_type_ref()); 28 | case Union::Type::index_id: 29 | return f(3, *static_cast(t).index_id_ref()); 30 | case Union::Type::cluster_id: 31 | return f(4, *static_cast(t).cluster_id_ref()); 32 | case Union::Type::__EMPTY__: ; 33 | } 34 | } 35 | }; 36 | } // namespace detail 37 | } // namespace thrift 38 | } // namespace apache 39 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/meta_visitation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for meta.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | #include "common_visitation.h" 9 | #include "meta_for_each_field.h" 10 | #include "meta_visit_union.h" 11 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/storage_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/storage_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "storage_types.h" 12 | 13 | namespace nebula { namespace storage { namespace cpp2 { 14 | 15 | struct storage_constants { 16 | 17 | }; 18 | 19 | }}} // nebula::storage::cpp2 20 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/storage_types_custom_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | 10 | /** 11 | * This header file includes the tcc files of the corresponding header file 12 | * and the header files of its dependent types. Include this header file 13 | * only when you need to use custom protocols (e.g. DebugProtocol, 14 | * VirtualProtocol) to read/write thrift structs. 15 | */ 16 | 17 | #include "storage_types.tcc" 18 | 19 | #include "common_types_custom_protocol.h" 20 | #include "meta_types_custom_protocol.h" 21 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/storage_visit_union.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | 9 | #include "storage_metadata.h" 10 | #include 11 | 12 | namespace apache { 13 | namespace thrift { 14 | namespace detail { 15 | 16 | } // namespace detail 17 | } // namespace thrift 18 | } // namespace apache 19 | -------------------------------------------------------------------------------- /src/interface/gen-cpp2/storage_visitation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift for storage.thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #pragma once 8 | #include "common_visitation.h" 9 | #include "meta_visitation.h" 10 | #include "storage_for_each_field.h" 11 | #include "storage_visit_union.h" 12 | -------------------------------------------------------------------------------- /src/mclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | 5 | nebula_add_subdirectory(tests) 6 | -------------------------------------------------------------------------------- /src/mclient/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | 5 | nebula_add_test( 6 | NAME 7 | meta_client_test 8 | SOURCES 9 | MetaClientTest.cpp 10 | OBJECTS 11 | ${NEBULA_MCLIENT_OBJS} 12 | $ 13 | $ 14 | $ 15 | $ 16 | LIBRARIES 17 | gtest 18 | ${NEBULA_THIRD_PARTY_LIBRARIES} 19 | ) 20 | 21 | nebula_add_test( 22 | NAME 23 | meta_client_ssl_test 24 | SOURCES 25 | MetaClientSSLTest.cpp 26 | OBJECTS 27 | ${NEBULA_MCLIENT_OBJS} 28 | $ 29 | $ 30 | $ 31 | $ 32 | LIBRARIES 33 | gtest 34 | ${NEBULA_THIRD_PARTY_LIBRARIES} 35 | ) 36 | -------------------------------------------------------------------------------- /src/mclient/tests/MClientTest.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/DataSet.h" 11 | #include "common/graph/Response.h" 12 | class MClientTest : public ::testing::Test { 13 | protected: 14 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::DataSet& resp, 15 | const nebula::DataSet& expect) { 16 | nebula::DataSet respCopy = resp; 17 | nebula::DataSet expectCopy = expect; 18 | std::sort(respCopy.rows.begin(), respCopy.rows.end()); 19 | std::sort(expectCopy.rows.begin(), expectCopy.rows.end()); 20 | if (respCopy != expectCopy) { 21 | return ::testing::AssertionFailure() << "Resp is : " << resp << std::endl 22 | << "Expect : " << expect; 23 | } 24 | return ::testing::AssertionSuccess(); 25 | } 26 | 27 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::ExecutionResponse& resp, 28 | const nebula::DataSet& expect) { 29 | auto result = succeeded(resp); 30 | if (!result) { 31 | return result; 32 | } 33 | const auto& data = *resp.data; 34 | return verifyResultWithoutOrder(data, expect); 35 | } 36 | 37 | static ::testing::AssertionResult succeeded(const nebula::ExecutionResponse& resp) { 38 | if (resp.errorCode != nebula::ErrorCode::SUCCEEDED) { 39 | return ::testing::AssertionFailure() 40 | << "Execution Failed with error: " << resp.errorCode << "," << *resp.errorMsg; 41 | } 42 | return ::testing::AssertionSuccess(); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/mclient/tests/MetaClientSSLTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "./MClientTest.h" 16 | #include "common/datatypes/HostAddr.h" 17 | #include "common/thrift/ThriftTypes.h" 18 | 19 | // Require a nebula server could access 20 | 21 | #define kServerHost "127.0.0.1" 22 | 23 | class MetaClientTest : public MClientTest { 24 | protected: 25 | static void prepare() { 26 | nebula::ConnectionPool pool; 27 | nebula::Config cfg; 28 | cfg.enableSSL_ = true; 29 | pool.init({kServerHost ":9669"}, cfg); 30 | auto session = pool.getSession("root", "nebula"); 31 | ASSERT_TRUE(session.valid()); 32 | EXPECT_TRUE(session.ping()); 33 | auto result = session.execute( 34 | "CREATE SPACE IF NOT EXISTS meta_client_test(vid_type=FIXED_STRING(8)," 35 | "partition_num=3);USE meta_client_test"); 36 | ASSERT_EQ(result.errorCode, nebula::ErrorCode::SUCCEEDED) << *result.errorMsg; 37 | 38 | auto result2 = session.execute("CREATE EDGE IF NOT EXISTS like(likeness int)"); 39 | ASSERT_EQ(result2.errorCode, nebula::ErrorCode::SUCCEEDED) << *result2.errorMsg; 40 | 41 | ::sleep(30); 42 | 43 | auto result3 = session.execute( 44 | "INSERT EDGE like(likeness) VALUES '101'->'102':(78), '102'->'103':(99), " 45 | "'103'->'201':(43), '201'->'202':(56), '202'->'203':(-13), '203'->'301':(431), " 46 | "'301'->'302':(457)"); 47 | ASSERT_EQ(result3.errorCode, nebula::ErrorCode::SUCCEEDED); 48 | } 49 | 50 | static void runOnce(nebula::MetaClient &c) { 51 | auto ret = c.getSpaceIdByNameFromCache("meta_client_test"); 52 | ASSERT_TRUE(ret.first); 53 | nebula::GraphSpaceID spaceId = ret.second; 54 | LOG(INFO) << "spaceId of nba: " << spaceId; 55 | EXPECT_GT(spaceId, 0); 56 | 57 | auto ret2 = c.getEdgeTypeByNameFromCache(spaceId, "like"); 58 | ASSERT_TRUE(ret2.first); 59 | nebula::EdgeType edgeType = ret2.second; 60 | LOG(INFO) << "edgeType of like: " << edgeType; 61 | EXPECT_GT(edgeType, 0); 62 | 63 | auto ret3 = c.getPartsFromCache(spaceId); 64 | ASSERT_TRUE(ret3.first); 65 | auto parts = ret3.second; 66 | EXPECT_EQ(parts, (std::vector{1, 2, 3})); 67 | 68 | auto ret4 = c.getPartLeaderFromCache(spaceId, 1); 69 | ASSERT_TRUE(ret4.first); 70 | EXPECT_EQ(ret4.second, nebula::HostAddr(kServerHost, 9779)); 71 | } 72 | }; 73 | 74 | TEST_F(MetaClientTest, SSL) { 75 | LOG(INFO) << "Prepare data."; 76 | prepare(); 77 | 78 | LOG(INFO) << "Run once."; 79 | nebula::MConfig mConfig{1000, 60 * 1000, true, false, false, "", "", "", ""}; 80 | nebula::MetaClient c({kServerHost ":9559"}, mConfig); 81 | runOnce(c); 82 | } 83 | 84 | int main(int argc, char **argv) { 85 | testing::InitGoogleTest(&argc, argv); 86 | nebula::init(&argc, &argv); 87 | google::SetStderrLogging(google::INFO); 88 | 89 | return RUN_ALL_TESTS(); 90 | } 91 | -------------------------------------------------------------------------------- /src/mclient/tests/MetaClientTest.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "./MClientTest.h" 16 | #include "common/datatypes/HostAddr.h" 17 | #include "common/thrift/ThriftTypes.h" 18 | 19 | // Require a nebula server could access 20 | 21 | #define kServerHost "127.0.0.1" 22 | 23 | class MetaClientTest : public MClientTest { 24 | protected: 25 | static void prepare() { 26 | nebula::ConnectionPool pool; 27 | pool.init({kServerHost ":9669"}, nebula::Config{}); 28 | auto session = pool.getSession("root", "nebula"); 29 | ASSERT_TRUE(session.valid()); 30 | EXPECT_TRUE(session.ping()); 31 | auto result = session.execute( 32 | "CREATE SPACE IF NOT EXISTS meta_client_test(vid_type=FIXED_STRING(8)," 33 | "partition_num=3);USE meta_client_test"); 34 | ASSERT_EQ(result.errorCode, nebula::ErrorCode::SUCCEEDED); 35 | 36 | auto result2 = session.execute("CREATE EDGE IF NOT EXISTS like(likeness int)"); 37 | ASSERT_EQ(result2.errorCode, nebula::ErrorCode::SUCCEEDED); 38 | 39 | ::sleep(30); 40 | 41 | auto result3 = session.execute( 42 | "INSERT EDGE like(likeness) VALUES '101'->'102':(78), '102'->'103':(99), " 43 | "'103'->'201':(43), '201'->'202':(56), '202'->'203':(-13), '203'->'301':(431), " 44 | "'301'->'302':(457)"); 45 | ASSERT_EQ(result3.errorCode, nebula::ErrorCode::SUCCEEDED); 46 | } 47 | 48 | static void runOnce(nebula::MetaClient &c) { 49 | auto ret = c.getSpaceIdByNameFromCache("meta_client_test"); 50 | ASSERT_TRUE(ret.first); 51 | nebula::GraphSpaceID spaceId = ret.second; 52 | LOG(INFO) << "spaceId of nba: " << spaceId; 53 | EXPECT_GT(spaceId, 0); 54 | 55 | auto ret2 = c.getEdgeTypeByNameFromCache(spaceId, "like"); 56 | ASSERT_TRUE(ret2.first); 57 | nebula::EdgeType edgeType = ret2.second; 58 | LOG(INFO) << "edgeType of like: " << edgeType; 59 | EXPECT_GT(edgeType, 0); 60 | 61 | auto ret3 = c.getPartsFromCache(spaceId); 62 | ASSERT_TRUE(ret3.first); 63 | auto parts = ret3.second; 64 | EXPECT_EQ(parts, (std::vector{1, 2, 3})); 65 | 66 | auto ret4 = c.getPartLeaderFromCache(spaceId, 1); 67 | ASSERT_TRUE(ret4.first); 68 | EXPECT_EQ(ret4.second, nebula::HostAddr(kServerHost, 9779)); 69 | } 70 | }; 71 | 72 | TEST_F(MetaClientTest, Basic) { 73 | LOG(INFO) << "Prepare data."; 74 | prepare(); 75 | 76 | LOG(INFO) << "Run once."; 77 | nebula::MetaClient c({kServerHost ":9559"}); 78 | runOnce(c); 79 | } 80 | 81 | int main(int argc, char **argv) { 82 | testing::InitGoogleTest(&argc, argv); 83 | nebula::init(&argc, &argv); 84 | google::SetStderrLogging(google::INFO); 85 | 86 | return RUN_ALL_TESTS(); 87 | } 88 | -------------------------------------------------------------------------------- /src/sclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | 5 | nebula_add_subdirectory(tests) 6 | -------------------------------------------------------------------------------- /src/sclient/ScanEdgeIter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "nebula/sclient/ScanEdgeIter.h" 7 | 8 | #include "../interface/gen-cpp2/storage_types.h" 9 | #include "nebula/sclient/StorageClient.h" 10 | 11 | namespace nebula { 12 | 13 | ScanEdgeIter::ScanEdgeIter(StorageClient* client, storage::cpp2::ScanEdgeRequest* req, bool hasNext) 14 | : client_(client), req_(req), hasNext_(hasNext) {} 15 | 16 | bool ScanEdgeIter::hasNext() { 17 | return hasNext_; 18 | } 19 | 20 | ScanEdgeIter::~ScanEdgeIter() { 21 | delete req_; 22 | } 23 | 24 | std::pair<::nebula::ErrorCode, DataSet> ScanEdgeIter::next() { 25 | DCHECK(hasNext()) << "hasNext() == false !"; 26 | DCHECK(!!req_); 27 | auto partCursorMapReq = req_->get_parts(); 28 | DCHECK_EQ(partCursorMapReq.size(), 1); 29 | partCursorMapReq.begin()->second.set_next_cursor(nextCursor_); 30 | req_->set_parts(partCursorMapReq); 31 | auto r = client_->doScanEdge(*req_); 32 | auto code = r.first; 33 | if (code != ::nebula::ErrorCode::SUCCEEDED) { 34 | LOG(ERROR) << "Scan edge failed, error code: " << static_cast(code); 35 | this->hasNext_ = false; 36 | return {code, DataSet()}; 37 | } 38 | auto scanResponse = r.second; 39 | DCHECK(scanResponse.get_result().get_failed_parts().empty()); 40 | auto partCursorMapResp = scanResponse.get_cursors(); 41 | DCHECK_EQ(partCursorMapResp.size(), 1); 42 | auto scanCursor = partCursorMapResp.begin()->second; 43 | hasNext_ = scanCursor.next_cursor_ref().has_value(); 44 | if (hasNext_) { 45 | nextCursor_ = scanCursor.next_cursor_ref().value(); 46 | } 47 | 48 | return {::nebula::ErrorCode::SUCCEEDED, *scanResponse.get_props()}; 49 | } 50 | 51 | } // namespace nebula 52 | -------------------------------------------------------------------------------- /src/sclient/ScanVertexIter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #include "nebula/sclient/ScanVertexIter.h" 7 | 8 | #include "../interface/gen-cpp2/storage_types.h" 9 | #include "nebula/sclient/StorageClient.h" 10 | 11 | namespace nebula { 12 | 13 | ScanVertexIter::ScanVertexIter(StorageClient* client, 14 | storage::cpp2::ScanVertexRequest* req, 15 | bool hasNext) 16 | : client_(client), req_(req), hasNext_(hasNext) {} 17 | 18 | bool ScanVertexIter::hasNext() { 19 | return hasNext_; 20 | } 21 | 22 | ScanVertexIter::~ScanVertexIter() { 23 | delete req_; 24 | } 25 | 26 | std::pair<::nebula::ErrorCode, DataSet> ScanVertexIter::next() { 27 | DCHECK(hasNext()) << "hasNext() == false !"; 28 | DCHECK(!!req_); 29 | auto partCursorMapReq = req_->get_parts(); 30 | DCHECK_EQ(partCursorMapReq.size(), 1); 31 | partCursorMapReq.begin()->second.set_next_cursor(nextCursor_); 32 | req_->set_parts(partCursorMapReq); 33 | auto r = client_->doScanVertex(*req_); 34 | auto code = r.first; 35 | if (code != ::nebula::ErrorCode::SUCCEEDED) { 36 | LOG(ERROR) << "Scan vertex failed, error code: " << static_cast(code); 37 | this->hasNext_ = false; 38 | return {code, DataSet()}; 39 | } 40 | auto scanResponse = r.second; 41 | DCHECK(scanResponse.get_result().get_failed_parts().empty()); 42 | auto partCursorMapResp = scanResponse.get_cursors(); 43 | DCHECK_EQ(partCursorMapResp.size(), 1); 44 | auto scanCursor = partCursorMapResp.begin()->second; 45 | hasNext_ = scanCursor.next_cursor_ref().has_value(); 46 | if (hasNext_) { 47 | nextCursor_ = scanCursor.next_cursor_ref().value(); 48 | } 49 | 50 | return {::nebula::ErrorCode::SUCCEEDED, *scanResponse.get_props()}; 51 | } 52 | 53 | } // namespace nebula 54 | -------------------------------------------------------------------------------- /src/sclient/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 vesoft inc. All rights reserved. 2 | # 3 | # This source code is licensed under Apache 2.0 License. 4 | 5 | nebula_add_test( 6 | NAME 7 | storage_client_test 8 | SOURCES 9 | StorageClientTest.cpp 10 | OBJECTS 11 | ${NEBULA_SCLIENT_OBJS} 12 | $ 13 | $ 14 | $ 15 | $ 16 | LIBRARIES 17 | gtest 18 | ${NEBULA_THIRD_PARTY_LIBRARIES} 19 | ) 20 | 21 | nebula_add_test( 22 | NAME 23 | storage_client_ssl_test 24 | SOURCES 25 | StorageClientSSLTest.cpp 26 | OBJECTS 27 | ${NEBULA_SCLIENT_OBJS} 28 | $ 29 | $ 30 | $ 31 | $ 32 | LIBRARIES 33 | gtest 34 | ${NEBULA_THIRD_PARTY_LIBRARIES} 35 | ) 36 | -------------------------------------------------------------------------------- /src/sclient/tests/SClientTest.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "common/datatypes/DataSet.h" 11 | #include "common/graph/Response.h" 12 | class SClientTest : public ::testing::Test { 13 | protected: 14 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::DataSet& resp, 15 | const nebula::DataSet& expect) { 16 | nebula::DataSet respCopy = resp; 17 | nebula::DataSet expectCopy = expect; 18 | std::sort(respCopy.rows.begin(), respCopy.rows.end()); 19 | std::sort(expectCopy.rows.begin(), expectCopy.rows.end()); 20 | if (respCopy != expectCopy) { 21 | return ::testing::AssertionFailure() << "Resp is : " << resp << std::endl 22 | << "Expect : " << expect; 23 | } 24 | return ::testing::AssertionSuccess(); 25 | } 26 | 27 | static ::testing::AssertionResult verifyResultWithoutOrder(const nebula::ExecutionResponse& resp, 28 | const nebula::DataSet& expect) { 29 | auto result = succeeded(resp); 30 | if (!result) { 31 | return result; 32 | } 33 | const auto& data = *resp.data; 34 | return verifyResultWithoutOrder(data, expect); 35 | } 36 | 37 | static ::testing::AssertionResult succeeded(const nebula::ExecutionResponse& resp) { 38 | if (resp.errorCode != nebula::ErrorCode::SUCCEEDED) { 39 | return ::testing::AssertionFailure() 40 | << "Execution Failed with error: " << resp.errorCode << "," << *resp.errorMsg; 41 | } 42 | return ::testing::AssertionSuccess(); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/thrift/ThriftClientManager.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 vesoft inc. All rights reserved. 2 | * 3 | * This source code is licensed under Apache 2.0 License. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "common/datatypes/HostAddr.h" 12 | #include "../SSLConfig.h" 13 | 14 | namespace nebula { 15 | namespace thrift { 16 | 17 | template 18 | class ThriftClientManager final { 19 | public: 20 | std::shared_ptr client(const HostAddr& host, 21 | folly::EventBase* evb = nullptr, 22 | bool compatibility = false, 23 | uint32_t timeout = 0); 24 | 25 | ~ThriftClientManager() { 26 | VLOG(3) << "~ThriftClientManager"; 27 | } 28 | 29 | explicit ThriftClientManager(int32_t connTimeoutInMs, bool enableSSL, SSLConfig cfg = SSLConfig()) 30 | : connTimeoutInMs_(connTimeoutInMs), enableSSL_(enableSSL), sslcfg_(std::move(cfg)) { 31 | VLOG(3) << "ThriftClientManager"; 32 | } 33 | 34 | private: 35 | using ClientMap = 36 | std::unordered_map, std::shared_ptr>; 37 | 38 | folly::ThreadLocal clientMap_; 39 | int32_t connTimeoutInMs_; 40 | // whether enable ssl 41 | bool enableSSL_; 42 | SSLConfig sslcfg_; 43 | }; 44 | 45 | } // namespace thrift 46 | } // namespace nebula 47 | 48 | #include "../thrift/ThriftClientManager-inl.h" 49 | -------------------------------------------------------------------------------- /third-party/cxx-compiler-abi-version.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Copyright (c) 2019 vesoft inc. All rights reserved. 4 | # 5 | # This source code is licensed under Apache 2.0 License. 6 | 7 | set -e 8 | abi="unknown" 9 | cxx_cmd=${CXX:-g++} 10 | link_flags="-std=c++14 -static-libstdc++ -static-libgcc" 11 | [[ $disable_cxx11_abi -ne 0 ]] && extra_flags="$extra_flags -D_GLIBCXX_USE_CXX11_ABI=0" 12 | tmpdir=$(mktemp -q -d /tmp/nebula-compiler-test.XXXX 2>/dev/null) 13 | object=$tmpdir/a.out.o 14 | 15 | $cxx_cmd $link_flags $extra_flags -g -x c++ - -c -o $object > /dev/null < 17 | void foobar(std::string) { 18 | } 19 | EOF 20 | 21 | string=$(nm -C $object | sed -nr 's/.*foobar.*(std.*string).*/\1/p') 22 | 23 | [[ $string = 'std::__cxx11::basic_string' ]] && abi=11 24 | [[ $string = 'std::string' ]] && abi=98 25 | 26 | echo $abi 27 | -------------------------------------------------------------------------------- /third-party/install-cmake.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Copyright (c) 2019 vesoft inc. All rights reserved. 4 | # 5 | # This source code is licensed under Apache 2.0 License. 6 | 7 | # Usage: build-cmake.sh [prefix] 8 | 9 | # Always use bash 10 | shell=$(basename $(readlink /proc/$$/exe)) 11 | if [ ! x$shell = x"bash" ] 12 | then 13 | bash $0 $@ 14 | exit $? 15 | fi 16 | 17 | archive=cmake-3.15.5-Linux-x86_64.sh 18 | url=https://cmake.org/files/v3.15/$archive 19 | prefix=`pwd`/cmake-3.15.5 20 | 21 | if [[ -n $1 ]] 22 | then 23 | prefix=$1 24 | fi 25 | 26 | if [[ -f $archive ]] 27 | then 28 | checksum=$(md5sum $archive | cut -d ' ' -f 1) 29 | fi 30 | 31 | if [[ ! $checksum = 35d56e9c27b4fd2819a11c29320c655a ]] 32 | then 33 | hash wget &> /dev/null && download_cmd="wget -c" 34 | hash axel &> /dev/null && download_cmd="axel -a -n 8" 35 | if [[ -z $download_cmd ]] 36 | then 37 | echo "'wget' not found for downloading" 1>&2; 38 | exit 1; 39 | fi 40 | 41 | echo "Downloading with $download_cmd..." 42 | if ! bash -c "$download_cmd $url" 43 | then 44 | echo "Download failed." 45 | exit 1 46 | fi 47 | fi 48 | 49 | set -e 50 | mkdir -p $prefix 51 | bash $archive --prefix=$prefix &> /dev/null < $prefix/bin/enable-cmake.sh < $prefix/bin/disable-cmake.sh </dev/null || { 40 | echo "'wget' not fould, please install it first" 1>&2 41 | exit 1 42 | } 43 | 44 | download_cmd="wget -c" 45 | if [[ -t 1 ]] 46 | then 47 | wget --help | grep -q '\--show-progress' && \ 48 | download_cmd="$download_cmd -q --show-progress" || \ 49 | download_cmd="$download_cmd --progress=bar:force:noscroll" 50 | else 51 | download_cmd="$download_cmd -q" 52 | fi 53 | 54 | function version_cmp { 55 | mapfile -t left < <( echo $1 | tr . '\n' ) 56 | mapfile -t right < <( echo $2 | tr . '\n') 57 | local i 58 | for i in ${!left[@]} 59 | do 60 | local lv=${left[$i]} 61 | local rv=${right[$i]} 62 | [[ -z $rv ]] && { echo $lv; return; } 63 | [[ $lv -ne $rv ]] && { echo $((lv - rv)); return; } 64 | done 65 | ((i++)) 66 | rv=${right[$i]} 67 | [[ ${#right[@]} -gt ${#left[@]} ]] && { echo $((0-rv)); return; } 68 | } 69 | 70 | # Find the maximum version not greater than the system one 71 | function select_by_version { 72 | local this_version=$1 73 | shift 1 74 | local candidates="$@" 75 | for v in $candidates 76 | do 77 | if [[ $(version_cmp $v $this_version) -le 0 ]] 78 | then 79 | echo $v 80 | break 81 | fi 82 | done 83 | } 84 | 85 | selected_libc_version=$(select_by_version $this_libc_version "${libc_preset_versions[@]}") 86 | selected_gcc_version=$(select_by_version $this_gcc_version "${gcc_preset_versions[@]}") 87 | 88 | [[ -z $selected_libc_version ]] && { 89 | echo "No prebuilt third-party found for your environment: libc-$this_libc_version, GCC-$this_gcc_version, ABI $this_abi_version" 1>&2 90 | exit 1 91 | } 92 | 93 | selected_archive=vesoft-third-party-$version-$(uname -m)-libc-$selected_libc_version-gcc-$selected_gcc_version-abi-$this_abi_version.sh 94 | 95 | url=$url_base/$selected_archive 96 | echo "Downloading $selected_archive..." 97 | $download_cmd $url 98 | [[ $? -ne 0 ]] && { 99 | echo "Downloading $selected_archive failed" 1>&2 100 | exit 1 101 | } 102 | 103 | bash $selected_archive $@ && rm -rf $selected_archive 104 | --------------------------------------------------------------------------------