Commit Graph

599 Commits

Author SHA1 Message Date
Jarek Kowalski
7ee30b76bb fix(repository): fixed handling of content.Info (#3356)
* fix(repository): fixed handling of content.Info

Previously content.Info was an interface which was implemented by:

* index.InfoStruct
* index.indexEntryInfoV1
* index.indexEntryInfoV2

The last 2 implementations were relying on memory-mapped files
which in rare cases could be closed while Kopia was still processing
them leading to #2599.

This changes fixes the bug and strictly separates content.Info (which
is now always a struct) from the other two (which were renamed as
index.InfoReader and only used inside repo/content/...).

In addition to being safer, this _should_ reduce memory allocations.

* reduce the size of content.Info with proper alignment.

* pr feedback

* renamed index.InfoStruct to index.Info
2023-10-14 10:34:15 -07:00
Jarek Kowalski
c8d1b221e2 refactor(repository): added fs.DirectoryIterator (#3365)
* refactor(repository): added fs.DirectoryIterator

This significantly reduces number of small allocations while
taking snapshots of lots of files, which leads to faster snapshots.

```
$ runbench --kopia-exe ~/go/bin/kopia \
   --compare-to-exe ~/go/bin/kopia-baseline --min-duration 30s \
   ./snapshot-linux-parallel-4.sh
DIFF duration: current:5.1 baseline:5.8 change:-13.0 %
DIFF repo_size: current:1081614127.6 baseline:1081615302.8 change:-0.0 %
DIFF num_files: current:60.0 baseline:60.0 change:0%
DIFF avg_heap_objects: current:4802666.0 baseline:4905741.8 change:-2.1 %
DIFF avg_heap_bytes: current:737397275.2 baseline:715263289.6 change:+3.1 %
DIFF avg_ram: current:215.0 baseline:211.5 change:+1.6 %
DIFF max_ram: current:294.8 baseline:311.4 change:-5.3 %
DIFF avg_cpu: current:167.3 baseline:145.3 change:+15.1 %
DIFF max_cpu: current:227.2 baseline:251.0 change:-9.5 %
```

* changed `Next()` API

* mechanical move of the iterator to its own file

* clarified comment

* pr feedback

* mechanical move of all localfs dependencies on os.FileInfo to a separate file

* Update fs/entry.go

Co-authored-by: ashmrtn <3891298+ashmrtn@users.noreply.github.com>

* Update fs/entry_dir_iterator.go

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>

* doc: clarified valid results from Next()

---------

Co-authored-by: ashmrtn <3891298+ashmrtn@users.noreply.github.com>
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-10-05 02:45:44 +00:00
PhracturedBlue
e653ec0a02 refactor(repository): Move encryption into a common package in preparation to handle secrets (#3351) 2023-09-24 17:44:50 -07:00
PhracturedBlue
bcb07da5f3 fix(cli): Convert --run-missed from bool to Enum (#3337) 2023-09-22 10:18:19 -07:00
Jarek Kowalski
af1550ad81 feat(server): reduce server refreshes of the repository (#3265)
* feat(server): reduce server refreshes of the repository

Previously each source would refresh itself from the repository
very frequently to determine the upcoming snapshot time. This change
refactors source manager so it does not own the repository connection
on its own but instead delegates all policy reads through the server.

Also introduces a new server scheduler that is responsible for
centrally managing the snapshot schedule and triggering snapshots
when they are due.

* Update cli/command_server_start.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* Update internal/server/server.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* Update internal/server/server_maintenance.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* pr feedback

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-09-15 12:08:35 -07:00
Jarek Kowalski
164dcceb11 feat(server): introduced generic scheduler (#3293)
This is a generic scheduler that executes a loop consisting of:

- determining upcoming set of events
- waiting until the appropriate time
- triggering the events
2023-09-12 07:37:41 -07:00
PhracturedBlue
30d6ef2ceb feat(ui): Allow specifying whether local or all snapshots are shown by default in the UI (#3289) 2023-09-11 22:49:36 -07:00
Jarek Kowalski
aa064bb442 fix(providers): fixed list/get caching with rclone providers (#3284)
Added improved providervalidation logic which tests for read-after-write
property between connections. The new test was failing before the change
and is now passing for Google Drive, OneDrive and DropBox.
2023-09-09 13:07:53 -07:00
Jarek Kowalski
044db7593b feat(repository): apply retention policies server-side (#3249)
* feat(repository): apply retention policies server-side

This allows append-only snapshots where the client can never delete
arbitrary manifests and policies are maintained on the server.

The client only needs permissions to create snapshots in a given, which
automatically gives them permission to invoke the server-side method
for their own snapshots only.

* Update cli/command_acl_add.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/grpc_session.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

---------

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>
2023-09-02 18:23:21 -07:00
Jarek Kowalski
80423cf5f6 feat(server): fixed server logging file & console (#3262)
Previously some logs from a running server were only kept in memory
(including storage activity logs) which was confusing to many folks.

This changes the behavior so that logs are sent to their regular
(console/file) file locations in addition to the UI tasks.

Old behavior can be restored by adding `--no-persistent-logs` to
server.
2023-09-02 18:10:18 -07:00
Jarek Kowalski
20928258d6 test(general): fixed TestOnNthCompletion test flake, which was 1-5/10000 runs (#3263) 2023-09-02 16:04:36 -07:00
Jarek Kowalski
fe55dcb6a2 feat(repository): added hard size limit to the on-disk cache (#3238)
* test(providers): added capacity limits to blobtesting.mapStorage

* refactor(general): added mutex map which dynamically allocates and releases named mutexes

* refactor(repository): refactored cache cleanup and limit enforcement

* refactor(repository): plumb through cache size limits in the repository

* feat(cli): added CLI options to set cache size limits

* unified flag setting and field naming

* Update cli/command_cache_set.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* pr feedback

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-08-24 09:38:56 -07:00
Jarek Kowalski
1120e4f629 chore(ci): reenable check-locks after the fix was merged upstream (#3245) 2023-08-22 19:41:03 -07:00
ashmrtn
b57d16d4a7 fix(repository): skip epoch compaction and advancement on read-only storage (#3225)
* Set epoch manager not to compact if readonly

Thread read-only parameter through the stack and make use of it when
loading epochs.

* Add test for manager read-only mode

Uses a bit of a contrived setup, but the state used in the test is
possible to reach given the right set of conditions and can cause the
manager to get stuck trying to refresh.

* Pull read-only status from Storage provider
2023-08-21 15:29:13 -07:00
ashmrtn
29320a7c33 refactor(providers): Create default provider that has common functions (#3241)
* Rename UnsupportedBlobRetention struct

Rename this struct to DefaultProviderImplementation in preparation for
adding other simple "default" functionality to it.

* Add other functions to default provider

Add other simple function implementations to the default provider so
that other providers can just embed this to get basic behavior.

* Cleanup existing users of default provider

* Add default provider to remaining storage types

Add the default provider to remaining storage providers and remove
functions that are now implemented by the default provider.
2023-08-21 15:27:15 -07:00
ashmrtn
08c58d53b6 feat(providers): Create IsReadOnly API for blob storage (#3230)
* Add new blob.Storage call to see if it's readonly

Return whether the storage is readonly so higher layers in the stack can
selectively disable some functionality if needed, like compaction.

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-08-21 17:00:50 +00:00
PhracturedBlue
9237b29023 feat(server): add server support for unix domain sockets (#3216)
* Add server support for unix domain sockets

* Ensure socket path < 104 bytes for UDS test
2023-08-20 17:17:20 -07:00
Jarek Kowalski
7eca44993f feat(providers): improve performance of SFTP uploads (#3235)
This improves the performance of gather writes (p and q blobs) in
particular on high-latency links by reducing round-trips.

Tested by uploading Kopia working directory
(3 GB, files:32157 dirs:6051) to SFTP server on LAN (TrueNAS) over WiFi:

Before: 2m4s (~24 MB/s)
After: 1m13s (~41 MB/s)
2023-08-19 18:07:43 -07:00
ashmrtn
bb27e3147e test(repository): More precise check for retention in tests (#3220)
* Store and return retention info in test storage

Add a new interface and function that allows getting retention
information during testing. This allows for more exact comparisons about
retention duration and mode in tests.

* Fixup how blobtesting retention extension works

Use the clock instead of the object's mod time so that extensions are
from the "current time." This aligns with how the S3 blob storage
functions.

* Update retention tests to use more precise checks

Where possible, use the information returned by GetRetention in tests
that deal with retention information. This allows for more precise
comparions of retention duration and mode instead of indirectly testing
duration by advancing the clock and attempting to modify blobs.
2023-08-15 16:53:27 +00:00
Julio Lopez
bb7affebda fix(general): change cache full logging frequency & message (#3193)
fix(general): change cache full logging frequency to once every 10 minutes
Addresses concerns about too many messages in the logs (#3085)

fix(general): avoid logging cache key.
Instead log the cache description, which provides information about
the types of contents being cached.

Followups to #3085
2023-08-03 20:27:23 +00:00
Aurélien Rouëné
e98eb371ed fix(cli): log cache full when on debug level (#3085)
Should help fixing #3059
2023-08-03 17:30:28 +00:00
Jarek Kowalski
83b88d8bbf chore(ci): fixes for ARM64 runner on AWS (#3179)
- fixed directory iteration order
- reduced providervalidation memory usage
- disabled one test case of TestSnapshotSparseRestore
  (filed https://github.com/kopia/kopia/issues/3178 to fix)
2023-07-27 11:30:40 -07:00
ashmrtn
2b73527b43 refactor(general): Cleaner error checking in retention tests (#3164)
* More robust error comparisons in retention tests

Update tests for retention to use `ErrorIs` checks instead of comparing
error messages.

* Use `require.NoError` in retention tests

Minor cleanup to reduce branches in code by using `require.NoError`
instead of if-blocks and `t.Fatal`.
2023-07-21 00:29:17 +00:00
Jarek Kowalski
cb98abbc2c feat(snapshots): added ability to use cron expressions to schedule snapshots (#3149)
* feat(snapshots): added ability to use cron expressions to schedule snapshots

We use `github.com/hashicorp/cronexpr` to parse and evaluate expressions,
as documented in https://github.com/hashicorp/cronexpr#implementation

* upgrade ui

* pr feedback
2023-07-19 19:26:17 -07:00
Jarek Kowalski
d8a33bdd44 feat(ui): UI updates (Theming support, action fix) (#3145)
* feat(ui): UI updates (Theming support, action fix)

- theming support https://github.com/kopia/htmlui/pull/150
- actions fix https://github.com/kopia/htmlui/pull/163

* disable dark mode selector test
2023-07-13 21:36:08 -07:00
Christoph Anderson
f42c9fb521 Potential fix for TestLogFileMaxTotalSize. (#3140)
LessOrEquall will return true for edge cases.

Co-authored-by: lupusA <lupuapps@gmail.com>
2023-07-11 20:31:24 +00:00
PhracturedBlue
42aad38540 feat(repository): Implement retention time extension on S3 buckets using Object Locks (#2179)
* Implement ability to extend retention time on S3 buckets using Object Locks
    * Move object-lock extension to maintenance.Params.
    * Use a default function for unsupported extensions instead of duplicating code
    * Fix potential lockup during object-lock extension
    * Fix race condition.  Add more code coverage
    * rebase to V3
* Add checks to prevent user from setting Retention Period  < Full Maintenance Interval

---------

Co-authored-by: Ashlie Martinez <ashmrtnz@alcion.ai>
2023-07-03 16:20:02 -07:00
Jarek Kowalski
cbc66f936d chore(ci): upgraded linter to 1.53.3 (#3079)
* chore(ci): upgraded linter to 1.53.3

This flagged a bunch of unused parameters, so the PR is larger than
usual, but 99% mechanical.

* separate lint CI task

* run Lint in separate CI
2023-06-18 13:26:01 -07:00
Denis Voytyuk
0d7a4de5b7 test(general): added tests for parallelwork (#2942) 2023-04-21 00:11:51 -07:00
Jarek Kowalski
cbc204a2c7 fix(repository): remove metrics.Registry from repo.Repository (#2944) 2023-04-14 19:16:10 -07:00
Denis Voytyuk
5d8e1134c1 test(general): added unit tests for diff (#2931) 2023-04-14 19:05:54 -07:00
Denis Voytyuk
2063a343f3 test(general): added tests for iocopy (#2932) 2023-04-14 16:57:57 -07:00
Denis Voytyuk
36e2b9ff89 test(general): added tests for tlsutil (#2933) 2023-04-14 16:56:46 -07:00
Jarek Kowalski
2568eebc6e chore(general): fixed remaining checklocks violations (#2939)
We can't enable checklocks on CI yet until
https://github.com/google/gvisor/pull/8807 is merged upstream.

This was tested with private build of checklocks with this patch
applied and the results were clean.
2023-04-13 20:11:36 -07:00
Denis Voytyuk
bfeef01d23 test(general): added unit tests for freepool (#2930) 2023-04-13 18:58:16 -07:00
Aaron Alpar
ac8446b028 fix(deps-dev): fixup mutex for make check-locks (#2920) 2023-04-11 15:58:20 -04:00
Shikhar Mall
9f9309ad2a feat(repository): live cache eviction of expired BLOBs in persistent LRU content cache (#2879)
* feat(repository): live cache eviction for persistent lru content cache

* Update internal/cache/persistent_lru_cache.go

Co-authored-by: Ali Dowair <adowair@umich.edu>

* merge the mutex cache into list cache

---------

Co-authored-by: Shikhar Mall <small@kopia.io>
Co-authored-by: Ali Dowair <adowair@umich.edu>
2023-04-08 04:30:45 +00:00
Christoph Anderson
c624b8eece fix(general): Fixed ordering in function "isAbs" in ospath (#2850)
The special case (Windows) has to be checked before "filepath.IsAbs".
The test for internal\ospath now return success.

Co-authored-by: lupusA <lupuapps@gmail.com>
2023-03-31 04:19:14 +00:00
Aaron Alpar
cc7a413d0d fix(general): fix-up *Fault with lock (#2855)
Add concurrency safety for helper functions.

---

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
Co-authored-by: Ali Dowair <adowair@umich.edu>
Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2023-03-28 03:03:56 +00:00
Julio Lopez
a99e38c247 fix(lint): remove uses of deprecated rand.Read (#2858)
Lint fixes in preparation for moving to Go 1.20

Remove deprecated calls to `rand.Seed`
In Go 1.20 the default generator is seeded randomly at program startup,
which is the desired behavior for these tests.

Remove uses of deprecated rand.Read: replace with calls to rand.Uint64()

Remove deprecated uses of rand.Read in content manager tests and
S3 versioned tests.
Adds a concurrency-safe helpers to provide functionality similar to that
provided by `rand.Read(b []byte) (int, error)`
2023-03-28 01:44:09 +00:00
Jarek Kowalski
92291a61e1 feat(repository): added RepositoryWriter.ReplaceManifests (#2747)
This simplifies use cases where we intend to replace a manifest uniquely
identified by a set of labels with another one as is the case for
policies.

This helped fix annoying test flake on Windows where the clock is not
guaranteed to move forward when read in quick succession.

This is now passing on Windows:

```
$ go test -timeout 1000s ./internal/server -run TestSourceRefreshesAfterPolicy -count=1000
```
2023-03-12 00:44:28 +00:00
Jarek Kowalski
6fa50640f4 build(deps): manual upgrade to github.com/alecthomas/kingpin/v2 (#2804)
also upgraded github.com/klauspost/reedsolomon to latest non-retracted version
go mod tidy
2023-03-11 06:28:05 -08:00
Jarek Kowalski
939152cfda chore(ci): upgraded linter to 1.51.1, minor style fixes (#2748) 2023-02-09 06:47:36 +00:00
Jarek Kowalski
2801ab1640 feat(repository): added streaming of FindManifests responses (#2733)
This change adds a new streaming response to the FindManifests API. The
server will deliver the response in chunks of N manifests where N is
requested by the client. This allows the client to process the response
in chunks and improves pipelining of responses.

For now client will hold the entire response in memory since this
is what FindManifests() API currently does. This will be fixed in a
follow up change.

Replaces #2713
Fixes #2660
2023-02-07 06:19:09 -08:00
Jarek Kowalski
e6612977b7 feat(server): improved server shutdown and integration tests (#2722)
* feat(server): improved server shutdown and integration tests

Added `--shutdown-grace-period` flag to `kopia server start` command
which can be used to specify how long the server will wait for active
connections to finish before forcibly shutting down.

This allowed removal of final out-of-process execution of
during integration tests and the need for `integration-tests` target
which was running the same tests as `tests` but in out-of-process mode.

We thus now have all the test coverage in-process without having to
build and launch `kopia` binary.

* fixed logging

* increase test timeout

* speed up and/or parallelize longest-running tests
2023-02-01 22:19:32 -08:00
Edward Betts
1e97574391 fix(general): correct spelling mistakes (#2684) 2023-01-21 07:37:15 -08:00
Jarek Kowalski
f8be8f6a56 refactor(repository): extract parts repo/content into packages (#2651)
- repolog package
- blobcrypto package
- indexblob package

Minor cleanups:

- removed dead code
- introduced New*() methods for object construction
2022-12-17 16:19:12 +00:00
lciti
37d64afc21 fix(snapshots): Partly fix #544 by supporting setuid/setgid/sticky bits when snapshotting, restoring and fuse-mounting. (#2597)
Also modified an end-to-end test to also check that these extra mode flags work when snapshotting+restoring.
Manually tested fuse-mount.

Co-authored-by: Luca Citi <lciti@ieee.org>
2022-12-07 03:26:29 +00:00
Jarek Kowalski
c2cc25c504 feat(repository): added internal/metricid package (#2626)
This manages mapping of metric names to IDs which allows efficient JSON
representation of counter values for each set of metrics where
only values are in the index order.

This will be used in the telemetry protocol and for storing counters in
the repository.

Added test that ensures all metrics registered in a repository have
the corresponding mapping.
2022-12-05 04:41:42 +00:00
Jarek Kowalski
7cc93265ef refactor(repository): moved cache protection to separate package (#2621) 2022-12-03 18:47:01 +00:00