vesoft-inc / nebula-go Goto Github PK
View Code? Open in Web Editor NEWNebula client in Golang
License: Apache License 2.0
Nebula client in Golang
License: Apache License 2.0
See detail in https://discuss.nebula-graph.com.cn/t/topic/3856
It seems that we don't use those thrift generated files to meta and storage in go client repo but keep updating with engine, does this make any sense?
Just as the title said, maybe we can use zap to instead the go log import ?
According to https://github.com/rs/logbench result, it shows that zap have good performance in logging.
Hi, I saw that the go client provides graph_storage_service-remote.go, which provides the kv interface, which means that I can use the kv service directly in the go client?
I write a api for executing neblua, but after some time, it's always disconnected. How to reconnect it?
my code api
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"time"
"github.com/gorilla/mux"
nebula "github.com/vesoft-inc/nebula-go/v3"
)
const (
address = "10.234.0.1"
// The default port of Nebula Graph 2.x is 9669.
// 3699 is only for testing.
port = 9669
username = "root"
password = "oksi1"
)
var pool *nebula.ConnectionPool
var session *nebula.Session
func init() {
hostAddress := nebula.HostAddress{Host: address, Port: port}
hostList := []nebula.HostAddress{hostAddress}
poolConfig := nebula.GetDefaultConf()
var err error
pool, err = nebula.NewConnectionPool(hostList, poolConfig, nebula.DefaultLogger{})
if err != nil {
log.Fatal(fmt.Sprintf("Fail to initialize the connection pool, host: %s, port: %d, %s", address, port, err.Error()))
}
session, err = pool.GetSession(username, password)
if err != nil {
log.Fatal(fmt.Sprintf("Fail to create a new session from connection pool, username: %s, password: %s, %s",
username, password, err.Error()))
}
}
func main() {
router := mux.NewRouter()
router.HandleFunc("/data", GetData).Methods("POST")
http.ListenAndServe(":8500", router)
defer pool.Close()
defer session.Release()
}
type JsonObj struct {
Results []struct {
Columns []string
Data []struct {
Row []interface{}
Meta []interface{}
}
}
Errors []struct {
Code int
Message string
}
}
// Initialize logger
var log = nebula.DefaultLogger{}
type request struct {
Query string
}
func GetData(w http.ResponseWriter, r *http.Request) {
var request request
_ = json.NewDecoder(r.Body).Decode(&request)
var err error
if err != nil {
log.Fatal(fmt.Sprintf("Fail to create a new session from connection pool, username: %s, password: %s, %s",
username, password, err.Error()))
}
jsonResult, err := session.ExecuteJson(request.Query)
if err != nil {
log.Fatal(fmt.Sprintf("fail to get the result in json format, %s", err.Error()))
}
var jsonObj JsonObj
json.Unmarshal(jsonResult, &jsonObj)
json.NewEncoder(w).Encode(jsonObj)
}
panic: runtime error: slice bounds out of range [:8192] with capacity 4096
goroutine 44 [running]:
bufio.(*Reader).Read(0xc0000323c0, 0xc000032474, 0x4, 0x4, 0x300000002, 0xc000082c00, 0xc000852e00)
/usr/local/go/src/bufio/bufio.go:238 +0x3ba
io.ReadAtLeast(0x10060a0, 0xc0000323c0, 0xc000032474, 0x4, 0x4, 0x4, 0x74, 0xc000852e60, 0x4dadb2)
/usr/local/go/src/io/io.go:328 +0x87
io.ReadFull(...)
/usr/local/go/src/io/io.go:347
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*FramedTransport).readFrameHeader(0xc000032420, 0x0, 0x7, 0x0)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/framed_transport.go:154 +0x74
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*FramedTransport).Read(0xc000032420, 0xc00016c0d2, 0x4, 0x40, 0xc00015e080, 0xc000548000, 0x74)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/framed_transport.go:80 +0x2ff
io.ReadAtLeast(0x7f62e2dc8150, 0xc000032420, 0xc00016c0d2, 0x4, 0x40, 0x4, 0x74, 0x20000, 0x74)
/usr/local/go/src/io/io.go:328 +0x87
io.ReadFull(...)
/usr/local/go/src/io/io.go:347
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*BinaryProtocol).readAll(0xc00016c090, 0xc00016c0d2, 0x4, 0x40, 0xc000548000, 0x74)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/binary_protocol.go:494 +0x5f
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*BinaryProtocol).ReadI32(0xc00016c090, 0x0, 0xec9160, 0x7f62e2fec008)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/binary_protocol.go:424 +0x48
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*BinaryProtocol).ReadMessageBegin(0xc00016c090, 0x18, 0x18, 0xe1ebc0, 0x0, 0x0)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/binary_protocol.go:241 +0x2f
github.com/facebook/fbthrift/thrift/lib/go/thrift.(*ClientConn).RecvMsg(0xc000032490, 0xeec85a, 0x7, 0x1006aa0, 0xc00000c3a8, 0x0, 0x0)
/go/pkg/mod/github.com/facebook/[email protected]/thrift/lib/go/thrift/clientconn.go:104 +0x4c
github.com/vesoft-inc/nebula-go/v2/nebula/graph.(*GraphServiceClient).recvExecute(0xc000032480, 0xeec85a, 0x7, 0x1006a40)
/go/pkg/mod/github.com/vesoft-inc/nebula-go/[email protected]/nebula/graph/graphservice.go:146 +0x75
github.com/vesoft-inc/nebula-go/v2/nebula/graph.(*GraphServiceClient).Execute(0xc000032480, 0x5d55d3e5f78c2, 0xc0000ae0f0, 0x4a, 0x50, 0x50, 0x5f, 0x0)
/go/pkg/mod/github.com/vesoft-inc/nebula-go/[email protected]/nebula/graph/graphservice.go:140 +0x10d
github.com/vesoft-inc/nebula-go/v2.(*connection).execute(0xc000116000, 0x5d55d3e5f78c2, 0xc0000ae050, 0x4a, 0xc06fbea7a74b3b37, 0x4b, 0xc00012f680)
/go/pkg/mod/github.com/vesoft-inc/nebula-go/[email protected]/connection.go:111 +0x7f
github.com/vesoft-inc/nebula-go/v2.(*Session).Execute(0xc0000760f0, 0xc0000ae050, 0x4a, 0xc0008533c0, 0x40db9b, 0xc00063a720)
/go/pkg/mod/github.com/vesoft-inc/nebula-go/[email protected]/session.go:35 +0x74`
I found the same panic from golang/go#42289, but I don't know it's the same and how to solve
Please add fetch/Go.Lookup query example to read me or documentation.
when my client request nebula server for long time, it return error for session
fail to authenticate, error: Create session failed: Unknown error!
nebula-storaged v2.6.1
nebula-graphd v2.6.1
nebula-metad v2.6.1
nebula-graph-studio v3.1.0
nebula-http-gateway v2.1.1
nebula-go v2.6.0
metad warning logs
W0614 05:04:45.844468 107 SessionManagerProcessor.cpp:56] Session id `1655183124722335' not found
W0614 05:09:06.080336 105 SessionManagerProcessor.cpp:56] Session id `1655183384989427' not found
W0614 05:19:56.704413 108 SessionManagerProcessor.cpp:56] Session id `1655184035640282' not found
W0614 05:21:06.777271 106 SessionManagerProcessor.cpp:56] Session id `1655184105714553' not found
W0614 05:21:46.824519 105 SessionManagerProcessor.cpp:56] Session id `1655184145761765' not found
W0614 05:24:47.016147 108 SessionManagerProcessor.cpp:56] Session id `1655184325959818' not found
W0614 05:25:07.037206 105 SessionManagerProcessor.cpp:56] Session id `1655184345977612' not found
W0614 05:27:07.169456 107 SessionManagerProcessor.cpp:56] Session id `1655184466088790' not found
W0614 05:34:07.615229 107 SessionManagerProcessor.cpp:56] Session id `1655184886565665' not found
W0614 05:36:17.764503 108 SessionManagerProcessor.cpp:56] Session id `1655185016713685' not found
graphd warning logs
E0614 05:24:47.016408 16 GraphSessionManager.cpp:205] Update sessions failed: Session not existed!
E0614 05:24:47.016480 18 GraphSessionManager.cpp:229] Update sessions failed: Update sessions failed: Session not existed!
E0614 05:25:07.037410 13 GraphSessionManager.cpp:205] Update sessions failed: Session not existed!
E0614 05:25:07.037528 18 GraphSessionManager.cpp:229] Update sessions failed: Update sessions failed: Session not existed!
E0614 05:27:07.169734 15 GraphSessionManager.cpp:205] Update sessions failed: Session not existed!
E0614 05:27:07.169849 18 GraphSessionManager.cpp:229] Update sessions failed: Update sessions failed: Session not existed!
E0614 05:34:07.615523 15 GraphSessionManager.cpp:205] Update sessions failed: Session not existed!
E0614 05:34:07.615622 18 GraphSessionManager.cpp:229] Update sessions failed: Update sessions failed: Session not existed!
E0614 05:36:17.764770 15 GraphSessionManager.cpp:205] Update sessions failed: Session not existed!
E0614 05:36:17.764878 18 GraphSessionManager.cpp:229] Update sessions failed: Update sessions failed: Session not existed!
i restart my client can solve the problem,
Lines 77 to 80 in 4f76b90
If the session is nil, there will be panic.
Hello
Using go 1.18, I am able to install with success this module via go get
. However if I try to run the tests for this particular repository via make test
(using master) I got this:
$ make test
go mod tidy
github.com/vesoft-inc/nebula-go/v3/nebula/graph/graph_service-remote imports
../../github.com/vesoft-inc/nebula-go/v3/nebula/graph: "../../github.com/vesoft-inc/nebula-go/v3/nebula/graph" is relative, but relative import paths are not supported in module mode
github.com/vesoft-inc/nebula-go/v3/nebula/meta/meta_service-remote imports
../../github.com/vesoft-inc/nebula-go/v3/nebula/meta: "../../github.com/vesoft-inc/nebula-go/v3/nebula/meta" is relative, but relative import paths are not supported in module mode
github.com/vesoft-inc/nebula-go/v3/nebula/storage/graph_storage_service-remote imports
../../github.com/vesoft-inc/nebula-go/v3/nebula/storage: "../../github.com/vesoft-inc/nebula-go/v3/nebula/storage" is relative, but relative import paths are not supported in module mode
make: *** [Makefile:10: test] Error 1
The issue is about this line:
also
It seems an easy thing to fix (just remove the ../.. in the import), however this code is Autogenerated by Thrift Compiler.
Since this is an issue with how the latest versions of go handle the module versus gopath mode and I did not find an easy command line option to fix it, I search and see that the tests are running using go 1.13 - last released was on 2020-08-06. It is no longer support.
Use make test
using the current go version available is something that 99% of the people who wants to contribute will do. If there is a specific requirement to run tests will be nice add a note (or add a section / page about this).
Questions
Thanks
Although i'm updateted go version to 1.55.11, but still using go vendor, i'm getting error when run my code local as follow:
cannot find package "github.com/vesoft-inc/nebula-go/v2" in any of: /Users/xxx/go/src/gitlab.xxx.com/xxx/my-proj/vendor/github.com/vesoft-inc/nebula-go/v2 (vendor tree) /usr/local/Cellar/go/go1.15.11/src/github.com/vesoft-inc/nebula-go/v2 (from $GOROOT) /Users/xxx/go/src/github.com/vesoft-inc/nebula-go/v2 (from $GOPATH)
so, i'm still want to use govendor to manage my go repo
but how can i do to avoid this error when using v2.0.0-ga branch ?
thx
Hi everyone, I have write a orm library support nebula write by go, now it's feature like this
Now i am test it in we production, and it will be a Open Compute Project in one or two weeks later.
There are some example:
// init
func main() {
dalector := norm.MustNewDialector(norm.DialectorConfig{
Addresses: []string{"127.0.0.1:9669"},
Timeout: time.Second * 5,
})
db := norm.MustOpen(dalector, norm.Config{
Space: "test",
Username: "test",
Password: "test",
})
run(db)
}
func insertVertex(db *norm.DB) {
user := &examples.User{
VModel: norm.VModel{
Vid: "user_101",
},
ID: 101,
Created: 101,
}
err := db.Debug().InsertVertex(user)
if err != nil {
log.Errorf(context.TODO(), "insert %+v error: %v", user, err)
panic(err)
}
}
func insertEdge(db *norm.DB) {
vote := &examples.AnswerVoteUp{
EModel: norm.EModel{
Src: "user_101",
Dst: "answer_102",
},
VoteUpCnt: 101,
Created: 100000,
}
err := db.Debug().InsertEdge(vote)
if err != nil {
log.Errorf(context.TODO(), "insert %+v error: %v", vote, err)
panic(err)
}
}
func matchSingle(db *norm.DB) {
nsql := "match(v:user) where id(v)=='user_101' return v.id as id,v.created as created"
user := examples.User{}
err := db.Debug().ExecuteAndParse(nsql, &user)
if err != nil {
log.Errorf(context.TODO(), "exec %s error: %v", nsql, err)
panic(err)
}
log.Infof(context.TODO(), "%+v", user)
}
(forgive my pool english
Originally posted by @everywan in #111 (comment)
Didn't look into the code seriously, just an brief look, and lots of bad thoughts. I can say the code looks substandard, it is probably the worst I have seen in a year.
gofmt
. In case you didn't like it – just set up your editor to show 2 spaces instead of tabs.pkg.subpkg.subsubpkg
thing. graph
variable is precious, don't pollute the scope with unneeded packages. Put everything into one.As I said, I didn't really look into the code. But the on in README.md is dubious
resp, err := client.Execute("SHOW HOSTS;")
if err != nil {
log.Fatal(err)
}
if resp.GetErrorCode() != graph.ErrorCode_SUCCEEDED {
log.Printf("ErrorCode: %v, ErrorMsg: %s", resp.GetErrorCode(), resp.GetErrorMsg())
}
Is really poor. You don't need to put errors into a response when you can put them into a custom error implementation. Something like
type ResponseError struct {
code Code
msg string
}
func (e *ResponseErrror) Error() string {
return fmt.Sprintf("%s: %s", e.code, e.msg)
}
func AsResponseError(err error) *ResponseError {
var target *ResponseError
if errors.As(err, &target) {
return target
}
return nil
}
will do the job in a way how it is done in Go:
resp, err := client.Execute("SHOW HOSTS;")
if err != nil {
if err := ndbg.AsResponseError {
log.Printlf(…)
return
}
log.Fatal(err)
}
This is far more idiomatic Go.
Hi, no offence, but your code is utterly non-idiomatic. Completely not up to the DB itself: I like Nebula, but your Go code – not so much. I will split issues into two kinds:
It is not formatted with gofmt. I understand you may not like formatting with tabs, but this is how it is written in Go. Please apply gofmt and set up your editor to apply it on save. This is very basic, code formatted like yours will be immediately rejected if you would try to contribute in any barely decent project.
Library layout. It is not recommended in Go to split public functionality in different packages as it makes totally unclear what repo this package belongs to, as Go does not have nested namespaces. Use prefixes in a single package instead. You may split a functionality into different packages, but makes this in internal
folder of you package to hide them away from outer users and use type aliases type ClientConnection = client.Connection
and wrap function calls in the package itself:
…
import "github.com/vesoft-inc/internal/client"
type Client = client.Client
func NewClient(addr string) (Client, error) {
return client.New(addr)
}
There're 3 popular logging options in Go:
Stdlib logger is not really a common option in any half-serious project. one of these three is typically a better pick. I mean, a project using your DB is likely to be a part of large infrastructure and they are very likely to use structured logging any of these packages provide. Your logging not only will be alien, the lines printed in stdlib logger will likely be missing important things like trace-request-id
, etc. You should not use logging in packages and should return errors instead which will be printed with a logger of choice.
Error processing is totally off.
Splitting error processing into two parts is insane for public API. You should wrap response errors in Go error
. Just implement your own error type and do response processing yourself:
type ErrorResponse struct {
code graph.ErrorCode
msg string
}
func newErrorResponse(code *graph.ErrorCode, msg string) *ErrorResponse {
return &ErrorResponse{
code: code,
msg: msg,
}
}
func (e *ErrorResponse) Error() string {
return fmt.Sprintf("%s: %s", e.code, e.msg)
}
…
// hijack response error in Execute method
if IsError(resp) {
return nil, newErrorResponse(resp.GetErrorCode(), resp.GetErrorMsg())
}
Go users will be able to understand if it is some low level network error or Nebula error with errors.As(err, &errRespVar)
if needed (I doubt if it is really needed though)
You should use errors wrapping instead of logging:
if err != nil {
log.Printf("failed to do something: %s", err)
return
}
if err != nil {
return fmt.Errorf("do something: %w", err)
}
In the end users will have error chain annotated with steps what lead to the error. They will be able to extract root error with errors.As
if needed. The error text itself will be self-explaining, showing a chain and error context what you can put in an error.
Hi,
I am using golang 17 and nebula-go 2.5.1 versions
In other go-clients when we query data we can load that into a struct.
result, err := client.Execute(query)
result.Scan(&struct)
But here I can see the data is returned as string type.
// Get a row from resultSet
record, err := resultSet.GetRowValuesByIndex(0)
if err != nil {
log.Error(err.Error())
}
// Print whole row
fmt.Println("The first row elements: \n", record.String())
If there is a way please document it or point me to that documentation link.
Thanks,
Akhil
I only find two samples in basic_example/goroutine_example and there is barely parse resultSet demo? is this possible to provide parse method for result or add more cases?
❯ go get -v github.com/vesoft-inc/nebula-go/[email protected]
go: downloading github.com/vesoft-inc/nebula-go/v2 v2.5.0
go get: github.com/vesoft-inc/nebula-go/[email protected]: verifying module: checksum mismatch
downloaded: h1:7w3bUYTAtvEA20go5XFoEDx5HbnzlOgo5VBSP3AvXtE=
sum.golang.org: h1:A4wZoGqR1W1mQ9y/X+tV1wCMIsDkuhFMthTQKMeT8Yc=
SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.
For more information, see 'go help module-auth'.
maybe the thrift version not match?
刚启动服务时一起正常,等待一天后,就会出现错误,重启服务后又正常了。刚开始以为是go客户端版本太低了(之前是3.0),后面又升级到了最新的3.1,还是有问题。
nebula.go 代码
func NewDbSession() *nebula.Session {
session, err := pool.GetSession(nebulaOpt.Username, nebulaOpt.Password)
if err != nil {
panic(fmt.Sprintf("获取sesion失败, %s", err.Error()))
}
session.Execute("use " + nebulaOpt.Space)
return session
}
session := db.NewDbSession()
_s.Insert(session)
session.Release()
panic
Error: 获取sesion失败, fail to authenticate, error: The version of the client sending request from "x.x.x.x":64950 is lower than v2.6.0, please update the client.
go.mod
require (
github.com/vesoft-inc/nebula-go/v3 v3.1.0
google.golang.org/protobuf v1.28.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
docker ps
b46cc2ff0901 vesoft/nebula-graph-studio:v3.2.3 "./server" 13 days ago Up 13 days 0.0.0.0:7001->7001/tcp, :::7001->7001/tcp nebula-studio_web_1
6d7aa8435117 vesoft/nebula-console:v3.0.0 "sh -c 'sleep 3 \n'" 13 days ago Exited (0) 13 days ago nebula-docker-compose_console_1
88ffa08610dd vesoft/nebula-graphd:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 0.0.0.0:49178->9669/tcp, :::49178->9669/tcp, 0.0.0.0:49177->19669/tcp, :::49177->19669/tcp, 0.0.0.0:49175->19670/tcp, :::49175->19670/tcp nebula-docker-compose_graphd2_1
132e43918916 vesoft/nebula-graphd:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 0.0.0.0:49176->9669/tcp, :::49176->9669/tcp, 0.0.0.0:49174->19669/tcp, :::49174->19669/tcp, 0.0.0.0:49173->19670/tcp, :::49173->19670/tcp nebula-docker-compose_graphd1_1
bbeefd74a112 vesoft/nebula-graphd:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 0.0.0.0:9669->9669/tcp, :::9669->9669/tcp, 0.0.0.0:49172->19669/tcp, :::49172->19669/tcp, 0.0.0.0:49171->19670/tcp, :::49171->19670/tcp nebula-docker-compose_graphd_1
f570f61a89ef vesoft/nebula-storaged:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9777-9778/tcp, 9780/tcp, 0.0.0.0:49164->9779/tcp, :::49164->9779/tcp, 0.0.0.0:49163->19779/tcp, :::49163->19779/tcp, 0.0.0.0:49162->19780/tcp, :::49162->19780/tcp nebula-docker-compose_storaged0_1
c46dda48a551 vesoft/nebula-storaged:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9777-9778/tcp, 9780/tcp, 0.0.0.0:49170->9779/tcp, :::49170->9779/tcp, 0.0.0.0:49169->19779/tcp, :::49169->19779/tcp, 0.0.0.0:49167->19780/tcp, :::49167->19780/tcp nebula-docker-compose_storaged1_1
caa38fdfa2b8 vesoft/nebula-storaged:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9777-9778/tcp, 9780/tcp, 0.0.0.0:49168->9779/tcp, :::49168->9779/tcp, 0.0.0.0:49166->19779/tcp, :::49166->19779/tcp, 0.0.0.0:49165->19780/tcp, :::49165->19780/tcp nebula-docker-compose_storaged2_1
2fa3f79d51c4 vesoft/nebula-metad:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9560/tcp, 0.0.0.0:49161->9559/tcp, :::49161->9559/tcp, 0.0.0.0:49160->19559/tcp, :::49160->19559/tcp, 0.0.0.0:49158->19560/tcp, :::49158->19560/tcp nebula-docker-compose_metad0_1
1c981509fd0c vesoft/nebula-metad:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9560/tcp, 0.0.0.0:49156->9559/tcp, :::49156->9559/tcp, 0.0.0.0:49154->19559/tcp, :::49154->19559/tcp, 0.0.0.0:49153->19560/tcp, :::49153->19560/tcp nebula-docker-compose_metad1_1
ce6a83da43c1 vesoft/nebula-metad:v3.0.1 "/usr/local/nebula/b…" 13 days ago Up 13 days (healthy) 9560/tcp, 0.0.0.0:49159->9559/tcp, :::49159->9559/tcp, 0.0.0.0:49157->19559/tcp, :::49157->19559/tcp, 0.0.0.0:49155->19560/tcp, :::49155->19560/tcp nebula-docker-compose_metad2_1
服务器部分日志
[2022/04/27 04:27:51] [application] [^[[32mINFO^[[0m] [domain.go:40,Init] ^[[32mtoken初始化完成^[[0m
[2022/04/27 04:27:51] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc00000c0d0) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 04:27:51] [application] [^[[32mINFO^[[0m] [domain.go:42,Init] ^[[32m邮箱初始化完成^[[0m
[2022/04/27 04:27:51] [application] [^[[32mINFO^[[0m] [domain.go:44,Init] ^[[32mSession初始化完成^[[0m
[2022/04/27 04:27:51] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc00000c0d0) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 04:28:42] [application] [TRACE] [bus.go:68,Exec] 0xc00000e030(ret:0xc00000e040) Exec事件: &{Inner:{} current:0 interval:0}
......
[2022/04/27 12:24:28] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc0000a40a0) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:24:56] [application] [TRACE] [bus.go:68,Exec] 0xc00000e008(ret:0xc00000e010) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:24:56] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc0000a4100) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:24:56] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc0000a4100) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:25:52] [application] [TRACE] [bus.go:68,Exec] 0xc0000ac048(ret:0xc0000ac050) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:25:52] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc0000a4778) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:25:52] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc0000a4778) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:26:44] [application] [TRACE] [bus.go:68,Exec] 0xc0000ac058(ret:0xc0000ac060) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:26:44] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc0000a4a60) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:26:44] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc0000a4a60) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:27:28] [application] [TRACE] [bus.go:68,Exec] 0xc00000e008(ret:0xc00000e010) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:27:28] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc00000c4d8) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:27:28] [application] [TRACE] [bus.go:156,1] 0xc0000ac6c0(ret:0xc00000c4d8) 处理事件结束: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:27:56] [application] [TRACE] [bus.go:68,Exec] 0xc00000e018(ret:0xc00000e020) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:27:56] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc0000a40a0) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:27:56] [application] [^[[35mERROR^[[0m] [bus.go:148,1] ^[[35m
Error: 获取sesion失败, fail to authenticate, error: The version of the client sending request from "35.172.193.194":53092 is lower than v2.6.0, please update the client.
goroutine 21 [running]:
runtime/debug.Stack()
C:/Users/username/sdk/go1.18/src/runtime/debug/stack.go:24 +0x65
github.com/userproject/ddd/event.(*bus).Run.func1.1.1()
C:/Users/username/project/userproject/ddd/event/bus.go:148 +0x3d
panic({0xa55f60, 0xc0001fd320})
C:/Users/username/sdk/go1.18/src/runtime/panic.go:838 +0x207
hello.com/jing/project/server/db.NewDbSession()
C:/Users/username/project/userproject/project/server/db/nebula.go:82 +0x174
hello.com/jing/project/server/domain.(*platform).genSysOrder(0xc0001e0720)
C:/Users/username/project/userproject/project/server/domain/platform_gen_order.go:61 +0x467
hello.com/jing/project/server/domain.(*platform_mgr).genSysOrder(...)
C:/Users/username/project/userproject/project/server/domain/platform_gen_order.go:91
hello.com/jing/project/server/domain.(*platform_mgr).init.func1({0xb174a0?, 0xc000081680?}, {0xc1b798?, 0xc0002ce0b0?}, 0x32000095ed8?)
C:/Users/username/project/userproject/project/server/domain/platform_mgr.go:40 +0x94
github.com/userproject/ddd/event.(*handler).Exec(0xc0001cf200, {0xb174a0, 0xc000081680}, {0xc1b798?, 0xc0002ce0b0?}, 0x5?)
C:/Users/username/project/userproject/ddd/event/hander.go:135 +0x472
github.com/userproject/ddd/event.(*bus).Run.func1.1(0xc0000ac6c0, {0xb174a0, 0xc000081680})
C:/Users/username/project/userproject/ddd/event/bus.go:155 +0x325
github.com/userproject/ddd/event.(*bus).Run.func1()
C:/Users/username/project/userproject/ddd/event/bus.go:165 +0x34
created by github.com/userproject/ddd/event.(*bus).Run
C:/Users/username/project/userproject/ddd/event/bus.go:142 +0xe5
^[[0m
[2022/04/27 12:28:52] [application] [TRACE] [bus.go:68,Exec] 0xc00000e008(ret:0xc00000e010) Exec事件: &{Inner:{} current:0 interval:0}
[2022/04/27 12:28:52] [application] [TRACE] [bus.go:154,1] 0xc0000ac6c0(ret:0xc0000a40a0) 处理事件开始: inner[3307](&{Inner:{} current:0 interval:0})
[2022/04/27 12:28:52] [application] [^[[35mERROR^[[0m] [bus.go:148,1] ^[[35m
Error: 获取sesion失败, fail to authenticate, error: The version of the client sending request from "35.172.193.194":53090 is lower than v2.6.0, please update the client.
goroutine 21 [running]:
runtime/debug.Stack()
C:/Users/username/sdk/go1.18/src/runtime/debug/stack.go:24 +0x65
github.com/userproject/ddd/event.(*bus).Run.func1.1.1()
C:/Users/username/project/userproject/ddd/event/bus.go:148 +0x3d
panic({0xa55f60, 0xc000211520})
C:/Users/username/sdk/go1.18/src/runtime/panic.go:838 +0x207
hello.com/jing/project/server/db.NewDbSession()
C:/Users/username/project/userproject/project/server/db/nebula.go:82 +0x174
hello.com/jing/project/server/domain.(*platform).genSysOrder(0xc0001e0720)
The design of this client library seems unusual to me as querying requires checking two sources for error instead of an expected single source.
The documentation checks err
from client.Execute() as well as nebula.IsError(resp)
such as in the following code from the readme.
resp, err := client.Execute("SHOW HOSTS;")
if err != nil {
log.Fatal(err)
}
if nebula.IsError(resp) {
log.Printf("ErrorCode: %v, ErrorMsg: %s", resp.GetErrorCode(), resp.GetErrorMsg())
}
Why are two sources of error checking done and not one?
My expectation would be a single check such as;
resp, err := client.Execute("SHOW HOSTS;")
if err != nil {
log.Printf("ErrorCode: %v, ErrorMsg: %s", resp.GetErrorCode(), resp.GetErrorMsg())
}
IdleTimeout for connection pools doesn't seem to be implemented, are there any plans to implement it or can I provide a rough implementation?
使用ExecuteWithParameter插入点, 报错。
代码如下:
guild_vid := "guild_11"
params := make(map[string]interface{})
params["p2"] = 111
nGql := fmt.Sprintf(`INSERT VERTEX guild (code) VALUES "%s":($p2);`, guild_vid)
resultSet, err := session.ExecuteWithParameter(nGql, params)
报错如下:
ErrorMsg: Storage Error: The data type does not meet the requirements. Use the correct type of data.
schame如下:
CREATE TAG IF NOT EXISTS guild (
code int NOT NULL DEFAULT 0 COMMENT '',
open_id int NOT NULL DEFAULT 0 COMMENT '',
custom_id string NOT NULL DEFAULT '' COMMENT '',
name string NOT NULL DEFAULT '' COMMENT '',
status int NOT NULL DEFAULT 0 COMMENT ''
)
COMMENT = 'xxx';
nebula-go/nebula/meta/ttypes.go
Line 2164 in 9461e07
Now I can only build query from raw string, but it's unsafe for online service because it may accept some invalid input.
Is there a tool that I can use it to build query safely
I find some invalid implement in session pool, could you please take a look at them and I am willing to fix them when they are really invalid.
Line 301 in f38f53c
Line 118 in f38f53c
Line 124 in f38f53c
Line 129 in f38f53c
Line 308 in f38f53c
Line 316 in f38f53c
Line 320 in f38f53c
Line 340 in f38f53c
go get 2.0 时, 报错.
命令以及报错详情
$ go get -v github.com/vesoft-inc/[email protected]
go get github.com/vesoft-inc/[email protected]: github.com/vesoft-inc/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2
查阅文档可知, go 官方推荐在 v2 及更高版本中, 使用 {path}/v2
的方式, 从而管理多个版本. 参考文档: Go Modules: v2 and Beyond
如何解决
module github.com/vesoft-inc/nebula-go/v2
.如何复现
unset GOPROXY
go get -v github.com/vesoft-inc/[email protected]
其他仓库的参考示例
go version go1.13.5 linux/amd64
go.mod:
go 1.13
require (
github.com/vesoft-inc/nebula-go v2.0.0-ga
)
Error:
require github.com/vesoft-inc/nebula-go: version "v2.0.0-ga" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2
client.go::Connect function do not check the error code of AuthResponse, and use invalid sessionId for subsequent query.
report connect failed error (Bad username/password)
In java client, user can use a session manager to specify SPACE when getting a session, so why go-client doesn't support that feature, since it's maybe a common requirement of client.
SessionsManagerConfig config = new SessionsManagerConfig();
NebulaPoolConfig poolConfig = new NebulaPoolConfig();
poolConfig.setMaxConnSize(4);
config.setAddresses(Collections.singletonList(
new HostAddress("127.0.0.1", 9670)))
.setUserName("root")
.setPassword("nebula")
.setSpaceName("space")
.setPoolConfig(poolConfig);
SessionsManager sessionsManager = new SessionsManager(config);
// Gets the session of the specified space
SessionWrapper session = sessionsManager.getSessionWrapper();
ResultSet resultSet = session.execute("......");
vendor/github.com/vesoft-inc/nebula-go/v3/nebula/meta/ttypes.go:2526:3: cannot use &const_lit_vid_type_type_length (type *int16) as type int16 in field value
var SpaceDesc_VidType_DEFAULT *ColumnTypeDef = &ColumnTypeDef{
Type: 7,
TypeLength: &const_lit_vid_type_type_length,
}
➜ nebula-console git:(master) ./nebula-console -u root -p nebula --address localhost --port 9669
2021/11/10 15:12:07 [INFO] connection pool is initialized successfully
2021/11/10 15:12:07 Fail to create a new session from connection pool, Failed to create a net.Conn-backed Transport,: address ::1:9669: too many colons in address
panic: Fail to create a new session from connection pool, Failed to create a net.Conn-backed Transport,: address ::1:9669: too many colons in address
如何查询全部的点和边以及他们的属性
as title, we are missing this, could we consider implementing go-sclient?
There is a lot of errors of 'write: broken pipe' when the first time invoke SessionPool.Execute after a long idle time.
nebula-go version: v3.3.0
when session expired ,service return code -5. but in this link https://github.com/vesoft-inc/nebula-go/blob/master/nebula/ttypes.go ErrorCode_E_SESSION_INVALID ErrorCode = -1002
用的v3.0.0版本,找不到原因
原生语句如下:
INSERT VERTEX guild (code, open_id, custom_id, name, status)
VALUES "guild_1051":(3919530414697626, 0, "", "111222的服务器aa\", 0);
使用studio能成功执行,使用go客户端就报下面的错误。
{"level":"fatal","msg":"INSERT VERTEX guild (code, open_id, custom_id, name, status)\n\tVALUES \"guild_1051\":(3919530414697626, 0, \"\", \"111222的服务器aa\\\", 0);, ErrorCode: -1004, ErrorMsg: SyntaxError: Unterminated string: near `us)\n\t'","time":"2022-06-01 19:29:02"}
considering 1 situation:
when one graph shutdown, then sessions connected to this graph will reconnect to others. if session pool is never updated, this graph will never be used although it maybe be recovered lately. and this case is regular when upgrading graph.
if this is true, maybe we should enhance the load balancer in session pool or connection pool. for example, we can build a map with key=address, val=sessions to it, define min/max session size to each address and then update session to each address timely?
Now when we want to execute a stmt, We need to use string formatting to write an stmt like this
sess.Execute(fmt.Sprintf("INSERT VERTEX t2 (name, age) VALUES \"11\":(\"%s\", %d);", name, age))
or just splice string like
stmt := "INSERT VERTEX t2 (name, age) VALUES \"11\":(\""+name+"\","+strconv.Itoa(age)+");"
sess.Execute(stmt)
this is not a good way to deal with.
sess.Execute("INSERT VERTEX t2 (name, age) VALUES \"11\":({name},{age});",map[string]interface{"name":name,"age":age})
sess.Execute("INSERT VERTEX t2 (time) VALUES \"11\":({time});",map[string]interface{"time":TimeOf(t)})
INSERT VERTEX t2 (time) VALUES "11":(time("17:53:59"));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.