krotik / eliasdb

EliasDB a graph-based database.
Mozilla Public License 2.0
994 stars 49 forks source link

Panic in cluster manager #20

Closed beoran closed 4 years ago

beoran commented 4 years ago

When performing the following rest query to an eliasdb running in clustered mode with 2 node:

curl -X POST "https://127.0.0.1:9090/db/v1/graph/my_database/n" -H  "accept: application/json" -H  "Content-Type: application/json" -d "[  {     \"key\": \"3\",     \"kind\": \"Upload\",     \"parcel\": \"12345\"  }]"

I get the following panic:

2019/12/09 08:39:47 http: panic serving 127.0.0.1:52704: interface conversion: interface {} is int, not uint64
goroutine 5100 [running]:
net/http.(*conn).serve.func1(0xc00015e6e0)
        /usr/local/go/src/net/http/server.go:1769 +0x139
panic(0x972200, 0xc000704990)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
devt.de/krotik/eliasdb/cluster.(*DistributedStorageManager).insertOrUpdate(0xc0007044e0, 0x1, 0x0, 0x963260, 0xc000134400, 0x0, 0x0, 0x0)
        /go/code/cluster/distributedstoragemanager.go:195 +0x7c1
devt.de/krotik/eliasdb/cluster.(*DistributedStorageManager).Insert(0xc0007044e0, 0x963260, 0xc000134400, 0xc000348800, 0xc000026740, 0x30)
        /go/code/cluster/distributedstoragemanager.go:135 +0x4d
devt.de/krotik/eliasdb/hash.NewHTree(0xb31fa0, 0xc0007044e0, 0x0, 0x0, 0x0)
        /go/code/hash/htree.go:128 +0x1c6
devt.de/krotik/eliasdb/graph.(*Manager).getHTree(0xc00010afc0, 0xb31fa0, 0xc0007044e0, 0x2, 0xb31fa0, 0xc0007044e0, 0x8)
        /go/code/graph/helpers.go:434 +0x6c
devt.de/krotik/eliasdb/graph.(*Manager).getIndexHTree(0xc00010afc0, 0xc000686260, 0x9, 0xc0002f05f4, 0x6, 0xc000686201, 0x9fd619, 0x4, 0xa00bba, 0x8, ...)
        /go/code/graph/helpers.go:321 +0x1e4
devt.de/krotik/eliasdb/graph.(*Manager).getNodeIndexHTree(...)
        /go/code/graph/helpers.go:283
devt.de/krotik/eliasdb/graph.(*baseTrans).commitNodes(0xc00012f9c0, 0xc000704330, 0xc000704360, 0xc00065ba48, 0x814329)
        /go/code/graph/trans.go:333 +0x2b9
devt.de/krotik/eliasdb/graph.(*baseTrans).Commit(0xc00012f9c0, 0x0, 0x0)
        /go/code/graph/trans.go:272 +0x19d
devt.de/krotik/eliasdb/api/v1.(*graphEndpoint).handleGraphRequest(0xc000136f60, 0xb2a520, 0xc000668460, 0xc000130f00, 0xc000259860, 0x2, 0x2, 0xa83258, 0xa83260)
        /go/code/api/v1/graph.go:384 +0x530
devt.de/krotik/eliasdb/api/v1.(*graphEndpoint).HandlePOST(0xc000136f60, 0xb2a520, 0xc000668460, 0xc000130f00, 0xc000259860, 0x2, 0x2)
        /go/code/api/v1/graph.go:278 +0x89
devt.de/krotik/eliasdb/api.RegisterRestEndpoints.func1.1(0xb2a520, 0xc000668460, 0xc000130f00)
        /go/code/api/rest.go:159 +0x2b2
net/http.HandlerFunc.ServeHTTP(0xc000102620, 0xb2a520, 0xc000668460, 0xc000130f00)
        /usr/local/go/src/net/http/server.go:1995 +0x44
net/http.(*ServeMux).ServeHTTP(0xed7820, 0xb2a520, 0xc000668460, 0xc000130f00)
        /usr/local/go/src/net/http/server.go:2375 +0x1d6
net/http.serverHandler.ServeHTTP(0xc0001cea90, 0xb2a520, 0xc000668460, 0xc000130f00)
        /usr/local/go/src/net/http/server.go:2774 +0xa8
net/http.(*conn).serve(0xc00015e6e0, 0xb2b8e0, 0xc00012f740)
        /usr/local/go/src/net/http/server.go:1878 +0x851
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2884 +0x2f4

Looking at the code, I'd say that either sendDataRequest should return an uint64 always, or, insertOrUpdate should expect to receive non-int64 integers. If possible, the first solution would proably be better, since the empty interface in Go can lead to reduced performance.

krotik commented 4 years ago

The bug should now be fixed. I've added also a proper clustering example. I've opted for the second options as changing the interface would require much more refactoring. Thanks again for finding this.