aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/sqlite.cc
AgeCommit message (Collapse)Author
2023-06-20Support opening local store with database on read-only filesystem (#8356)Ben Radford
Previously it was not possible to open a local store when its database is on a read-only filesystem. Obviously a store on a read-only filesystem cannot be modified, but it would still be useful to be able to query it. This change adds a new read-only setting to LocalStore. When set to true, Nix will skip operations that fail when the database is on a read-only filesystem (acquiring big-lock, schema migration, etc), and the store database will be opened in immutable mode. Co-authored-by: Ben Radford <benradf@users.noreply.github.com> Co-authored-by: cidkidnix <cidkidnix@protonmail.com> Co-authored-by: Dylan Green <67574902+cidkidnix@users.noreply.github.com> Co-authored-by: John Ericson <git@JohnEricson.me> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-04-11Move warning timing logic into handleSQLiteBusy.Ben Radford
2023-04-11Warn after a second of being busy instead of immediately.Ben Radford
Getting the occasional SQLITE_BUSY is expected when the database is being accessed concurrently. The retry will likely succeed so it is pointless to warn immediately. Instead we track how long each retrySQLite block has been running, and only begin warning after a second has elapsed (and then every 10 seconds subsequently).
2023-02-07sqlite.cc: Add SQL tracingRobert Hensing
Set environment variable NIX_DEBUG_SQLITE_TRACES=1 to log all sql statements.
2022-12-23src/libstore: Print the reason opening the DB failedrski
Without this, the error is lost, and it makes for a hard to debug situation. Also remove some of the busyness inside the sqlite_open_v2 args. The errcode returned is not the extended one. The only way to make open return an extended code, would be to add SQLITE_OPEN_EXRESCODE to the flags. In the future it might be worth making this change, which would also simplify the existing SQLiteError code.
2022-12-17Improve sqlite error messagesRobert Hensing
They did not include the detailed error message, losing essential information for troubleshooting. Example message: warning: creating statement 'insert or rplace into NARs(cache, hashPart, namePart, url, compression, fileHash, fileSize, narHash, narSize, refs, deriver, sigs, ca, timestamp, present) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)': at offset 10: SQL logic error, near "rplace": syntax error (in '/tmp/nix-shell.grQ6f7/nix-test/tests/binary-cache/test-home/.cache/nix/binary-cache-v6.sqlite') It's not the best example; more important information will be in the message for e.g. a constraint violation. I don't see why this specific error is printed as a warning, but that's for another commit.
2022-04-20Actually, solve this in a lighter-weight wayJohn Ericson
The templating is very superficial
2022-04-20Move templated functions to `sqlite-impl.hh`John Ericson
This ensures that use-sites properly trigger new monomorphisations on one hand, and on the other hand keeps the main `sqlite.hh` clean and interface-only. I think that is good practice in general, but in this situation in particular we do indeed have `sqlite.hh` users that don't need the `throw_` function.
2022-04-19Avoid `fmt` when constructor already does itJohn Ericson
There is a correctnes issue here, but #3724 will fix that. This is just a cleanup for brevity's sake.
2022-04-08Remove unused Error.name fieldEelco Dolstra
2022-02-25Remove std::string alias (for real this time)Eelco Dolstra
Also use std::string_view in a few more places.
2021-11-03libstore: Use unix-dotfile vfs if useSQLiteWAL is falseDoron Behar
2021-01-21Improve error formattingEelco Dolstra
Changes: * The divider lines are gone. These were in practice a bit confusing, in particular with --show-trace or --keep-going, since then there were multiple lines, suggesting a start/end which wasn't the case. * Instead, multi-line error messages are now indented to align with the prefix (e.g. "error: "). * The 'description' field is gone since we weren't really using it. * 'hint' is renamed to 'msg' since it really wasn't a hint. * The error is now printed *before* the location info. * The 'name' field is no longer printed since most of the time it wasn't very useful since it was just the name of the exception (like EvalError). Ideally in the future this would be a unique, easily googleable error ID (like rustc). * "trace:" is now just "…". This assumes error contexts start with something like "while doing X". Example before: error: --- AssertionError ---------------------------------------------------------------------------------------- nix at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix 6| 7| x = assert false; 1; | ^ 8| assertion 'false' failed ----------------------------------------------------- show-trace ----------------------------------------------------- trace: while evaluating the attribute 'x' of the derivation 'hello-2.10' at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix 191| // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) { 192| name = "${attrs.pname}-${attrs.version}"; | ^ 193| } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) { Example after: error: assertion 'false' failed at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix 6| 7| x = assert false; 1; | ^ 8| … while evaluating the attribute 'x' of the derivation 'hello-2.10' at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix 191| // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) { 192| name = "${attrs.pname}-${attrs.version}"; | ^ 193| } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) {
2020-11-17Make the sql debug statements more usefulregnat
Print the expanded sql query (with the variables bound to their value) rather than the original one in case of error
2020-06-17Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-15Get rid of explicit ErrorInfo constructorsEelco Dolstra
2020-05-13formatting and a few minor changesBen Burdette
2020-05-13consistent capitalizationBen Burdette
2020-05-01convert some errorsBen Burdette
2020-04-28Error classname as nameBen Burdette
2020-04-21remove 'format' from Error constructor callsBen Burdette
2020-04-17Use a more space/time-efficient representation for the eval cacheEelco Dolstra
2020-04-17SQLiteStmt: Use std::string_viewEelco Dolstra
2020-03-24Misc changes from the flakes branchEelco Dolstra
2019-06-07Add flake evaluation cacheEelco Dolstra
This exploits the hermetic nature of flake evaluation to speed up repeated evaluations of a flake output attribute. For example (doing 'nix build' on an already present package): $ time nix build nixpkgs:firefox real 0m1.497s user 0m1.160s sys 0m0.139s $ time nix build nixpkgs:firefox real 0m0.052s user 0m0.038s sys 0m0.007s The cache is ~/.cache/nix/eval-cache-v1.sqlite, which has entries like INSERT INTO Attributes VALUES( X'92a907d4efe933af2a46959b082cdff176aa5bfeb47a98fabd234809a67ab195', 'packages.firefox', 1, '/nix/store/pbalzf8x19hckr8cwdv62rd6g0lqgc38-firefox-67.0.drv /nix/store/g6q0gx0v6xvdnizp8lrcw7c4gdkzana0-firefox-67.0 out'); where the hash 92a9... is a fingerprint over the flake store path and the contents of the lockfile. Because flakes are evaluated in pure mode, this uniquely identifies the evaluation result.
2018-05-30Use extended SQLite error codesEelco Dolstra
2018-03-14Use boost::format from the boost packageEelco Dolstra
Note that this only requires headers from boost so it doesn't add a runtime dependency. Also, use Nixpkgs 18.03.
2017-07-30Replace Unicode quotes in user-facing strings by ASCIIJörg Thalheim
Relevant RFC: NixOS/rfcs#4 $ ag -l | xargs sed -i -e "/\"/s/’/'/g;/\"/s/‘/'/g"
2017-02-28Improve SQLite busy handlingEelco Dolstra
2017-02-28In SQLite errors, include the database pathEelco Dolstra
This is necessary because we have multiple SQLite databases (e.g. the binary cache cache).
2016-11-26Revert "Get rid of unicode quotes (#1140)"Eelco Dolstra
This reverts commit f78126bfd6b6c8477fcdbc09b2f98772dbe9a1e7. There really is no need for such a massive change...
2016-11-25Get rid of unicode quotes (#1140)Guillaume Maudoux
2016-09-21printMsg(lvlError, ...) -> printError(...) etc.Eelco Dolstra
2016-08-10SQLite:: Add some convenienceEelco Dolstra
2016-04-20Cache path info lookups in SQLiteEelco Dolstra
This re-implements the binary cache database in C++, allowing it to be used by other Store backends, in particular the S3 backend.
2016-04-05Probably fix SQLITE_BUSY errorsEelco Dolstra
2016-04-04throwSQLiteError(): Check for SIGINT so we don't loop foreverEelco Dolstra
2016-03-30Improve the SQLite wrapper APIEelco Dolstra
In particular, this eliminates a bunch of boilerplate code.
2016-03-30Factour out SQLite handlingEelco Dolstra