-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tableInfoStore should be scoped to transaction #243
Comments
Moving |
Actually, To my understanding, transaction isolation and concurrent access management are slightly different. When two transactions are trying to do the following actions:
the database should lock that resource for the first transaction and block the other transaction until the first one is either rolled back or commited (ideally with a timeout). It means that yes, transactions can be aware of other transactions doings on locked resources. - shell1> BEGIN;
- shell2> BEGIN;
- shell1> CREATE TABLE foo(a INT PRIMARY KEY);
- shell2> CREATE TABLE foo(a INT PRIMARY KEY);
this will block, until you either commit or rollback the first transaction The same goes for an update for example, when one transaction does an update on a given document and the other tries to read that document. What is currently missing with Genji is that locking mechanism. This is obviously not important for Bolt and the inmemory engine, which, like SQLite, only allow one concurrent write transaction. |
My understanding is that ACID/MVCC/locking/etc properties in Genji are expected to be implemented by K/V engines, and not at the SQL layer, so I think we need a |
Since BadgerDB uses snapshots isolation, I wouldn’t expect Genji to block in this case. |
Another issue with current implementation of |
I guess it depends on the direction the project is taking, which can be summed up with the following question: Do we want Genji to provide a unified experience but with specialized engines or do we want to delegate 100% of transaction management and complexity to the engines? First option Pros:
First option Cons:
Second option Pros:
Second option Cons:
Genji started as the second option but with the ambition of becoming the first one. I don't think it should only be a layer otherwise there will never be a good reason to be using Genji instead of SQLite for example (besides the fact that Genji doesn't use CGO). Regarding the issue at hand, and to explain why I'm talking about this, it was done this way as the first step towards the first option.
I don't think this is an issue because I don't think this is a good idea to let other processes (local or remote) modify the same data without some kind of control. |
@asdine which features do you think we need to implement to become a viable SQLite alternative? Regarding the second option cons, I’m not sure the last two points are exactly true.
|
There are lots of missing SQL features that would make Genji a true SQLite alternative, but I'll focus on what I think are the most important ones:
There is a huge problem with that, which can basically be summed up by this code:package main
import (
"fmt"
"log"
"net/http"
"sync/atomic"
"github.com/dgraph-io/badger/v2"
"github.com/genjidb/genji"
"github.com/genjidb/genji/document"
"github.com/genjidb/genji/engine/badgerengine"
)
func main() {
ng, err := badgerengine.NewEngine(badger.DefaultOptions("foo/"))
if err != nil {
panic(err)
}
db, err := genji.New(ng)
if err != nil {
panic(err)
}
defer db.Close()
err = db.Exec("CREATE TABLE foo; INSERT INTO foo (a) VALUES (0)")
if err != nil {
panic(err)
}
var count int64
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
reqID := atomic.AddInt64(&count, 1)
log.Printf("Handling request #%d\n", reqID)
defer fmt.Printf("Finished handling request #%d\n", reqID)
err = db.Update(func(tx *genji.Tx) error {
d, err := tx.QueryDocument("SELECT a FROM foo")
if err != nil {
return err
}
var a int
err = document.Scan(d, &a)
if err != nil {
return err
}
return tx.Exec("UPDATE foo SET a = ?", a+1)
})
if err != nil {
log.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
}
})
http.ListenAndServe(":8080", nil)
} If you run concurrent queries against this server, you have this:badger 2020/11/02 23:21:33 INFO: All 1 tables opened in 0s
badger 2020/11/02 23:21:33 INFO: Replaying file id: 0 at offset: 17270
badger 2020/11/02 23:21:33 INFO: Replay took: 731.8µs
badger 2020/11/02 23:21:33 DEBUG: Value log discard stats empty
2020/11/02 23:21:37 Handling request #1
2020/11/02 23:21:37 Handling request #2
2020/11/02 23:21:37 Handling request #4
2020/11/02 23:21:37 Handling request #3
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #2
2020/11/02 23:21:37 Handling request #5
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #4
2020/11/02 23:21:37 Handling request #6
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #1
2020/11/02 23:21:37 Handling request #7
2020/11/02 23:21:37 Handling request #8
2020/11/02 23:21:37 Handling request #9
2020/11/02 23:21:37 Handling request #10
2020/11/02 23:21:37 Handling request #11
2020/11/02 23:21:37 Handling request #12
2020/11/02 23:21:37 Handling request #13
2020/11/02 23:21:37 Handling request #14
2020/11/02 23:21:37 Handling request #15
2020/11/02 23:21:37 Handling request #16
2020/11/02 23:21:37 Handling request #17
2020/11/02 23:21:37 Handling request #18
2020/11/02 23:21:37 Handling request #19
2020/11/02 23:21:37 Handling request #20
2020/11/02 23:21:37 Handling request #21
2020/11/02 23:21:37 Handling request #22
2020/11/02 23:21:37 Handling request #23
2020/11/02 23:21:37 Handling request #24
2020/11/02 23:21:37 Handling request #26
2020/11/02 23:21:37 Handling request #25
2020/11/02 23:21:37 Handling request #27
2020/11/02 23:21:37 Handling request #28
2020/11/02 23:21:37 Handling request #29
2020/11/02 23:21:37 Handling request #30
2020/11/02 23:21:37 Handling request #31
2020/11/02 23:21:37 Handling request #32
2020/11/02 23:21:37 Handling request #33
2020/11/02 23:21:37 Handling request #34
2020/11/02 23:21:37 Handling request #35
2020/11/02 23:21:37 Handling request #37
2020/11/02 23:21:37 Handling request #36
2020/11/02 23:21:37 Handling request #38
2020/11/02 23:21:37 Handling request #40
2020/11/02 23:21:37 Handling request #39
2020/11/02 23:21:37 Handling request #41
2020/11/02 23:21:37 Handling request #42
2020/11/02 23:21:37 Handling request #43
2020/11/02 23:21:37 Handling request #44
2020/11/02 23:21:37 Handling request #45
2020/11/02 23:21:37 Handling request #46
2020/11/02 23:21:37 Handling request #47
2020/11/02 23:21:37 Handling request #48
2020/11/02 23:21:37 Handling request #49
2020/11/02 23:21:37 Handling request #50
2020/11/02 23:21:37 Handling request #51
2020/11/02 23:21:37 Handling request #52
2020/11/02 23:21:37 Handling request #53
Finished handling request #3
2020/11/02 23:21:37 Handling request #54
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #5
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #7
2020/11/02 23:21:37 Handling request #55
2020/11/02 23:21:37 Handling request #56
Finished handling request #6
2020/11/02 23:21:37 Handling request #57
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #57
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #9
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #10
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #11
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #12
2020/11/02 23:21:37 Handling request #59
2020/11/02 23:21:37 Handling request #58
2020/11/02 23:21:37 Handling request #60
2020/11/02 23:21:37 Handling request #61
2020/11/02 23:21:37 Handling request #62
Finished handling request #8
2020/11/02 23:21:37 Handling request #63
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #14
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #63
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #15
2020/11/02 23:21:37 Handling request #64
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #16
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #17
2020/11/02 23:21:37 Handling request #65
2020/11/02 23:21:37 Handling request #67
2020/11/02 23:21:37 Handling request #66
2020/11/02 23:21:37 Handling request #68
Finished handling request #13
2020/11/02 23:21:37 Handling request #69
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #20
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #19
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #69
2020/11/02 23:21:37 Handling request #70
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #21
2020/11/02 23:21:37 Handling request #71
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #22
2020/11/02 23:21:37 Handling request #72
2020/11/02 23:21:37 Handling request #73
2020/11/02 23:21:37 Handling request #74
Finished handling request #18
2020/11/02 23:21:37 Handling request #75
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #24
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #26
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #25
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #27
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #28
2020/11/02 23:21:37 Handling request #76
2020/11/02 23:21:37 Handling request #77
2020/11/02 23:21:37 Handling request #78
2020/11/02 23:21:37 Handling request #79
2020/11/02 23:21:37 Handling request #80
Finished handling request #23
2020/11/02 23:21:37 Handling request #81
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #30
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #31
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #32
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #81
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #33
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #34
2020/11/02 23:21:37 Handling request #83
2020/11/02 23:21:37 Handling request #84
2020/11/02 23:21:37 Handling request #82
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #35
2020/11/02 23:21:37 Handling request #85
2020/11/02 23:21:37 Handling request #86
2020/11/02 23:21:37 Handling request #87
2020/11/02 23:21:37 Handling request #88
Finished handling request #29
2020/11/02 23:21:37 Handling request #89
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #89
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #38
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #39
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #40
2020/11/02 23:21:37 Handling request #90
2020/11/02 23:21:37 Handling request #91
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #41
2020/11/02 23:21:37 Handling request #92
2020/11/02 23:21:37 Handling request #93
2020/11/02 23:21:37 Handling request #94
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #37
2020/11/02 23:21:37 Handling request #95
Finished handling request #36
2020/11/02 23:21:37 Handling request #96
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #42
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #45
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #44
2020/11/02 23:21:37 Handling request #97
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #96
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #46
2020/11/02 23:21:37 Handling request #98
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #47
2020/11/02 23:21:37 Handling request #99
2020/11/02 23:21:37 Handling request #100
2020/11/02 23:21:37 Handling request #101
2020/11/02 23:21:37 Handling request #102
Finished handling request #43
2020/11/02 23:21:37 Handling request #103
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #103
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #50
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #49
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #51
2020/11/02 23:21:37 Handling request #104
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #52
2020/11/02 23:21:37 Handling request #105
2020/11/02 23:21:37 Handling request #106
2020/11/02 23:21:37 Handling request #107
2020/11/02 23:21:37 Handling request #108
Finished handling request #48
2020/11/02 23:21:37 Handling request #109
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #109
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #54
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #53
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #56
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #59
2020/11/02 23:21:37 Handling request #110
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #60
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #58
2020/11/02 23:21:37 Handling request #111
2020/11/02 23:21:37 Handling request #112
2020/11/02 23:21:37 Handling request #113
2020/11/02 23:21:37 Handling request #114
2020/11/02 23:21:37 Handling request #115
2020/11/02 23:21:37 Handling request #116
Finished handling request #55
2020/11/02 23:21:37 Handling request #117
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #62
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #117
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #64
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #65
2020/11/02 23:21:37 Handling request #118
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #67
2020/11/02 23:21:37 Handling request #119
2020/11/02 23:21:37 Handling request #120
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #66
2020/11/02 23:21:37 Handling request #121
2020/11/02 23:21:37 Handling request #122
2020/11/02 23:21:37 Handling request #123
Finished handling request #61
2020/11/02 23:21:37 Handling request #124
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #70
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #124
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #71
2020/11/02 23:21:37 Transaction Conflict. Please retry
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #73
Finished handling request #72
2020/11/02 23:21:37 Handling request #126
2020/11/02 23:21:37 Handling request #125
2020/11/02 23:21:37 Handling request #127
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #74
2020/11/02 23:21:37 Handling request #129
2020/11/02 23:21:37 Handling request #128
2020/11/02 23:21:37 Handling request #130
Finished handling request #68
2020/11/02 23:21:37 Handling request #131
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #76
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #77
2020/11/02 23:21:37 Handling request #132
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #78
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #79
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #80
2020/11/02 23:21:37 Handling request #133
2020/11/02 23:21:37 Handling request #134
2020/11/02 23:21:37 Handling request #135
2020/11/02 23:21:37 Handling request #136
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #83
2020/11/02 23:21:37 Handling request #137
Finished handling request #75
2020/11/02 23:21:37 Handling request #138
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #82
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #85
2020/11/02 23:21:37 Transaction Conflict. Please retry
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #86
Finished handling request #138
2020/11/02 23:21:37 Handling request #139
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #87
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #88
2020/11/02 23:21:37 Handling request #141
2020/11/02 23:21:37 Handling request #140
2020/11/02 23:21:37 Handling request #142
2020/11/02 23:21:37 Handling request #143
2020/11/02 23:21:37 Handling request #144
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #90
Finished handling request #84
2020/11/02 23:21:37 Handling request #145
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #92
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #93
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #145
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #95
2020/11/02 23:21:37 Handling request #146
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #94
2020/11/02 23:21:37 Handling request #147
2020/11/02 23:21:37 Handling request #148
2020/11/02 23:21:37 Handling request #149
2020/11/02 23:21:37 Handling request #150
Finished handling request #91
2020/11/02 23:21:37 Handling request #151
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #98
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #99
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #100
2020/11/02 23:21:37 Handling request #152
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #151
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #102
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #104
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #101
2020/11/02 23:21:37 Handling request #153
2020/11/02 23:21:37 Handling request #155
2020/11/02 23:21:37 Handling request #154
2020/11/02 23:21:37 Handling request #156
2020/11/02 23:21:37 Handling request #157
2020/11/02 23:21:37 Handling request #158
Finished handling request #97
2020/11/02 23:21:37 Handling request #159
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #107
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #106
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #108
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #110
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #111
2020/11/02 23:21:37 Handling request #160
2020/11/02 23:21:37 Handling request #161
2020/11/02 23:21:37 Handling request #162
2020/11/02 23:21:37 Handling request #163
2020/11/02 23:21:37 Handling request #164
Finished handling request #105
2020/11/02 23:21:37 Handling request #165
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #165
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #113
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #115
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #114
2020/11/02 23:21:37 Handling request #166
2020/11/02 23:21:37 Handling request #167
2020/11/02 23:21:37 Handling request #169
2020/11/02 23:21:37 Handling request #168
Finished handling request #112
2020/11/02 23:21:37 Handling request #170
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #118
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #120
2020/11/02 23:21:37 Handling request #171
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #121
2020/11/02 23:21:37 Handling request #172
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #119
Finished handling request #116
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #122
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #123
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #127
2020/11/02 23:21:37 Handling request #174
2020/11/02 23:21:37 Handling request #173
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #129
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #125
2020/11/02 23:21:37 Handling request #175
2020/11/02 23:21:37 Handling request #176
Finished handling request #126
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #130
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #131
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #132
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #133
2020/11/02 23:21:37 Handling request #178
2020/11/02 23:21:37 Transaction Conflict. Please retry
Finished handling request #135 Delegating this kind of issue to the engine might create bad surprises for users and a mixed experience. Etcd implements their own MVCC layer on top of Bolt, I wouldn't be surprised if Dgraph had their own locking mechanism over Badger. Cockroach only uses serializable atomic operations in Pebble and deal with MVCC itself. |
Closing this as the issue no longer exists with #322. Once the project will be more mature I'll reopen a separate discussion on the subject. |
Currently
database.Database
holds a reference totableInfoStore
that is shared between all transactions which, among other things, may create/rename/alter/drop tables. This violates the transaction isolation.Make sure INSERT is indeed isolated.
Make sure that CREATE INDEX is indeed isolated.
Reproduce the bug. Panics with "table already exists" error.
Tangentially related to #210 since it needs concurrent transactions.
The text was updated successfully, but these errors were encountered: