Giter Site home page Giter Site logo

Comments (3)

mitar avatar mitar commented on May 20, 2024 1

I see. Thanks.

Then docs should be updated. In docs, there is:

tx, err := st.NewTx(context.Background(), &store.TxOptions{Mode: store.ReadWriteTx})

As we see, this is not a problem in this concrete example in docs, but it leads to the error like I have made. Example should use store.DefaultTxOptions() to tell the (future) user about this.

from immudb.

jeroiraz avatar jeroiraz commented on May 20, 2024

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).

Hi @mitar, transactions in immudb work pretty much as you would expect from any other database. Transactions are full ACID compliant with strict isolation.

I think the only issue with the code above is that the transactions options struct is built in a raw manner without a helpful constructor. Then it's not imposing any requirement for the snapshot used for the second transaction

tx, err = immuStore.NewTx(context.Background(), store.DefaultTxOptions().WithMode(store.ReadOnlyTx))

Please take a look at here https://github.com/jeroiraz/immudb/blob/9cfa35003ce361c3df4d53465d41b724bcee5018/embedded/store/immustore_test.go#L3739

from immudb.

mitar avatar mitar commented on May 20, 2024

I made codenotary/immudb.io#506 to update docs. Thanks.

from immudb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.