Skip to content

Commit 0286e50

Browse files
authored
Experimental file control opcode for write transaction (#339)
1 parent 8ac10eb commit 0286e50

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

embed/bcw2/bcw2.wasm

196 Bytes
Binary file not shown.

embed/bcw2/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ cd ~-
5959
-D_HAVE_SQLITE_CONFIG_H \
6060
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \
6161
-DSQLITE_ENABLE_ORDERED_SET_AGGREGATES \
62+
-DSQLITE_EXPERIMENTAL_PRAGMA_20251114 \
6263
-DSQLITE_CUSTOM_INCLUDE=sqlite_opt.h \
6364
$(awk '{print "-Wl,--export="$0}' ../exports.txt)
6465

vfs/mvcc/mvcc.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type mvccFile struct {
9090
data *wbt.Tree[int64, string]
9191
lock vfs.LockLevel
9292
readOnly bool
93+
wrflag bool
9394
}
9495

9596
var (
@@ -212,6 +213,14 @@ func (m *mvccFile) Truncate(size int64) error {
212213
return nil
213214
}
214215

216+
func (m *mvccFile) Pragma(name, value string) (string, error) {
217+
// notest // https://sqlite.org/forum/forumpost/c4ca8e7f4a887aa4
218+
if name == "experimental_pragma_20251114" {
219+
m.wrflag = true
220+
}
221+
return "", sqlite3.NOTFOUND
222+
}
223+
215224
func (m *mvccFile) Lock(lock vfs.LockLevel) error {
216225
if m.lock >= lock {
217226
return nil
@@ -225,7 +234,7 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
225234
defer m.mtx.Unlock()
226235

227236
// Take a snapshot of the database.
228-
if lock == vfs.LOCK_SHARED {
237+
if lock == vfs.LOCK_SHARED && !m.wrflag {
229238
m.data = m.mvccDB.data
230239
m.lock = lock
231240
return nil
@@ -244,7 +253,7 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
244253
defer time.AfterFunc(time.Millisecond, m.waiter.Broadcast).Stop()
245254
for m.owner != nil {
246255
// Our snapshot is invalid.
247-
if m.data != m.mvccDB.data {
256+
if m.data != nil && m.data != m.mvccDB.data {
248257
return sqlite3.BUSY_SNAPSHOT
249258
}
250259
if time.Since(before) > time.Millisecond {
@@ -253,11 +262,15 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
253262
m.waiter.Wait()
254263
}
255264
}
256-
// Our snapshot is invalid.
257-
if m.data != m.mvccDB.data {
265+
switch {
266+
case m.data == nil:
267+
m.data = m.mvccDB.data
268+
case m.data != m.mvccDB.data:
269+
// Our snapshot is invalid.
258270
return sqlite3.BUSY_SNAPSHOT
259271
}
260272
// Take ownership.
273+
m.wrflag = false
261274
m.lock = lock
262275
m.owner = m
263276
return nil

0 commit comments

Comments
 (0)