Commit Graph

27 Commits

Author SHA1 Message Date
Earlopain cf24e98885
Remove coverage workaround
The running? method has been added in Ruby 2.4
2024-03-05 14:07:32 +01:00
Jean Boussier ad189d1367 Fix a cache corruption issue during revalidation
Fix: https://github.com/Shopify/bootsnap/issues/474
Fix: https://github.com/Shopify/bootsnap/issues/471

As noticed by Stan Hu, upon revalidation, we'd corrupt the
`data_size` field, as it wasn't initialized at all on the
cache key we computed from the source file.

The only thing we actually want to update is the `mtime`.

Co-Authored-By: Stan Hu <stanhu@gmail.com>
2024-01-31 09:45:36 +01:00
Jean Boussier a5b46d0e92 Disable stale cache entries revalidation by default
Ref: https://github.com/Shopify/bootsnap/issues/471
Ref: https://github.com/Shopify/bootsnap/issues/474

Since it is still unclear what causes the corruption, and more
people seem to be running into it, I'd rather make it an opt-in
feature until I get to the bottom of this.
2024-01-31 08:51:15 +01:00
Jean Boussier 7eb03b2a45 Add `hit` instrumentation events and add log_stat! 2024-01-30 14:59:13 +01:00
Étienne Barrié df6267fdfa Revalidate stale entries using a digest.
Ref: https://github.com/Shopify/bootsnap/issues/336

Bootsnap was initially designed for improving boot time
in development, so it was logical to use `mtime` to detect changes
given that's reliable on a given machine.

But is just as useful on production and CI environments, however
there its hit rate can vary a lot because depending on how the
source code and caches are saved and restored, many if not all
`mtime` will have changed.

To improve this, we can first try to revalidate using the `mtime`,
and if it fails, fallback to compare a digest of the file content.
Digesting a file, even with `fnv1a_64` is of course an overhead,
but the assumption is that true misses should be relatively rare
and that digesting the file will always be faster than compiling it.
So even if it only improve the hit rate marginally, it should be
faster overall.

Also we only recompute the digest if the file mtime changed, but
its size remained the same, which should discard the overwhelming
majority of legitimate source file changes.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-01-30 13:45:34 +01:00
Jean Boussier 070151f130 Fix require and include call style 2023-12-14 10:48:35 +01:00
Randy Stauner c094e57b2f
Remove custom permission error code and restore path in read error
Add a test to prove that if there is an error reading a file
the message contains the problematic path.

The custom permission error class and method were designed
to warn about errors with the cache path
but we stopped reporting write errors in
d878622782
and read errors in
503e9d5080
2023-07-24 15:35:22 -07:00
Randy Stauner 91977e3f22
Guard against unsupported platforms so that code can still be loaded
With this change the test suite can finish on unsupported platforms.

131 runs, 22 assertions, 0 failures, 0 errors, 114 skips
2023-06-30 14:31:03 -07:00
Jean Boussier b51397f96c Add readonly mode
Fix: https://github.com/Shopify/bootsnap/issues/423

When you know that the cache won't be used again, it avoid
some useless work and IOs.

Typically this might be the case for dockerized applications. You
generate a cache when building the image, but then when you boot the
application any cache update won't be persisted, so thre is no point.
2022-11-24 16:28:39 +01:00
Jean Boussier bd5cff326c Fix an unused variable warning in the test suite 2022-01-14 18:21:26 +01:00
Jean Boussier f210df9492 Handle YAML.load_file on Psych 4 2022-01-14 17:58:35 +01:00
Jean Boussier b277e75e85 Cleanup the rubocop config
Go back to rubocop 0.80 for Ruby 2.3 support.
Stop depending on the company style guide, as it needs a newer
rubocop.
2022-01-13 10:05:10 +01:00
Jean Boussier 503e9d5080 Tread read errors as cache misses as well 2021-04-16 10:34:55 +02:00
Jean Boussier 0dc8f2b6b4 Adds an instrumentation API to monitor cache misses 2021-02-01 11:51:37 +01:00
James Pogran 0cc8fbf3e9 Fix tests for windows platform
This commit makes several changes to the existing test files to support the Windows platform. These changes mainly comprise using Windows file paths or file access methods. There are two tests called out that do not work on Windows at all, and are hardcoded to pass. I would have used 'pending', but I could not find out how to do that in minitest.

Co-authored-by: Daniel Rikowski <daniel-rikowski@users.noreply.github.com>
2020-10-05 12:03:15 -04:00
alebruck b720530584 Update minimum ruby version and fix rubocop 2019-10-12 17:23:16 +02:00
Burke Libbey 149f5d9b81 Paper over EACCES from Native.fetch with clearer error:
Currently, users get:

  Permission denied - bs_fetch:atomic_write_cache_file:open.

This is not actionable: it doesn't even include the path which was
denied access. Here we at least present the paths we failed on.
2019-03-05 16:26:34 -05:00
Burke Libbey 581bc3fa59 update style guide 2019-02-06 13:29:01 -05:00
Aaron Patterson aec3600b0d
Fix ununsed variable warnings
```
.......a.rb:1: warning: assigned but unused variable - a
...a.rb:1: warning: assigned but unused variable - a
..a.rb:1: warning: assigned but unused variable - a
.a.rb:1: warning: assigned but unused variable - a
..a.rb:1: warning: assigned but unused variable - a
.a.rb:1: warning: assigned but unused variable - a
..a.rb:1: warning: assigned but unused variable - a
..a.rb:1: warning: assigned but unused variable - a
a.rb:1: warning: assigned but unused variable - a
..a.rb:1: warning: assigned but unused variable - a
.......................
```
2017-08-04 10:47:13 -07:00
Burke Libbey bb898e5d8a
Fix on 32-bit platforms 2017-06-22 11:45:13 -04:00
Burke Libbey 2029239436
Correctly detect if coverage is actually running 2017-06-19 15:40:43 -04:00
Adam Jacques b633496722 Open cache file as read-only
When opening a previously generated cache file, we will
now open the file as read-only. Consumers of this method
never wrote to the file descriptor and opening as read-only
enables us to avoid needing write permissions on the cache folder.
2017-06-04 22:09:04 -07:00
Burke Libbey b72c19d602
Replace xattr usage with a cache directory 2017-05-25 14:09:44 -04:00
Will Jordan 8045f93d05 fix test_no_write_permission 2017-05-21 19:26:11 -07:00
Sam Saffron 1051d006f1 FEATURE: stop using xattr binary to set/remove xattrs 2017-04-29 21:22:11 -04:00
Burke Libbey 4ba030b369
Reapply julian's patch to AOTCC that includes OS Version in cache keys 2017-04-05 15:21:35 -04:00
Burke Libbey 47539a1c07
Initial public release 2017-03-31 11:38:33 -04:00