Closed Bug 1919655 Opened 18 days ago Closed 10 days ago

Support importing rkv databases from different storage directories into Skv

Categories

(Core :: SQLite and Embedded Database Bindings, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
132 Branch
Tracking Status
firefox132 --- fixed

People

(Reporter: lina, Assigned: lina)

References

(Blocks 2 open bugs)

Details

Attachments

(2 files)

The Skv importer assumes that it'll be importing rkv databases in the same storage directory—there's currently no way to ask it to import keys and values from databases in different storage directories. (Separating databases into different directories was necessary to work around race conditions in rkv's safe mode).

In bug 1919530, add-ons would like to consolidate their databases, from 4 different storage directories into just one directory. We'll need to extend the importer to support this.

The Rust internals already support this, but we'll need to make a few changes to the API, and call into the internals differently.

Here's a sketch of how it could work:

let importer = SQLiteKeyValueService.createImporter(
    SQLiteKeyValueService.Importer.RKV_SAFE_MODE,
    destinationDir,
);

// Copy all keys and values from the `foo` rkv database in `sourceDir`
// into the `foo` Skv database in `destinationDir`, with the default
// conflict and cleanup policies.
importer.from(sourceDir)
    .add("foo");

// Copy all keys and values from the `bar` rkv database in `sourceDir2`
// into the `qux` Skv database in `destinationDir`, with custom
// conflict and cleanup policies.
importer.from(sourceDir2)
    .add("bar")
    .renameTo("qux")
    .setConflictPolicy(KeyValueImporter.ConflictPolicy.IGNORE)
    .setCleanupPolicy(KeyValueImporter.CleanupPolicy.KEEP);

// Copy all keys and values from all rkv databases in `destinationDir` into
// Skv databases of the same name in `destinationDir`, with the
// default conflict and cleanup policies.
importer.from(destinationDir)
    .addAll();

// Do the import.
await importer.import();

This would support all the use cases that I can think of. (Technically, renameTo isn't needed; all the extensions databases that are in separate directories have unique names—but it's easy to add!)

kvstore uses "wide" ns{A}Strings (potentially ill-formed UTF-16
strings) to represent paths in its XPCOM interface methods.
ns{A}String doesn't implement Hash or the built-in comparison
traits, so a wide path can't currently be used as a map key.

This commit introduces a WidePathBuf wrapper type, with the same
semantics as an ns{A}String path, but usable as a map key.

Assignee: nobody → lina
Status: NEW → ASSIGNED

This commit extends the Skv importer to allow consolidating multiple
Rkv databases in different storage directories, which add-ons would
like to do when they migrate (bug 1919530).

nsIKeyValueImporter is now a fluent builder interface. Callers can
use importer.add{Database, AllDatabases}() to configure the importer
to import Rkv databases in the same storage directory, and use
importer.withSourcePath().add{Database, AllDatabases()} to configure
importing databases from other directories. The reworked import()
method does the actual import.

Depends on D223228

Pushed by lbutler@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/92cc663ef661 Encapsulate `kvstore::fs::canonicalize` into `WidePathBuf`. r=nanj https://hg.mozilla.org/integration/autoland/rev/eca8c06d72f1 Support importing `kvstore` databases from multiple directories. r=nanj
Status: ASSIGNED → RESOLVED
Closed: 10 days ago
Resolution: --- → FIXED
Target Milestone: --- → 132 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: