tarantool / go-tarantool

Tarantool 1.10+ client for Go language
https://pkg.go.dev/github.com/tarantool/go-tarantool/v2
BSD 2-Clause "Simplified" License
180 stars 57 forks source link

Can't get space length via tarantool.crud #394

Closed Vlad97vsv closed 4 months ago

Vlad97vsv commented 4 months ago

Can't get space length via crud.len

I get an error: array len doesn't match: 1

db - is connected ConnectionPool

func getLen() uint64 {
    space := "test_space"
    req := tarantoolcrud.MakeLenRequest(space)
    data := tarantoolcrud.LenResult{}
    if err := db.Do(req, tarantoolpool.ANY).GetTyped(&data); err != nil {
        panic(err)
    }
    fmt.Println(data.Value)
    return data.Value
}

>>> panic: array len doesn't match: 1

When I use Count query everything is ok.

func getCount() uint64 {
    space := "test_space"
    req := tarantoolcrud.MakeCountRequest(space)
    data := tarantoolcrud.CountResult{}
    if err := db.Do(req, tarantoolpool.ANY).GetTyped(&data); err != nil {
        panic(err)
    }
    fmt.Println(data.Value)
    return data.Value
}
`>>> 10000`

If you look at what arrives, you can see that only 1 entry in the array arrives for crud.len. And for count there are 2 entries:

func (r *MetaTntRepositoryVShard) getCount2() {
    space := "test_space"
    req := crud.MakeCountRequest(space)
    if data, err := db.Do(req, tarantoolpool.ANY).Get(); err != nil {
        panic(err)
    } else {
        fmt.Printf("%+v\n", data)
    }
}
image

The error occurs precisely during serialization. Therefore the code below works

func (r *MetaTntRepositoryVShard) getLen2() {
    space := "test_space"
    req := crud.MakeLenRequest(space)
    if data, err := db.Do(req, tarantoolpool.ANY).Get(); err != nil {
        panic(err)
    } else {
        fmt.Printf("%+v\n", data)
    }
}
image

Crud is installed, everything works correctly via tarantoolctl crud.len works.


The error seems clear, but I can’t understand why tarantool returns 1 field when asking for length.


golang version: 1.21.1 lib: go-tarantool/v2 2.0.0 OS: MacOs tarantool version: 2.11

DifferentialOrange commented 4 months ago

The error seems clear, but I can’t understand why tarantool returns 1 field when asking for length.

To be honest, it's more weird that every (or almost every) other method returns explicit result, nil in case of success.

oleg-jukovec commented 4 months ago

Thank you for the issue, are you sure that go-tarantool version is exactly v2.0.0? It should be fixed with: https://github.com/tarantool/go-tarantool/commit/c3ba5b59b7d1d7fdedba1e914925abe7d6b1c77d

Please, write a crud version because I can’t reproduce the problem. It works fine for me:

// ExampleLenRequest demonstrates how to execute a LenRequest.
func ExampleLenRequest() {
    conn := exampleConnect()
    req := crud.MakeLenRequest(exampleSpace)

    ret := crud.LenResult{}
    if err := conn.Do(req).GetTyped(&ret); err != nil {
        fmt.Printf("Failed to execute request: %s", err)
        return
    }

    fmt.Println(ret.Value)
    // Output:
    // 4
}

Please, make sure that go-tarantool version is release and v2.0.0 at least (or you could use v2.1.0 to make sure).

Vlad97vsv commented 4 months ago

I use github.com/tarantool/go-tarantool/v2 v2.0.0-20230823074441-d8df65dcd0f2.


Thank you. I'll try to update to 2.1.0 and will be back with feedback

Vlad97vsv commented 4 months ago

With the update to version 2.1.0 the problem disappeared.

Thank you very much for the quick response