Class SplitDbBuilder
- Namespace
- VpnHood.Core.Filtering.Sqlite
- Assembly
- VpnHood.Core.Filtering.Sqlite.dll
Provides the build of a split database: a SQLite file of include, exclude and block sets, which a filter of this package reads.
public abstract class SplitDbBuilder
- Inheritance
-
SplitDbBuilder
- Derived
- Inherited Members
Remarks
Derive from SplitIpDbBuilder or SplitDomainDbBuilder, which give the schema. A build
writes a new file beside the target, its path plus .tmp, with no journal: the rows in one transaction, the
indexes after them, and the mark that the file is complete last. It then deletes the target and moves the new
file to its path, so a crash never leaves a half-built database there.
The target must not be open while it is replaced: give a changed source a new file name, from GetSourceSignature(), so a running filter keeps the old file until it swaps.
Methods
BuildAsync(string, CancellationToken)
Builds the database at a path, replacing the file there.
public Task BuildAsync(string dbPath, CancellationToken cancellationToken)
Parameters
dbPathstringThe database's path; its folder is made if missing.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
The target's -wal, -shm and -journal files are deleted with it. A build that fails before its
new file is complete leaves the target as it was, and the new file, which the next build deletes; as the target
is deleted before the new file is moved to its path, a failure between the two leaves neither there.
Exceptions
- ArgumentException
dbPathhas no parent folder.- SqliteException
SQLite refused a row of the build.
- OperationCanceledException
cancellationTokenwas canceled.
EnsureAsync(string, CancellationToken)
Builds the database at a path, unless the file there is complete, of this builder's schema version, and from the same source signature.
public Task EnsureAsync(string dbPath, CancellationToken cancellationToken)
Parameters
dbPathstringThe database's path.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
A file that cannot be opened or read counts as out of date. With an unchanged source, it reads the database's own record of its build and nothing of the source.
Exceptions
- ArgumentException
dbPathhas no parent folder.- SqliteException
SQLite refused a row of the build.
- OperationCanceledException
cancellationTokenwas canceled.
GetSourceSignature()
Gets the identity of the source of the sets, which a build stores in the database: it must change exactly when the sets would.
public abstract string GetSourceSignature()
Returns
- string
The identity, compared as a string.
Remarks
EnsureAsync(string, CancellationToken) calls it every time, so keep it cheap: hashes and file sizes and times, never a parse of the source.