84 Commits

Author SHA1 Message Date
Julio López
d1bc68ef61 refactor(general): cleanup nits (#5236)
Cleanup nits:
- get error handling policy upfront and improve readability in uploader
- update error message
- update field documentation and update flag description
- remove unused function
- const `isWindows` and remove redundant condition check
- add `getEnvVarBool` helper
- refactor common helper for mockfs.AddError* functions, and
  add mockfs.AddErrorEntry<Type> wrappers for clarity.
- removed list of skipped tests from gotestsum summary
2026-03-23 11:52:29 -07:00
lyndon-li
83bd4d45da feat(general): maintenance stats for drop deleted contents and compact indexes (#4948) 2025-11-04 11:40:20 -08:00
Julio Lopez
952058a744 refactor(general): fix field names in CompactSingleEpochStats (#4947)
- Followup to #4941
2025-11-02 21:01:10 -08:00
lyndon-li
29ee7b18ea compact single epoch stats (#4941)
Add stats to maintenance phase: `CompactSingleEpoch`
2025-11-02 20:38:23 -08:00
lyndon-li
ed7ef85a2d feat(general): add stats to maintenance run - AdvanceEpoch (#4937) 2025-10-30 23:11:15 -07:00
Julio Lopez
5ca49e8eb4 refactor(general): lastSettledEpochNumber() helper (#4927) 2025-10-28 21:17:45 -07:00
Julio Lopez
2b2efeb031 refactor(general): fix return value order to match return names (#4926) 2025-10-28 18:28:01 -07:00
Julio Lopez
736ee451b9 refactor(general): rename GenerateRangeCheckpointStats fields (#4925)
- Rename GenerateRangeCheckpointStats fields for consistency
- Add marshaling test for GenerateRangeCheckpointStats
2025-10-28 17:32:39 -07:00
lyndon-li
930793c754 feat(general) maintenance stats for generate range checkpoint (#4924) 2025-10-28 16:48:28 -07:00
Julio Lopez
c3dc18f7e5 fix typo (#4920) 2025-10-27 16:12:20 -07:00
lyndon-li
727fea0801 feat(general): add maintenance phase stats - CleanupSupersededIndexes (#4916) 2025-10-27 12:49:38 -07:00
Julio Lopez
25b1492d65 fix(general): field and variable names (#4911)
Fixes field names in CleanupMarkersStats persistent struct.
Also renames variables for consistency.

- Followup fix for: #4900 add stats to maintenance run - CleanupMarkers 
- Ref: #4848
2025-10-24 16:09:36 -07:00
lyndon-li
e3e4e09bc8 feat(general): add stats to maintenance run - CleanupMarkers (#4900) 2025-10-24 13:49:40 -07:00
Julio Lopez
af62386ecd chore(general): modernize min/max (#4898) 2025-10-22 22:22:54 -07:00
Jarek Kowalski
0f7253eb66 feat(general): rewrote content logs to always be JSON-based and reorganized log structure (#4822)
This is a breaking change to users who might be using Kopia as a library.

### Log Format

```json
{"t":"<timestamp-rfc-3389-microseconds>", "span:T1":"V1", "span:T2":"V2", "n":"<source>", "m":"<message>", /*parameters*/}
```

Where each record is associated with one or more spans that describe its scope:

* `"span:client": "<hash-of-username@hostname>"`
* `"span:repo": "<random>"` - random identifier of a repository connection (from `repo.Open`)
* `"span:maintenance": "<random>"` - random identifier of a maintenance session
* `"span:upload": "<hash-of-username@host:/path>"` - uniquely identifies upload session of a given directory
* `"span:checkpoint": "<random>"` - encapsulates each checkpoint operation during Upload
* `"span:server-session": "<random>"` -single client connection to the server
* `"span:flush": "<random>"` - encapsulates each Flush session
* `"span:maintenance": "<random>"` - encapsulates each maintenance operation
* `"span:loadIndex" : "<random>"` - encapsulates index loading operation
* `"span:emr" : "<random>"` - encapsulates epoch manager refresh
* `"span:writePack": "<pack-blob-ID>"` - encapsulates pack blob preparation and writing

(plus additional minor spans for various phases of the maintenance).

Notable points:

- Used internal zero allocation JSON writer for reduced memory usage.
- renamed `--disable-internal-log` to `--disable-repository-log` (controls saving blobs to repository)
- added `--disable-content-log` (controls writing of `content-log` files)
- all storage operations are also logged in a structural way and associated with the corresponding spans.
- all content IDs are logged in a truncated format (since first N bytes that are usually enough to be unique) to improve compressibility of logs (blob IDs are frequently repeated but content IDs usually appear just once).

This format should make it possible to recreate the journey of any single content throughout pack blobs, indexes and compaction events.
2025-09-27 17:11:13 -07:00
Nathan Baulch
19d92613a6 chore(general): typos (#4659) 2025-06-10 17:24:14 -07:00
Julio Lopez
d91a5a8f94 chore(general): enable forcetypeassert linter (#4624)
- enable `forcetypeassert` linter in non-test files
- add `//nolint` annotations
- add `testutil.EnsureType` helper for type assertions
- enable `forcetypeassert` linter in test files
2025-05-31 23:17:38 -07:00
Julio Lopez
31a1fd25ba style(general): cleanup linter config (#4538)
- use 'localmodule' for gci linter config
- enabled 'wastedassign' linter
- remove unused assignment
- prevent re-introducing dependencies
- remove unused //nolint directive
- disable zerologlint linter
2025-04-30 10:37:03 -07:00
Matthieu MOREL
8a176255c0 fix(general): enable wsl for all go files (#4524)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-26 13:01:20 -07:00
Matthieu MOREL
675e958877 chore(ci): bump golangci-lint to v2.1.2 (#4500)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-15 22:49:13 -07:00
Jarek Kowalski
eb1cf64c27 chore(ci): upgraded linter to 1.62.0 (#4250) 2024-11-16 07:16:50 -08:00
Julio López
961a39039b refactor(general): use errors.New where appropriate (#4160)
Replaces 'errors.Errorf\("([^"]+)"\)' => 'errors.New("\1")'
2024-10-05 19:05:00 -07:00
Julio López
1f9f9a1846 chore(general): use non-formatting log variants when there is no formatting (#3931)
Use non-formatting logging functions for message without formatting.
For example, `log.Info("message")` instead of `log.Infof("message")`

Configure linter for printf-like functions
2024-06-18 23:13:17 -07:00
Julio López
4786ab3cbb refactor(general): remove no-longer used functions and tests (#3924)
Followup cleanup for #3919

All the changes are in the `epoch` package

Summary:
- Removal of now unused code and tests.
- Refactoring to simplify test and remove a linter annotation.
- Fix a typo
2024-06-18 12:24:56 -07:00
Julio López
2a79224a33 fix(general): relax epoch compaction check for contiguous ranges (#3919)
While the current implementation should not produce non-contiguous
ranges, this invariant check may be too stringent, in particular for
repositories created and mutated by older kopia (client) processes.

For backwards compatibility the check is relaxed to allow operations to
proceed in older repositories.
2024-06-17 16:25:47 -07:00
Julio López
d9b2aab8b9 fix(general): add parameter to log message (#3904) 2024-06-06 13:44:48 -07:00
Jarek Kowalski
fcb8197f3f chore(ci): upgraded linter to 1.59.0 (#3883) 2024-05-29 20:31:57 -07:00
Julio López
ad06bb20b1 refactor(general): remove ability to enable compaction on index load (#3834)
Cleanup.

- Fixes: #3638
- #3639
2024-05-01 14:33:46 -07:00
Jarek Kowalski
09415e0c7d chore(ci): upgraded to go 1.22 (#3746)
Upgrades go to 1.22 and switches to new-style for loops

---------

Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2024-04-08 09:52:47 -07:00
lvyaoting
67f87a5450 chore(general): fix function names in comment (#3786)
Signed-off-by: lvyaoting <lvyaoting@outlook.com>
2024-04-07 21:33:33 -07:00
Julio López
e600c15b6b fix(general): disable writes on index loads (#3646)
Change default 'allowWritesOnIndexLoad' to false when env var is unset
Add TestNoEpochAdvanceOnIndexRead

Ref:
- Followup to #3645
- Avoid index (epoch) cleanup and compaction during index reads #3638
- Make "read" commands/operations really read-only.  #3639
2024-03-31 22:27:49 -07:00
Julio López
522209369c refactor(test): explicitly advance epoch in TestMaybeCompactSingleEpoch_CompactionError (#3755)
Ref:
- #3638
2024-03-27 12:49:53 -07:00
Julio López
fdb6d3c097 refactor(general): add epoch.Manager.MaybeGenerateRangeCheckpoint (#3727)
* epoch manager: factor out getRangeToCompact
* epoch manager: add epoch.Manager.MaybeGenerateRangeCheckpoint
* test epoch.Manager.MaybeGenerateRangeCheckpoint
2024-03-22 15:29:11 -07:00
Julio López
f8352275ba refactor(general): add epoch.Manager.CleanupMarkers (#3726)
Includes tests for CleanupMarkers
2024-03-19 18:35:29 -07:00
Julio López
6236ff7fba refactor(general): add epoch.Manager.MaybeCompactSingleEpoch (#3728)
Add:
- epoch.Manager.MaybeCompactSingleEpoch
- getCompactedEpochRange helper
- oldestUncompactedEpoch helper
- TestOldestUncompactedEpoch
- Tests for MaybeCompactSingleEpoch

Ref:
- Subset and dependency of #3651
- Depends on #3735
- Avoid index (epoch) cleanup and compaction during index reads #3638
- Make "read" commands/operations really read-only.  #3639
2024-03-19 17:46:45 -07:00
Julio López
316356a031 refactor(general): closedIntRange (#3735)
Refactoring for the original implementation with intRange and
getKeyRange from closed-open ranges [lo, hi) to closed ranges: [lo, hi].
The primary motivation is for consistency with the implementation
of epoch.RangeMetadata in the same package, and thus avoid
confusion and reduce cognitive load.

Changes:

- adds a getContiguousKeyRange wrapper that checks for contiguity.
- getKeyRange simply returns a range with minimum and maximum
  values for the keys in the map.
- changes the range implementation from closed-open ranges [lo, hi)
   to closed ranges: [lo, hi] where both lo and hi are included in the range.
- Additional unit tests are included.
- renames intRange to closedIntRange to reflect new functionality.

Ref:
- Follow up refactor(general): add epoch.getKeyRange helper #3721
- Needed for refactor(general): add epoch.Manager.MaybeCompactSingleEpoch #3728
- Avoid index (epoch) cleanup and compaction during index reads #3638
2024-03-18 22:58:16 -07:00
Julio López
4a06623eb6 refactor(general): add clarification comment (#3723)
Followup to #3721

Co-authored-by: Nick <nick@kasten.io>
2024-03-12 11:52:25 -07:00
Julio López
e143c71e6d refactor(general): add epoch.getKeyRange helper (#3721)
Extracted from #3651.

Thanks to @plar and @redgoat650 for the suggestions.

Ref:

- #3603
- #3645
- #3638
- #3639
2024-03-12 11:05:50 -07:00
Julio López
e347710611 nit: fix comment (#3722) 2024-03-11 22:23:56 -07:00
Jarek Kowalski
29cd545c33 chore(ci): upgrade linter to 1.56.2 (#3714) 2024-03-09 10:39:11 -08:00
Julio López
be49fcd42b refactor(general): add epoch.Manager.MaybeAdvanceEpoch helper (#3709)
Add
- TestMabyeAdvanceEpoch
- TestMabyeAdvanceEpoch_Empty
- TestMaybeAdvanceEpoch_Error
- TestMaybeAdvanceEpoch_GetParametersError

Ref:
- #3638
- #3645
- #3651
2024-03-06 17:12:49 -08:00
Julio López
8d9e8d580e test(general): fix TestIndexEpochManager_CompactionAlwaysFails (#3677) 2024-02-23 20:42:39 -08:00
Jarek Kowalski
524ffaf4b8 refactor(repository): added context to potentially blocking repository methods (#3654)
Primarily for wiring a context.Context to a call to content.Manager.refresh,
which was using a detached context.
2024-02-20 14:48:23 -08:00
Julio López
06ff37fa63 refactor(general): allow disabling writes on index index loads (#3645)
Conditionally disables epoch index maintenance operations when loading indexes.
This prevents (potentially expensive) cleanup write operations on the index
read path.
The behavior is controlled via the `epoch.Manager.allowCleanupWritesOnIndexLoad`
field, which can be temporarily overridden via an environment variable.
This override mechanism will be removed in the near future.

Refs:

- #3174
- #3224
- #3225
- #3638
- #3639
2024-02-16 14:59:06 -08:00
Julio López
1892a9f1d9 refactor(general): move index cleanup out to refreshAttempt (#3603)
Refactor: move index compaction and cleanup out of refreshAttemptLocked

Introduces an `allowWritesOnLoadHelper` to check whether or not writes
can be performed when loading the indexes. Currently this is only
a function of whether the storage is in read-only mode. In the near
future, an explicit flag will be added to control this behavior.

Fix epoch manager: avoid single-epoch compaction when writes are disallowed.
Functional change: prevents compacting single epochs when writes are
disallowed, that is when using read-only storage. Currently, the epoch
manager will attempt to perform single-epoch compactions for all
eligible epochs, even on read-only storage.

Ref:
- #3224
- #3225
- #3638
- #3639
2024-02-16 10:25:58 -08:00
Julio Lopez
871e2e0082 test(general): use require.Eventually to ensure test stops (#3530) 2023-12-19 15:09:56 -08:00
Julio Lopez
a447f34e24 test(general): fix race in TestIndexEpochManager_NoCompactionInReadOnly (#3517) 2023-12-17 23:37:14 -08:00
Julio Lopez
ab8680c997 refactor(general): minor cleanups related to index managers (#3518)
Rename faketime.AutoAdvance parameter to start for clarity

Clarify faketime.ClockTimeWithOffset.Advance documentation

Refactor `faketime.TimeAdvance`:
  Add `faketime.NewAutoAdvance` to create auto-advancing
  `TimeAdvance` clocks.

Refactor faketime.NewTimeAdvance to return non-auto-advancing clocks,
which can still be explicitly advanced.
Removes the now unused `autoDelta` parameter, since it is always 0.

Rename function to `sm.setupCachesAndIndexManagers`
It matches the current implementation better.

Unexport `indexblob.ManagerV1.epochMgr`

Rename function for clarity to `advanceEpochMarker`

Cleanup logs after cleaning up epoch manager.
This is consistent with quick maintenance as well.

Make 'def' a test-local variable instead of a package-level
variable, it is not used outside this test.

Cleanup epoch test newTestEnv()

Misc:
* Reword comment and fix typo
* Fix log message
* `log.Debug` for non-formatted output
2023-12-17 22:21:28 -08:00
Julio Lopez
92e4f165d7 refactor(general): minor cleanups (#3495)
Unexport epoch.Manager.forceAdvanceEpoch. It is only used in tests.
Moved implementation to the `epoch_manager_test.go` file.

Remove `RetentionMode` and `RetentionPeriod` from `content.ManagerOptions` struct
2023-12-08 00:13:17 -08: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