diff --git a/go.mod b/go.mod index 522fc2b..7ec23cb 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( go.opentelemetry.io/otel v1.38.0 go.opentelemetry.io/otel/metric v1.38.0 golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb - modernc.org/sqlite v1.26.0 ) require ( @@ -50,17 +49,14 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/flatbuffers v1.12.1 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect - github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/klauspost/compress v1.18.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/onsi/gomega v1.20.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect @@ -70,7 +66,6 @@ require ( github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.65.0 // indirect github.com/prometheus/procfs v0.17.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect @@ -83,22 +78,10 @@ require ( go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/otel/trace v1.38.0 // indirect golang.org/x/crypto v0.38.0 // indirect - golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.40.0 // indirect - golang.org/x/sync v0.15.0 // indirect golang.org/x/sys v0.35.0 // indirect - golang.org/x/tools v0.22.0 // indirect google.golang.org/protobuf v1.36.8 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - lukechampine.com/uint128 v1.2.0 // indirect - modernc.org/cc/v3 v3.40.0 // indirect - modernc.org/ccgo/v3 v3.16.13 // indirect - modernc.org/libc v1.24.1 // indirect - modernc.org/mathutil v1.5.0 // indirect - modernc.org/memory v1.6.0 // indirect - modernc.org/opt v0.1.3 // indirect - modernc.org/strutil v1.1.3 // indirect - modernc.org/token v1.0.1 // indirect ) replace ( diff --git a/go.sum b/go.sum index 659ab6e..b185f70 100644 --- a/go.sum +++ b/go.sum @@ -492,8 +492,6 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/trillian v1.3.11/go.mod h1:0tPraVHrSDkA3BO6vKX67zgLXs6SsOAbHEivX+9mPgw= @@ -502,8 +500,6 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= @@ -660,8 +656,6 @@ github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4 github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U= github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw= github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0= -github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= -github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.6.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -738,16 +732,12 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= -github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc= @@ -950,9 +940,6 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= -github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/go-dbus v0.0.0-20121104212943-b7232d34b1d5/go.mod h1:+u151txRmLpwxBmpYn9z3d1sdJdjRPQpsXuYeY9jNls= github.com/remyoudompheng/go-liblzma v0.0.0-20190506200333-81bf2d431b96/go.mod h1:90HvCY7+oHHUKkbeMCiHt1WuFR2/hPJ9QrljDG+v6ls= github.com/remyoudompheng/go-misc v0.0.0-20190427085024-2d6ac652a50e/go.mod h1:80FQABjoFzZ2M5uEa6FUaJYEmqU2UOKojlFVak1UAwI= @@ -1278,8 +1265,6 @@ golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1511,7 +1496,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1644,8 +1628,6 @@ golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1899,34 +1881,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.3.1/go.mod h1:vlRD9XErLMGT+mDuofSr0mMMquscM/1nQqtRSsh6m70= -lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI= -lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= -modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw= -modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0= -modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw= -modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY= -modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk= -modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ= -modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM= -modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM= -modernc.org/libc v1.24.1 h1:uvJSeCKL/AgzBo2yYIPPTy82v21KgGnizcGYfBHaNuM= -modernc.org/libc v1.24.1/go.mod h1:FmfO1RLrU3MHJfyi9eYYmZBfi/R+tqZ6+hQ3yQQUkak= -modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= -modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= -modernc.org/memory v1.6.0 h1:i6mzavxrE9a30whzMfwf7XWVODx2r5OYXvU46cirX7o= -modernc.org/memory v1.6.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= -modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= -modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= -modernc.org/sqlite v1.26.0 h1:SocQdLRSYlA8W99V8YH0NES75thx19d9sB/aFc4R8Lw= -modernc.org/sqlite v1.26.0/go.mod h1:FL3pVXie73rg3Rii6V/u5BoHlSoyeZeIgKZEgHARyCU= -modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY= -modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw= -modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY= -modernc.org/tcl v1.15.2/go.mod h1:3+k/ZaEbKrC8ePv8zJWPtBSW0V7Gg9g8rkmhI1Kfs3c= -modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg= -modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= -modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY= -modernc.org/z v1.7.3/go.mod h1:Ipv4tsdxZRbQyLq9Q1M6gdbkxYzdlrciF2Hi/lS7nWE= mvdan.cc/gofumpt v0.3.1/go.mod h1:w3ymliuxvzVx8DAutBnVyDqYb1Niy/yCJt/lk821YCE= mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= diff --git a/ss/sqlite/batch.go b/ss/sqlite/batch.go deleted file mode 100644 index e2d5657..0000000 --- a/ss/sqlite/batch.go +++ /dev/null @@ -1,93 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package sqlite - -import ( - "database/sql" - "fmt" -) - -type batchAction int - -const ( - batchActionSet batchAction = 0 - batchActionDel batchAction = 1 -) - -type batchOp struct { - action batchAction - storeKey string - key, value []byte -} - -type Batch struct { - tx *sql.Tx - ops []batchOp - size int - version int64 -} - -func NewBatch(storage *sql.DB, version int64) (*Batch, error) { - tx, err := storage.Begin() - if err != nil { - return nil, fmt.Errorf("failed to create SQL transaction: %w", err) - } - - return &Batch{ - tx: tx, - ops: make([]batchOp, 0), - version: version, - }, nil -} - -func (b *Batch) Size() int { - return b.size -} - -func (b *Batch) Reset() { - b.ops = nil - b.ops = make([]batchOp, 0) - b.size = 0 -} - -func (b *Batch) Set(storeKey string, key, value []byte) error { - b.size += len(key) + len(value) - b.ops = append(b.ops, batchOp{action: batchActionSet, storeKey: storeKey, key: key, value: value}) - return nil -} - -func (b *Batch) Delete(storeKey string, key []byte) error { - b.size += len(key) - b.ops = append(b.ops, batchOp{action: batchActionDel, storeKey: storeKey, key: key}) - return nil -} - -func (b *Batch) Write() error { - _, err := b.tx.Exec(latestVersionStmt, reservedStoreKey, keyLatestHeight, b.version, 0, b.version) - if err != nil { - return fmt.Errorf("failed to exec SQL statement: %w", err) - } - - for _, op := range b.ops { - switch op.action { - case batchActionSet: - _, err := b.tx.Exec(upsertStmt, op.storeKey, op.key, op.value, b.version, op.value) - if err != nil { - return fmt.Errorf("failed to exec SQL statement: %w", err) - } - - case batchActionDel: - _, err := b.tx.Exec(delStmt, b.version, op.storeKey, op.key, b.version) - if err != nil { - return fmt.Errorf("failed to exec SQL statement: %w", err) - } - } - } - - if err := b.tx.Commit(); err != nil { - return fmt.Errorf("failed to write SQL transaction: %w", err) - } - - return nil -} diff --git a/ss/sqlite/bench_test.go b/ss/sqlite/bench_test.go deleted file mode 100644 index fa26b04..0000000 --- a/ss/sqlite/bench_test.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package sqlite - -import ( - "testing" - - "github.com/sei-protocol/sei-db/config" - sstest "github.com/sei-protocol/sei-db/ss/test" - "github.com/sei-protocol/sei-db/ss/types" -) - -func BenchmarkDBBackend(b *testing.B) { - s := &sstest.StorageBenchSuite{ - NewDB: func(dir string) (types.StateStore, error) { - return New(dir, config.DefaultStateStoreConfig()) - }, - BenchBackendName: "Sqlite", - } - - s.BenchmarkGet(b) - s.BenchmarkApplyChangeset(b) - s.BenchmarkIterate(b) -} diff --git a/ss/sqlite/db.go b/ss/sqlite/db.go deleted file mode 100644 index bc1ccd2..0000000 --- a/ss/sqlite/db.go +++ /dev/null @@ -1,354 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package sqlite - -import ( - "bytes" - "database/sql" - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - errorutils "github.com/sei-protocol/sei-db/common/errors" - "github.com/sei-protocol/sei-db/config" - "github.com/sei-protocol/sei-db/proto" - "github.com/sei-protocol/sei-db/ss/types" - _ "modernc.org/sqlite" -) - -const ( - driverName = "sqlite" - dbName = "ss.db" - reservedStoreKey = "_RESERVED_" - keyLatestHeight = "latest_height" - - latestVersionStmt = ` - INSERT INTO state_storage(store_key, key, value, version) - VALUES(?, ?, ?, ?) - ON CONFLICT(store_key, key, version) DO UPDATE SET - value = ?; - ` - upsertStmt = ` - INSERT INTO state_storage(store_key, key, value, version) - VALUES(?, ?, ?, ?) - ON CONFLICT(store_key, key, version) DO UPDATE SET - value = ?; - ` - delStmt = ` - UPDATE state_storage SET tombstone = ? - WHERE id = ( - SELECT id FROM state_storage WHERE store_key = ? AND key = ? AND version <= ? ORDER BY version DESC LIMIT 1 - ) AND tombstone = 0; - ` - - // TODO: Make configurable - ImportCommitBatchSize = 10000 -) - -var _ types.StateStore = (*Database)(nil) - -type Database struct { - storage *sql.DB - config config.StateStoreConfig -} - -func New(dataDir string, config config.StateStoreConfig) (*Database, error) { - if err := os.MkdirAll(dataDir, os.ModePerm); err != nil { - return nil, err - } - - db, err := sql.Open(driverName, filepath.Join(dataDir, dbName)+"?cache=shared") - if err != nil { - return nil, fmt.Errorf("failed to open sqlite DB: %w", err) - } - - // TODO: Make fully configurable - pragmas := []string{ - `PRAGMA journal_mode=WAL;`, - `PRAGMA synchronous=NORMAL;`, - `PRAGMA cache_size=-32000;`, - `PRAGMA auto_vacuum=FULL;`, - `PRAGMA temp_store=MEMORY;`, - } - - if err := execPragmas(db, pragmas); err != nil { - return nil, err - } - - stmt := ` - CREATE TABLE IF NOT EXISTS state_storage ( - id integer not null primary key, - store_key varchar not null, - key varchar not null, - value varchar not null, - version integer not null, - tombstone integer default 0, - unique (store_key, key, version) - ); - - CREATE UNIQUE INDEX IF NOT EXISTS idx_store_key_version ON state_storage (store_key, key, version); - ` - _, err = db.Exec(stmt) - if err != nil { - return nil, fmt.Errorf("failed to exec SQL statement: %w", err) - } - - return &Database{ - storage: db, - config: config, - }, nil -} - -func (db *Database) Close() error { - err := db.storage.Close() - db.storage = nil - return err -} - -func (db *Database) GetLatestVersion() int64 { - stmt, err := db.storage.Prepare("SELECT value FROM state_storage WHERE store_key = ? AND key = ?") - if err != nil { - return 0 - } - - defer func() { _ = stmt.Close() }() - - var latestHeight int64 - if err := stmt.QueryRow(reservedStoreKey, keyLatestHeight).Scan(&latestHeight); err != nil { - if errors.Is(err, sql.ErrNoRows) { - // in case of a fresh database - return 0 - } - return 0 - } - - return latestHeight -} - -func (db *Database) SetLatestVersion(version int64) error { - _, err := db.storage.Exec(latestVersionStmt, reservedStoreKey, keyLatestHeight, version, 0, version) - if err != nil { - return fmt.Errorf("failed to exec SQL statement: %w", err) - } - - return nil -} - -func (db *Database) GetEarliestVersion() int64 { - panic("not implemented") -} - -func (db *Database) SetEarliestVersion(version int64, ignoreVersion bool) error { - panic("not implemented") -} - -func (db *Database) Has(storeKey string, version int64, key []byte) (bool, error) { - val, err := db.Get(storeKey, version, key) - if err != nil { - return false, err - } - - return val != nil, nil -} - -func (db *Database) Get(storeKey string, targetVersion int64, key []byte) ([]byte, error) { - stmt, err := db.storage.Prepare(` - SELECT value, tombstone FROM state_storage - WHERE store_key = ? AND key = ? AND version <= ? - ORDER BY version DESC LIMIT 1; - `) - if err != nil { - return nil, fmt.Errorf("failed to prepare SQL statement: %w", err) - } - - defer func() { _ = stmt.Close() }() - - var ( - value []byte - tomb int64 - ) - if err := stmt.QueryRow(storeKey, key, targetVersion).Scan(&value, &tomb); err != nil { - if errors.Is(err, sql.ErrNoRows) { - return nil, nil - } - - return nil, fmt.Errorf("failed to query row: %w", err) - } - - // A tombstone of zero or a target version that is less than the tombstone - // version means the key is not deleted at the target version. - if tomb == 0 || targetVersion < tomb { - return value, nil - } - - // the value is considered deleted - return nil, nil -} - -func (db *Database) ApplyChangeset(version int64, cs *proto.NamedChangeSet) error { - b, err := NewBatch(db.storage, version) - if err != nil { - return err - } - - for _, kvPair := range cs.Changeset.Pairs { - if kvPair.Value == nil { - if err := b.Delete(cs.Name, kvPair.Key); err != nil { - return err - } - } else { - if err := b.Set(cs.Name, kvPair.Key, kvPair.Value); err != nil { - return err - } - } - } - - return b.Write() -} - -func (db *Database) ApplyChangesetAsync(version int64, changesets []*proto.NamedChangeSet) error { - return fmt.Errorf("not implemented") -} - -func (db *Database) Prune(version int64) error { - stmt := "DELETE FROM state_storage WHERE version <= ? AND store_key != ?;" - - _, err := db.storage.Exec(stmt, version, reservedStoreKey) - if err != nil { - return fmt.Errorf("failed to exec SQL statement: %w", err) - } - - return nil -} - -func (db *Database) Iterator(storeKey string, version int64, start, end []byte) (types.DBIterator, error) { - if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { - return nil, errorutils.ErrKeyEmpty - } - - if start != nil && end != nil && bytes.Compare(start, end) > 0 { - return nil, errorutils.ErrStartAfterEnd - } - - return newIterator(db.storage, storeKey, version, start, end, false) -} - -func (db *Database) ReverseIterator(storeKey string, version int64, start, end []byte) (types.DBIterator, error) { - if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) { - return nil, errorutils.ErrKeyEmpty - } - - if start != nil && end != nil && bytes.Compare(start, end) > 0 { - return nil, errorutils.ErrStartAfterEnd - } - - return newIterator(db.storage, storeKey, version, start, end, true) -} - -// Import loads the initial version of the state -// TODO: Parallelize Import -func (db *Database) Import(version int64, ch <-chan types.SnapshotNode) error { - batch, err := NewBatch(db.storage, version) - if err != nil { - return err - } - - var counter int - for entry := range ch { - err := batch.Set(entry.StoreKey, entry.Key, entry.Value) - if err != nil { - return err - } - - counter++ - if counter%ImportCommitBatchSize == 0 { - if err := batch.Write(); err != nil { - return err - } - - batch, err = NewBatch(db.storage, version) - if err != nil { - return err - } - } - } - - if batch.Size() > 0 { - if err := batch.Write(); err != nil { - return err - } - } - - return nil -} - -func (db *Database) PrintRowsDebug() { - stmt, err := db.storage.Prepare("SELECT store_key, key, value, version, tombstone FROM state_storage") - if err != nil { - panic(fmt.Errorf("failed to prepare SQL statement: %w", err)) - } - - defer func() { _ = stmt.Close() }() - - rows, err := stmt.Query() - if err != nil { - panic(fmt.Errorf("failed to execute SQL query: %w", err)) - } - - var sb strings.Builder - for rows.Next() { - var ( - storeKey string - key []byte - value []byte - version int64 - tomb int64 - ) - if err := rows.Scan(&storeKey, &key, &value, &version, &tomb); err != nil { - panic(fmt.Sprintf("failed to scan row: %s", err)) - } - - sb.WriteString(fmt.Sprintf("STORE_KEY: %s, KEY: %s, VALUE: %s, VERSION: %d, TOMBSTONE: %d\n", storeKey, key, value, version, tomb)) - } - if err := rows.Err(); err != nil { - panic(fmt.Errorf("received unexpected error: %w", err)) - } - - fmt.Println(strings.TrimSpace(sb.String())) -} - -func (db *Database) RawIterate(storeKey string, fn func(key []byte, value []byte, version int64) bool) (bool, error) { - panic("not implemented") -} - -// execPragmas executes a series of PRAGMA statements on sqlite db -func execPragmas(db *sql.DB, pragmas []string) error { - for _, pragma := range pragmas { - if _, err := db.Exec(pragma); err != nil { - return fmt.Errorf("failed to set %s: %w", strings.TrimSpace(pragma), err) - } - } - return nil -} - -func (db *Database) RawImport(ch <-chan types.RawSnapshotNode) error { - panic("implement me") -} - -// WriteBlockRangeHash writes a hash for a range of blocks to the database -func (db *Database) WriteBlockRangeHash(storeKey string, beginBlockRange, endBlockRange int64, hash []byte) error { - panic("implement me") -} - -func (db *Database) GetLatestMigratedKey() ([]byte, error) { - //TODO implement me - panic("implement me") -} - -func (db *Database) GetLatestMigratedModule() (string, error) { - //TODO implement me - panic("implement me") -} diff --git a/ss/sqlite/db_test.go b/ss/sqlite/db_test.go deleted file mode 100644 index 0348080..0000000 --- a/ss/sqlite/db_test.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package sqlite - -import ( - "testing" - - "github.com/sei-protocol/sei-db/config" - sstest "github.com/sei-protocol/sei-db/ss/test" - "github.com/sei-protocol/sei-db/ss/types" - "github.com/stretchr/testify/suite" -) - -// TODO: Update Sqlite to latest -func TestStorageTestSuite(t *testing.T) { - s := &sstest.StorageTestSuite{ - NewDB: func(dir string) (types.StateStore, error) { - return New(dir, config.DefaultStateStoreConfig()) - }, - EmptyBatchSize: 0, - } - - suite.Run(t, s) -} diff --git a/ss/sqlite/iterator.go b/ss/sqlite/iterator.go deleted file mode 100644 index e0dc1eb..0000000 --- a/ss/sqlite/iterator.go +++ /dev/null @@ -1,177 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package sqlite - -import ( - "bytes" - "database/sql" - "fmt" - "strings" - - "github.com/sei-protocol/sei-db/ss/types" - "golang.org/x/exp/slices" - // _ Import to register sqlite driver with database/sql. - _ "modernc.org/sqlite" -) - -var _ types.DBIterator = (*iterator)(nil) - -type iterator struct { - statement *sql.Stmt - rows *sql.Rows - key, val []byte - start, end []byte - valid bool - err error -} - -func newIterator(storage *sql.DB, storeKey string, targetVersion int64, start, end []byte, reverse bool) (*iterator, error) { - var ( - keyClause = []string{"store_key = ?", "version <= ?"} - queryArgs []any - ) - - switch { - case len(start) > 0 && len(end) > 0: - keyClause = append(keyClause, "key >= ?", "key < ?") - queryArgs = []any{storeKey, targetVersion, start, end, targetVersion} - - case len(start) > 0 && len(end) == 0: - keyClause = append(keyClause, "key >= ?") - queryArgs = []any{storeKey, targetVersion, start, targetVersion} - - case len(start) == 0 && len(end) > 0: - keyClause = append(keyClause, "key < ?") - queryArgs = []any{storeKey, targetVersion, end, targetVersion} - - default: - queryArgs = []any{storeKey, targetVersion, targetVersion} - } - - orderBy := "ASC" - if reverse { - orderBy = "DESC" - } - - // Note, this is not susceptible to SQL injection because placeholders are used - // for parts of the query outside the store's direct control. - stmt, err := storage.Prepare(fmt.Sprintf(` - SELECT x.key, x.value - FROM ( - SELECT key, value, version, tombstone, - row_number() OVER (PARTITION BY key ORDER BY version DESC) AS _rn - FROM state_storage WHERE %s - ) x - WHERE x._rn = 1 AND (x.tombstone = 0 OR x.tombstone > ?) ORDER BY x.key %s; - `, strings.Join(keyClause, " AND "), orderBy)) - if err != nil { - return nil, fmt.Errorf("failed to prepare SQL statement: %w", err) - } - - rows, err := stmt.Query(queryArgs...) - if err != nil { - _ = stmt.Close() - return nil, fmt.Errorf("failed to execute SQL query: %w", err) - } - - itr := &iterator{ - statement: stmt, - rows: rows, - start: start, - end: end, - valid: rows.Next(), - } - if !itr.valid { - itr.err = fmt.Errorf("iterator invalid: %w", sql.ErrNoRows) - return itr, nil - } - - // read the first row - itr.parseRow() - if !itr.valid { - return itr, nil - } - - return itr, nil -} - -func (itr *iterator) Close() error { - _ = itr.statement.Close() - itr.valid = false - itr.statement = nil - itr.rows = nil - return nil -} - -// Domain returns the domain of the iterator. The caller must not modify the -// return values. -func (itr *iterator) Domain() ([]byte, []byte) { - return itr.start, itr.end -} - -func (itr *iterator) Key() []byte { - itr.assertIsValid() - return slices.Clone(itr.key) -} - -func (itr *iterator) Value() []byte { - itr.assertIsValid() - return slices.Clone(itr.val) -} - -func (itr *iterator) Valid() bool { - if !itr.valid || itr.rows.Err() != nil { - itr.valid = false - return itr.valid - } - - // if key is at the end or past it, consider it invalid - if end := itr.end; end != nil { - if bytes.Compare(end, itr.Key()) <= 0 { - itr.valid = false - return itr.valid - } - } - - return true -} - -func (itr *iterator) Next() { - if itr.rows.Next() { - itr.parseRow() - itr.Valid() - return - } - - itr.valid = false -} - -func (itr *iterator) Error() error { - if err := itr.rows.Err(); err != nil { - return err - } - - return itr.err -} - -func (itr *iterator) parseRow() { - var ( - key []byte - value []byte - ) - if err := itr.rows.Scan(&key, &value); err != nil { - itr.err = fmt.Errorf("failed to scan row: %s", err) - itr.valid = false - return - } - - itr.key = key - itr.val = value -} - -func (itr *iterator) assertIsValid() { - if !itr.valid { - panic("iterator is invalid") - } -} diff --git a/ss/sqlite_init.go b/ss/sqlite_init.go deleted file mode 100644 index 2e06a7c..0000000 --- a/ss/sqlite_init.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build sqliteBackend -// +build sqliteBackend - -package ss - -import ( - "github.com/sei-protocol/sei-db/common/utils" - "github.com/sei-protocol/sei-db/config" - "github.com/sei-protocol/sei-db/ss/sqlite" - "github.com/sei-protocol/sei-db/ss/types" -) - -func init() { - initializer := func(dir string, configs config.StateStoreConfig) (types.StateStore, error) { - dbHome := utils.GetStateStorePath(dir, configs.Backend) - if configs.DBDirectory != "" { - dbHome = configs.DBDirectory - } - return sqlite.New(dbHome, configs) - } - RegisterBackend(SQLiteBackend, initializer) -} diff --git a/ss/store.go b/ss/store.go index 5bfd901..b48f324 100644 --- a/ss/store.go +++ b/ss/store.go @@ -21,9 +21,6 @@ const ( // PebbleDBBackend represents pebbledb PebbleDBBackend BackendType = "pebbledb" - - // SQLiteBackend represents sqlite - SQLiteBackend BackendType = "sqlite" ) type BackendInitializer func(dir string, config config.StateStoreConfig) (types.StateStore, error)