Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

pkg/sorted: survey of the KeyValue backends #1832

Open

Description

@bradfitz

When this survey started, Perkeep had seven sorted.KeyValue implementations (plus an unused eighth), from a time when Go had few embedded or networked key/value options and we tried several. This issue surveys what each one is and its state today, so that follow-up changes (removing, fixing, or bringing a backend up to parity) can each make their own case and link here. As changes land, I'll check off the findings they resolve and list the changes at the bottom.

Backends

Line numbers are at f890de4.

Backend (type) Dependency Optional interfaces Tests Config key Notes
sqlite modernc.org/sqlite v1.60.1 Wiper, TransactionalReader, Reindexer, NeedWipeError pass sqlite (the default) Batched reindex; rows stored WITHOUT ROWID (#1828). A single-slot gate serializes all access (sqlitekv.go:74)
leveldb syndtr/goleveldb, 2021 pseudo-version (upstream's last commit is 2022-07) Wiper, TransactionalReader pass levelDB Writes with Sync: false (leveldb.go:81); also the fallback type for queues and caches (below)
kv modernc.org/kv v1.0.6 Wiper pass kvIndexFile Deprecated in #1851; removal planned for no earlier than 2027-04-13 (#1850). app/publisher/main.go:393 hard-codes it for its thumbnail cache (the publisher now uses sorted.DefaultKVFileType)
mysql go-sql-driver/mysql v1.9.2 Wiper, TransactionalReader skipped mysql Gate of 20, "arbitrary limit. TODO" (mysqlkv.go:91)
postgres github.com/jackc/pgx/v5 v5.11.0 (lib/pq v1.10.9, switched in #1843) Wiper (generic DELETE), TransactionalReader skipped postgres Wipe TODO (sqlkv.go:330)
mongo gopkg.in/mgo.v2, 2016 Wiper skipped mongo Removed in #1835. mgo is unmaintained, and only writes the legacy wire-protocol opcodes MongoDB removed in 5.1/6.0. CommitBatch isn't atomic (mongokv.go:183)
memory github.com/google/btree v1.1.3 (already a perkeepd dependency, via tsnet) Wiper pass memoryIndex Reimplemented on google/btree in #1840; it no longer depends on goleveldb. Iterators read a copy-on-write snapshot, so they don't see writes made after Find
buffer (pkg/sorted/buffer) none none pass not registered Removed in #1836. Nothing imports it

Findings

  • The DBMS backends get no test coverage. On a current Docker (containerd 2.1+), the MySQL, Postgres and Mongo tests, including all 20 _MySQL/_Postgres/_Mongo index tests, are skipped. The pinned Postgres and Mongo test images use a manifest format containerd no longer accepts, and with Docker 29, dockertest can't find the MySQL container's IP. Tracked in CI: test the MySQL and Postgres backends against real servers in GitHub Actions #1833; fixed by pkg/test/dockertest, .github: test MySQL and Postgres against real servers in CI #1837.
  • The Mongo backend can't talk to a current MongoDB. mgo's socket.go only writes opcodes 2001–2007 (OP_UPDATE, OP_INSERT, OP_QUERY, OP_GET_MORE, OP_DELETE, OP_KILL_CURSORS), never OP_MSG, and MongoDB 6.0 removed those opcodes (starting in 5.1). Removed in all: remove MongoDB support #1835.
  • Only SQLite has batched reindex (sorted.Reindexer) and crash-safe detection of an interrupted reindex (NeedWipeError).
  • No caller uses TransactionalReader, other than kvtest.
  • Every backend drops oversized writes. All of them (sqlkv for MySQL/Postgres/SQLite, leveldb, kv, memory, and SQLite's reindex session) check sorted.CheckSizes (MaxKeySize 767, MaxValueSize 63000, inherited from MySQL/InnoDB limits) and, for a write over the limit, log it and skip it: Set returns nil and batches skip the mutation, so the caller never sees an error. See sorted: key of 1979 bytes too large #1812 for a case where this drops index rows.
  • Even with a DBMS index, some stores are leveldb files. With a local blobPath, the thumbnail cache and cloud sync queues use kvFileType() (pkg/serverinit/genconfig.go:358), which falls back to sorted.DefaultKVFileType = "leveldb" (pkg/sorted/kv.go:35). diskpacked's default index type is also leveldb (diskpacked.go:109).
  • The docs don't help anyone choose. doc/server-config.md:119 just lists the options. :214 still says SQLite is hard to get working on Windows because of mattn/go-sqlite3, though we use pure-Go modernc.org/sqlite now, and :232 says Mongo is "not as well tested as the MySQL one". doc/status.md:30 and doc/overview.md:143 still list App Engine. (docs mostly fixed in doc: update index backend guidance and Windows SQLite support #1842, except for helping users choose)
  • Other direct users: cmd/pk-put's have/stat caches use goleveldb directly, not pkg/sorted (see cmd/pk: use sqlite for havecache? #1773 about moving the havecache to SQLite). cmd/pk dbinit supports mysql, postgres and sqlite and mongo. dev/kvcopy (dev/kvcopy: add a tool to copy or dump sorted.KeyValue stores #1827) can copy any store into any other, which gives users of a backend that changes or goes away a migration path.

Changes

Each change that addresses a finding above should link this issue; I'll list it here and check off what it resolves.

Related: #126 and #46 (making the Mongo and Postgres indexers efficient), #790 and #1093 (LevelDB Sync and file descriptors), #258 (Postgres connection count), #523 (better pkg/sorted tests), #786 (a kv "unexpected EOF"), #1829 (startup performance).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions