Skip to content

Key commited in a transaction is not visible in the next transaction #1912

@mitar

Description

@mitar

What happened

I made a transaction and committed a value under a key. In the next transaction that key is not visible. But it is visible outside of the transaction (when using db.Get).

What you expected to happen

I expect that committed data is available in transactions.

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

package main

import (
	"context"
	"log"

	"github.com/codenotary/immudb/embedded/appendable"
	"github.com/codenotary/immudb/embedded/store"
)

func main() {
	opts := store.DefaultOptions()
	opts = opts.WithSyncFrequency(0)
	opts = opts.WithCompressionFormat(appendable.NoCompression)
	db, err := store.Open("/tmp/data", opts)
	if err != nil {
		log.Fatal(err)
	}

	defer db.Close()

	tx, err := db.NewTx(context.Background(), &store.TxOptions{Mode: store.ReadWriteTx})
	if err != nil {
		log.Fatal(err)
	}
	defer tx.Cancel()

	key := []byte("foo")
	value := []byte("bar")

	err = tx.Set(key, nil, value)
	if err != nil {
		log.Fatal(err)
	}

	_, err = tx.Commit(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	tx, err = db.NewTx(context.Background(), &store.TxOptions{Mode: store.ReadOnlyTx})
	if err != nil {
		log.Fatal(err)
	}

	ref, err := tx.Get(context.Background(), key)
	if err != nil {
		log.Fatal(err)
	}
	value, err = ref.Resolve()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%v", string(value))
}

Environment

I use Go with immudb embedded at version v1.9.0-RC2.0.20231220125802-d143b42683b7.

Additional info (any other context about the problem)

It might be that transactions in immudb work differently than they do in traditional databases. But there you can fetch data committed in prior transactions when you are inside a new transaction. They behave like a snapshot (also provide isolation against changes in other parallel transactions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions