chore: switch database engine to sqlite (fixes #9954) (#9965)

Switch the database from LevelDB to SQLite, for greater stability and
simpler code.

Co-authored-by: Tommy van der Vorst <tommy@pixelspark.nl>
Co-authored-by: bt90 <btom1990@googlemail.com>
This commit is contained in:
Jakob Borg
2025-03-29 13:50:08 +01:00
committed by GitHub
co-authored by Tommy van der Vorst bt90
parent b1c8f88a44
commit 025905fcdf
146 changed files with 8315 additions and 11984 deletions
+7 -5
View File
@@ -19,10 +19,12 @@ import (
// FileInfo.LocalFlags flags
const (
FlagLocalUnsupported = 1 << 0 // The kind is unsupported, e.g. symlinks on Windows
FlagLocalIgnored = 1 << 1 // Matches local ignore patterns
FlagLocalMustRescan = 1 << 2 // Doesn't match content on disk, must be rechecked fully
FlagLocalReceiveOnly = 1 << 3 // Change detected on receive only folder
FlagLocalUnsupported = 1 << 0 // 1: The kind is unsupported, e.g. symlinks on Windows
FlagLocalIgnored = 1 << 1 // 2: Matches local ignore patterns
FlagLocalMustRescan = 1 << 2 // 4: Doesn't match content on disk, must be rechecked fully
FlagLocalReceiveOnly = 1 << 3 // 8: Change detected on receive only folder
FlagLocalGlobal = 1 << 4 // 16: This is the global file version
FlagLocalNeeded = 1 << 5 // 32: We need this file
// Flags that should result in the Invalid bit on outgoing updates
LocalInvalidFlags = FlagLocalUnsupported | FlagLocalIgnored | FlagLocalMustRescan | FlagLocalReceiveOnly
@@ -32,7 +34,7 @@ const (
// disk.
LocalConflictFlags = FlagLocalUnsupported | FlagLocalIgnored | FlagLocalReceiveOnly
LocalAllFlags = FlagLocalUnsupported | FlagLocalIgnored | FlagLocalMustRescan | FlagLocalReceiveOnly
LocalAllFlags = FlagLocalUnsupported | FlagLocalIgnored | FlagLocalMustRescan | FlagLocalReceiveOnly | FlagLocalGlobal | FlagLocalNeeded
)
// BlockSizes is the list of valid block sizes, from min to max
-24
View File
@@ -10,10 +10,8 @@ import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"errors"
"io"
"os"
"sync"
"testing"
"time"
@@ -280,28 +278,6 @@ func TestUnmarshalFDPUv16v17(t *testing.T) {
}
}
func testMarshal(t *testing.T, prefix string, m1, m2 proto.Message) bool {
buf, err := proto.Marshal(m1)
if err != nil {
t.Fatal(err)
}
err = proto.Unmarshal(buf, m2)
if err != nil {
t.Fatal(err)
}
bs1, _ := json.MarshalIndent(m1, "", " ")
bs2, _ := json.MarshalIndent(m2, "", " ")
if !bytes.Equal(bs1, bs2) {
os.WriteFile(prefix+"-1.txt", bs1, 0o644)
os.WriteFile(prefix+"-2.txt", bs2, 0o644)
return false
}
return true
}
func TestWriteCompressed(t *testing.T) {
for _, random := range []bool{false, true} {
buf := new(bytes.Buffer)
+41
View File
@@ -7,6 +7,11 @@
package protocol
import (
"encoding/binary"
"encoding/hex"
"fmt"
"strconv"
"strings"
"time"
"github.com/syncthing/syncthing/internal/gen/bep"
@@ -20,6 +25,17 @@ type Vector struct {
Counters []Counter
}
func (v *Vector) String() string {
var buf strings.Builder
for i, c := range v.Counters {
if i > 0 {
buf.WriteRune(',')
}
fmt.Fprintf(&buf, "%x:%d", c.ID, c.Value)
}
return buf.String()
}
func (v *Vector) ToWire() *bep.Vector {
counters := make([]*bep.Counter, len(v.Counters))
for i, c := range v.Counters {
@@ -42,6 +58,31 @@ func VectorFromWire(w *bep.Vector) Vector {
return v
}
func VectorFromString(s string) (Vector, error) {
pairs := strings.Split(s, ",")
var v Vector
v.Counters = make([]Counter, len(pairs))
for i, pair := range pairs {
idStr, valStr, ok := strings.Cut(pair, ":")
if !ok {
return Vector{}, fmt.Errorf("bad pair %q", pair)
}
idslice, err := hex.DecodeString(idStr)
if err != nil {
return Vector{}, fmt.Errorf("bad id in pair %q", pair)
}
var idbs [8]byte
copy(idbs[8-len(idslice):], idslice)
id := binary.BigEndian.Uint64(idbs[:])
val, err := strconv.ParseUint(valStr, 10, 64)
if err != nil {
return Vector{}, fmt.Errorf("bad val in pair %q", pair)
}
v.Counters[i] = Counter{ID: ShortID(id), Value: val}
}
return v, nil
}
// Counter represents a single counter in the version vector.
type Counter struct {
ID ShortID