From 55d5e03639b61ac10923f39e5d5b7e3a2e5963b4 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 1 Mar 2021 09:16:08 +0100 Subject: [PATCH] lib/db: Remove Badger experiment (#7413) --- cmd/stindex/main.go | 13 +- go.mod | 1 - go.sum | 36 --- lib/db/backend/backend.go | 76 ----- lib/db/backend/badger_backend.go | 467 ------------------------------- lib/db/backend/badger_test.go | 38 --- lib/locations/locations.go | 8 - 7 files changed, 1 insertion(+), 638 deletions(-) delete mode 100644 lib/db/backend/badger_backend.go delete mode 100644 lib/db/backend/badger_test.go diff --git a/cmd/stindex/main.go b/cmd/stindex/main.go index 19764a7b3..e5cd54ee2 100644 --- a/cmd/stindex/main.go +++ b/cmd/stindex/main.go @@ -30,13 +30,7 @@ func main() { path = filepath.Join(defaultConfigDir(), "index-v0.14.0.db") } - var ldb backend.Backend - var err error - if looksLikeBadger(path) { - ldb, err = backend.OpenBadger(path) - } else { - ldb, err = backend.OpenLevelDBRO(path) - } + ldb, err := backend.OpenLevelDBRO(path) if err != nil { log.Fatal(err) } @@ -56,8 +50,3 @@ func main() { fmt.Println("Unknown mode") } } - -func looksLikeBadger(path string) bool { - _, err := os.Stat(filepath.Join(path, "KEYREGISTRY")) - return err == nil -} diff --git a/go.mod b/go.mod index 18d92c917..f7a635c8b 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5 github.com/d4l3k/messagediff v1.2.1 github.com/dchest/siphash v1.2.2 - github.com/dgraph-io/badger/v2 v2.0.3 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 github.com/getsentry/raven-go v0.2.0 github.com/go-ldap/ldap/v3 v3.2.4 diff --git a/go.sum b/go.sum index 3ca8fd212..065ee8d34 100644 --- a/go.sum +++ b/go.sum @@ -14,11 +14,7 @@ github.com/AudriusButkevicius/recli v0.0.5/go.mod h1:Q2E26yc6RvWWEz/TJ/goUp6yXvi github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c h1:/IBSNwUN8+eKzUzbJPqhK839ygXJ82sde8x3ogr6R28= github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= -github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= @@ -36,7 +32,6 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= @@ -61,8 +56,6 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= @@ -73,14 +66,10 @@ github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= @@ -91,15 +80,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/siphash v1.2.2 h1:9DFz8tQwl9pTVt5iok/9zKyzA1Q6bRGiF3HPiEEVr9I= github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= -github.com/dgraph-io/badger/v2 v2.0.3 h1:inzdf6VF/NZ+tJ8RwwYMjJMvsOALTHYdozn0qSl6XJI= -github.com/dgraph-io/badger/v2 v2.0.3/go.mod h1:3KY8+bsP8wI0OEnQJAKpd4wIJW/Mm32yw2j/9FUVnIM= -github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3 h1:MQLRM35Pp0yAyBYksjbj1nZI/w6eyRY/mWoM1sFf4kU= -github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= -github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= @@ -216,7 +198,6 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= @@ -264,7 +245,6 @@ github.com/lucas-clemente/quic-go v0.19.3 h1:eCDQqvGBB+kCTkA0XrAFtNe81FMa0/fn4QS github.com/lucas-clemente/quic-go v0.19.3/go.mod h1:ADXpNbTQjq1hIzCpB+y/k5iz4n4z4IwqoLb94Kh5Hu8= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/qpack v0.2.1/go.mod h1:F7Gl5L1jIgN1D11ucXefiuJS9UMVP2opoCp2jDKb7wc= github.com/marten-seemann/qtls v0.10.0 h1:ECsuYUKalRL240rRD4Ri33ISb7kAQ3qGDlrrl55b2pc= @@ -291,7 +271,6 @@ github.com/miscreant/miscreant.go v0.0.0-20200214223636-26d376326b75 h1:cUVxyR+U github.com/miscreant/miscreant.go v0.0.0-20200214223636-26d376326b75/go.mod h1:pBbZyGwC5i16IBkjVKoy/sznA8jPD/K9iedwe1ESE6w= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= @@ -343,7 +322,6 @@ github.com/oschwald/maxminddb-golang v1.6.0/go.mod h1:DUJFucBg2cvqx42YmDa/+xHvb0 github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= @@ -437,17 +415,8 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -466,7 +435,6 @@ github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cb github.com/thejerf/suture/v4 v4.0.0 h1:GX3X+1Qaewtj9flL2wgoTBfLA5NcmrCY39TJRpPbUrI= github.com/thejerf/suture/v4 v4.0.0/go.mod h1:g0e8vwskm9tI0jRjxrnA6lSr0q6OfPdWJVX7G5bVWRs= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= @@ -476,7 +444,6 @@ github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMI github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0 h1:okhMind4q9H1OxF44gNegWkiP4H/gsTFLalHFa4OOUI= github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0/go.mod h1:TTbGUfE+cXXceWtbTHq6lqcTvYPBKLNejBEbnUsQJtU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= @@ -495,7 +462,6 @@ golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -561,13 +527,11 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/lib/db/backend/backend.go b/lib/db/backend/backend.go index 4a29a79cc..e444b9ce4 100644 --- a/lib/db/backend/backend.go +++ b/lib/db/backend/backend.go @@ -8,12 +8,7 @@ package backend import ( "errors" - "os" - "strings" "sync" - "time" - - "github.com/syncthing/syncthing/lib/locations" ) // CommitHook is a function that is executed before a WriteTransaction is @@ -131,10 +126,6 @@ const ( ) func Open(path string, tuning Tuning) (Backend, error) { - if err := maybeCopyDatabase(path, strings.Replace(path, locations.LevelDBDir, locations.BadgerDir, 1), OpenLevelDBAuto, OpenBadger); err != nil { - return nil, err - } - return OpenLevelDB(path, tuning) } @@ -209,70 +200,3 @@ func (cg *closeWaitGroup) CloseWait() { cg.closeMut.Unlock() cg.WaitGroup.Wait() } - -type opener func(path string) (Backend, error) - -// maybeCopyDatabase copies the database if the destination doesn't exist -// but the source does. -func maybeCopyDatabase(toPath, fromPath string, toOpen, fromOpen opener) error { - if _, err := os.Lstat(toPath); !os.IsNotExist(err) { - // Destination database exists (or is otherwise unavailable), do not - // attempt to overwrite it. - return nil - } - - if _, err := os.Lstat(fromPath); err != nil { - // Source database is not available, so nothing to copy - return nil - } - - fromDB, err := fromOpen(fromPath) - if err != nil { - return err - } - defer fromDB.Close() - - toDB, err := toOpen(toPath) - if err != nil { - // That's odd, but it will be handled & reported in the usual path - // so we can ignore it here. - return err - } - defer toDB.Close() - - l.Infoln("Copying database for format conversion...") - if err := copyBackend(toDB, fromDB); err != nil { - return err - } - - // Move the old database out of the way to mark it as migrated. - fromDB.Close() - _ = os.Rename(fromPath, fromPath+".migrated."+time.Now().Format("20060102150405")) - return nil -} - -func copyBackend(to, from Backend) error { - srcIt, err := from.NewPrefixIterator(nil) - if err != nil { - return err - } - defer srcIt.Release() - - dstTx, err := to.NewWriteTransaction() - if err != nil { - return err - } - defer dstTx.Release() - - for srcIt.Next() { - if err := dstTx.Put(srcIt.Key(), srcIt.Value()); err != nil { - return err - } - } - if srcIt.Error() != nil { - return err - } - srcIt.Release() - - return dstTx.Commit() -} diff --git a/lib/db/backend/badger_backend.go b/lib/db/backend/badger_backend.go deleted file mode 100644 index 2649d0dc0..000000000 --- a/lib/db/backend/badger_backend.go +++ /dev/null @@ -1,467 +0,0 @@ -// Copyright (C) 2019 The Syncthing Authors. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -package backend - -import ( - "bytes" - "errors" - "time" - - badger "github.com/dgraph-io/badger/v2" -) - -const ( - checkpointFlushMinSize = 128 << KiB - maxCacheSize = 64 << MiB -) - -func OpenBadger(path string) (Backend, error) { - opts := badger.DefaultOptions(path) - opts = opts.WithMaxCacheSize(maxCacheSize).WithCompactL0OnClose(false) - opts.Logger = nil - backend, err := openBadger(opts) - if err != nil { - return nil, err - } - backend.location = path - return backend, nil -} - -func OpenBadgerMemory() Backend { - opts := badger.DefaultOptions("").WithInMemory(true) - opts.Logger = nil - backend, err := openBadger(opts) - if err != nil { - // Opening in-memory should never be able to fail, and is anyway - // used just by tests. - panic(err) - } - return backend -} - -func openBadger(opts badger.Options) (*badgerBackend, error) { - // XXX: We should find good values for memory utilization in the "small" - // and "large" cases we support for LevelDB. Some notes here: - // https://github.com/dgraph-io/badger/tree/v2.0.3#memory-usage - bdb, err := badger.Open(opts) - if err != nil { - return nil, wrapBadgerErr(err) - } - return &badgerBackend{ - bdb: bdb, - closeWG: &closeWaitGroup{}, - }, nil -} - -// badgerBackend implements Backend on top of a badger -type badgerBackend struct { - bdb *badger.DB - closeWG *closeWaitGroup - location string -} - -func (b *badgerBackend) NewReadTransaction() (ReadTransaction, error) { - rel, err := newReleaser(b.closeWG) - if err != nil { - return nil, err - } - return badgerSnapshot{ - txn: b.bdb.NewTransaction(false), - rel: rel, - }, nil -} - -func (b *badgerBackend) NewWriteTransaction(hooks ...CommitHook) (WriteTransaction, error) { - rel1, err := newReleaser(b.closeWG) - if err != nil { - return nil, err - } - rel2, err := newReleaser(b.closeWG) - if err != nil { - rel1.Release() - return nil, err - } - - // We use two transactions here to preserve the property that our - // leveldb wrapper has, that writes in a transaction are completely - // invisible until it's committed, even inside that same transaction. - rtxn := b.bdb.NewTransaction(false) - wtxn := b.bdb.NewTransaction(true) - return &badgerTransaction{ - badgerSnapshot: badgerSnapshot{ - txn: rtxn, - rel: rel1, - }, - txn: wtxn, - bdb: b.bdb, - rel: rel2, - commitHooks: hooks, - }, nil -} - -func (b *badgerBackend) Close() error { - b.closeWG.CloseWait() - return wrapBadgerErr(b.bdb.Close()) -} - -func (b *badgerBackend) Get(key []byte) ([]byte, error) { - if err := b.closeWG.Add(1); err != nil { - return nil, err - } - defer b.closeWG.Done() - - txn := b.bdb.NewTransaction(false) - defer txn.Discard() - item, err := txn.Get(key) - if err != nil { - return nil, wrapBadgerErr(err) - } - val, err := item.ValueCopy(nil) - if err != nil { - return nil, wrapBadgerErr(err) - } - return val, nil -} - -func (b *badgerBackend) NewPrefixIterator(prefix []byte) (Iterator, error) { - if err := b.closeWG.Add(1); err != nil { - return nil, err - } - - txn := b.bdb.NewTransaction(false) - it := badgerPrefixIterator(txn, prefix) - it.releaseFn = func() { - defer b.closeWG.Done() - txn.Discard() - } - return it, nil -} - -func (b *badgerBackend) NewRangeIterator(first, last []byte) (Iterator, error) { - if err := b.closeWG.Add(1); err != nil { - return nil, err - } - - txn := b.bdb.NewTransaction(false) - it := badgerRangeIterator(txn, first, last) - it.releaseFn = func() { - defer b.closeWG.Done() - txn.Discard() - } - return it, nil -} - -func (b *badgerBackend) Put(key, val []byte) error { - if err := b.closeWG.Add(1); err != nil { - return err - } - defer b.closeWG.Done() - - txn := b.bdb.NewTransaction(true) - if err := txn.Set(key, val); err != nil { - txn.Discard() - return wrapBadgerErr(err) - } - return wrapBadgerErr(txn.Commit()) -} - -func (b *badgerBackend) Delete(key []byte) error { - if err := b.closeWG.Add(1); err != nil { - return err - } - defer b.closeWG.Done() - - txn := b.bdb.NewTransaction(true) - if err := txn.Delete(key); err != nil { - txn.Discard() - return wrapBadgerErr(err) - } - return wrapBadgerErr(txn.Commit()) -} - -func (b *badgerBackend) Compact() error { - if err := b.closeWG.Add(1); err != nil { - return err - } - defer b.closeWG.Done() - - // This weird looking loop is as recommended in the README - // (https://github.com/dgraph-io/badger/tree/v2.0.3#garbage-collection). - // Basically, the RunValueLogGC will pick some promising thing to - // garbage collect at random and return nil if it improved the - // situation, then return ErrNoRewrite when there is nothing more to GC. - // The 0.5 is the discard ratio, for which the method docs say they - // "recommend setting discardRatio to 0.5, thus indicating that a file - // be rewritten if half the space can be discarded". - var err error - t0 := time.Now() - for err == nil { - if time.Since(t0) > time.Hour { - l.Warnln("Database compaction is taking a long time, performance may be impacted. Consider investigating and/or opening an issue if this warning repeats.") - t0 = time.Now() - } - err = b.bdb.RunValueLogGC(0.5) - } - - if errors.Is(err, badger.ErrNoRewrite) { - // GC did nothing, because nothing needed to be done - return nil - } - if errors.Is(err, badger.ErrRejected) { - // GC was already running (could possibly happen), or the database - // is closed (can't happen). - return nil - } - if errors.Is(err, badger.ErrGCInMemoryMode) { - // GC in in-memory mode, which is fine. - return nil - } - return err -} - -func (b *badgerBackend) Location() string { - return b.location -} - -// badgerSnapshot implements backend.ReadTransaction -type badgerSnapshot struct { - txn *badger.Txn - rel *releaser -} - -func (l badgerSnapshot) Get(key []byte) ([]byte, error) { - item, err := l.txn.Get(key) - if err != nil { - return nil, wrapBadgerErr(err) - } - val, err := item.ValueCopy(nil) - if err != nil { - return nil, wrapBadgerErr(err) - } - return val, nil -} - -func (l badgerSnapshot) NewPrefixIterator(prefix []byte) (Iterator, error) { - return badgerPrefixIterator(l.txn, prefix), nil -} - -func (l badgerSnapshot) NewRangeIterator(first, last []byte) (Iterator, error) { - return badgerRangeIterator(l.txn, first, last), nil -} - -func (l badgerSnapshot) Release() { - defer l.rel.Release() - l.txn.Discard() -} - -type badgerTransaction struct { - badgerSnapshot - txn *badger.Txn - bdb *badger.DB - rel *releaser - size int - commitHooks []CommitHook -} - -func (t *badgerTransaction) Delete(key []byte) error { - t.size += len(key) - kc := make([]byte, len(key)) - copy(kc, key) - return t.transactionRetried(func(txn *badger.Txn) error { - return txn.Delete(kc) - }) -} - -func (t *badgerTransaction) Put(key, val []byte) error { - t.size += len(key) + len(val) - kc := make([]byte, len(key)) - copy(kc, key) - vc := make([]byte, len(val)) - copy(vc, val) - return t.transactionRetried(func(txn *badger.Txn) error { - return txn.Set(kc, vc) - }) -} - -// transactionRetried performs the given operation in the current -// transaction, with commit and retry if Badger says the transaction has -// grown too large. -func (t *badgerTransaction) transactionRetried(fn func(*badger.Txn) error) error { - if err := fn(t.txn); err == badger.ErrTxnTooBig { - if err := t.txn.Commit(); err != nil { - return wrapBadgerErr(err) - } - t.size = 0 - t.txn = t.bdb.NewTransaction(true) - return wrapBadgerErr(fn(t.txn)) - } else if err != nil { - return wrapBadgerErr(err) - } - return nil -} - -func (t *badgerTransaction) Commit() error { - defer t.rel.Release() - defer t.badgerSnapshot.Release() - for _, hook := range t.commitHooks { - if err := hook(t); err != nil { - return err - } - } - return wrapBadgerErr(t.txn.Commit()) -} - -func (t *badgerTransaction) Checkpoint() error { - if t.size < checkpointFlushMinSize { - return nil - } - for _, hook := range t.commitHooks { - if err := hook(t); err != nil { - return err - } - } - err := t.txn.Commit() - if err == nil { - t.size = 0 - t.txn = t.bdb.NewTransaction(true) - } - return wrapBadgerErr(err) -} - -func (t *badgerTransaction) Release() { - defer t.rel.Release() - defer t.badgerSnapshot.Release() - t.txn.Discard() -} - -type badgerIterator struct { - it *badger.Iterator - prefix []byte - first []byte - last []byte - releaseFn func() - released bool - didSeek bool - err error -} - -func (i *badgerIterator) Next() bool { - if i.err != nil { - return false - } - for { - if !i.didSeek { - if i.first != nil { - // Range iterator - i.it.Seek(i.first) - } else { - // Prefix iterator - i.it.Seek(i.prefix) - } - i.didSeek = true - } else { - i.it.Next() - } - - if !i.it.ValidForPrefix(i.prefix) { - // Done - return false - } - if i.first == nil && i.last == nil { - // No range checks required - return true - } - - key := i.it.Item().Key() - if bytes.Compare(key, i.last) > 0 { - // Key is after range last - return false - } - return true - } -} - -func (i *badgerIterator) Key() []byte { - if i.err != nil { - return nil - } - return i.it.Item().Key() -} - -func (i *badgerIterator) Value() []byte { - if i.err != nil { - return nil - } - val, err := i.it.Item().ValueCopy(nil) - if err != nil { - i.err = err - } - return val -} - -func (i *badgerIterator) Error() error { - return wrapBadgerErr(i.err) -} - -func (i *badgerIterator) Release() { - if i.released { - // We already closed this iterator, no need to do it again - // (and the releaseFn might hang if we do). - return - } - i.released = true - i.it.Close() - if i.releaseFn != nil { - i.releaseFn() - } -} - -// wrapBadgerErr wraps errors so that the backend package can recognize them -func wrapBadgerErr(err error) error { - if err == nil { - return nil - } - if err == badger.ErrDiscardedTxn { - return &errClosed{} - } - if err == badger.ErrKeyNotFound { - return &errNotFound{} - } - return err -} - -func badgerPrefixIterator(txn *badger.Txn, prefix []byte) *badgerIterator { - it := iteratorForPrefix(txn, prefix) - return &badgerIterator{it: it, prefix: prefix} -} - -func badgerRangeIterator(txn *badger.Txn, first, last []byte) *badgerIterator { - prefix := commonPrefix(first, last) - it := iteratorForPrefix(txn, prefix) - return &badgerIterator{it: it, prefix: prefix, first: first, last: last} -} - -func iteratorForPrefix(txn *badger.Txn, prefix []byte) *badger.Iterator { - opts := badger.DefaultIteratorOptions - opts.Prefix = prefix - return txn.NewIterator(opts) -} - -func commonPrefix(a, b []byte) []byte { - minLen := len(a) - if len(b) < minLen { - minLen = len(b) - } - prefix := make([]byte, 0, minLen) - for i := 0; i < minLen; i++ { - if a[i] != b[i] { - break - } - prefix = append(prefix, a[i]) - } - return prefix -} diff --git a/lib/db/backend/badger_test.go b/lib/db/backend/badger_test.go deleted file mode 100644 index 8a4ef9daa..000000000 --- a/lib/db/backend/badger_test.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2019 The Syncthing Authors. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -package backend - -import "testing" - -func TestCommonPrefix(t *testing.T) { - cases := []struct { - a string - b string - common string - }{ - {"", "", ""}, - {"a", "b", ""}, - {"aa", "ab", "a"}, - {"aa", "a", "a"}, - {"a", "aa", "a"}, - {"aabab", "ab", "a"}, - {"ab", "aabab", "a"}, - {"abac", "ababab", "aba"}, - {"ababab", "abac", "aba"}, - } - - for _, tc := range cases { - pref := string(commonPrefix([]byte(tc.a), []byte(tc.b))) - if pref != tc.common { - t.Errorf("commonPrefix(%q, %q) => %q, expected %q", tc.a, tc.b, pref, tc.common) - } - } -} - -func TestBadgerBackendBehavior(t *testing.T) { - testBackendBehavior(t, OpenBadgerMemory) -} diff --git a/lib/locations/locations.go b/lib/locations/locations.go index 3d3b0f193..f6c497812 100644 --- a/lib/locations/locations.go +++ b/lib/locations/locations.go @@ -47,7 +47,6 @@ const ( UserHomeBaseDir BaseDirEnum = "userHome" LevelDBDir = "index-v0.14.0.db" - BadgerDir = "indexdb.badger" ) // Platform dependent directories @@ -160,16 +159,9 @@ func defaultDataDir(userHome, config string) string { default: // If a database exists at the "normal" location, use that anyway. - // We look for both LevelDB and Badger variants here regardless of - // what we're currently configured to use, because we might be - // starting up in Badger mode with only a LevelDB database present - // (will be converted), or vice versa. if _, err := os.Lstat(filepath.Join(config, LevelDBDir)); err == nil { return config } - if _, err := os.Lstat(filepath.Join(config, BadgerDir)); err == nil { - return config - } // Always use this env var, as it's explicitly set by the user if xdgHome := os.Getenv("XDG_DATA_HOME"); xdgHome != "" { return filepath.Join(xdgHome, "syncthing")