codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.62k stars 343 forks source link

SELECT after INSERT in transaction (regression) #1854

Closed SimoneLazzaris closed 11 months ago

SimoneLazzaris commented 12 months ago

What happened Pattern to trigger the bug is

The SELECT returns 0 rows.

What you expected to happen

In immudb 1.5.0 the SELECT returned the inserted row.

How to reproduce it (as minimally and precisely as possible)

You can use this simple code to check

package main

import (
    "context"
    "fmt"
    "math/rand"
    "time"

    immuclient "github.com/codenotary/immudb/pkg/client"
)

func init() {
    rand.Seed(time.Now().UnixNano())
}

var letters = []rune("abcdefghijklmnopqrstuvwxyz")

func rndString(n int) string {
    b := make([]rune, n)
    for i := range b {
        b[i] = letters[rand.Intn(len(letters))]
    }
    return string(b)
}
func main() {
    ctx := context.Background()
    client := immuclient.NewClient()
    err := client.OpenSession(ctx, []byte("immudb"), []byte("immudb"), "defaultdb")
    if err != nil {
        panic("Failed to open session: " + err.Error())
    }
    tabName := rndString(12)
    q := fmt.Sprintf("CREATE TABLE %s (id INTEGER AUTO_INCREMENT, tester VARCHAR[10], PRIMARY KEY id)", tabName)
    fmt.Println(q)
    client.SQLExec(ctx, q, nil)
    tx, err := client.NewTx(ctx)
    if err != nil {
        panic("Failed to open session: " + err.Error())
    }
    q = fmt.Sprintf("INSERT INTO %s(tester) values ('123')", tabName)
    fmt.Println(q)
    tx.SQLExec(ctx, q, nil)
    q = fmt.Sprintf("SELECT * from %s", tabName)
    fmt.Println(q)
    resp, err := tx.SQLQuery(ctx, q, nil)
    fmt.Printf("%+v", resp)
    tx.Commit(ctx)

}

Environment

# run "immu* version" and copy/paste the output here
immudb 1.9DOM.0
Commit  : 91a30ecf54cb7407626af94ef3183b07c1616539
Built by: slazzaris@gmail.com
Built at: Fri, 27 Oct 2023 11:49:04 CEST

Additional info (any other context about the problem)