Repository: kopia/kopia
Pull request #3495 (2023-12-08 02:33:59)

refactor(general): minor cleanups
Unexport `epoch.Manager.forceAdvanceEpoch`. It is only used in tests.

Remove unused `RetentionMode` and `RetentionPeriod` fields from
`content.ManagerOptions` struct.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/kopia/kopia/pull/3495?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`6f7d953`)](https://app.codecov.io/gh/kopia/kopia/commit/6f7d95310334db7c41c81f9fe0b05ab9e86b26bb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) 75.85% compared to head [(`22b147a`)](https://app.codecov.io/gh/kopia/kopia/pull/3495?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) 75.81%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3495      +/-   ##
==========================================
- Coverage   75.85%   75.81%   -0.04%     
==========================================
  Files         465      465              
  Lines       37180    37169      -11     
==========================================
- Hits        28203    28180      -23     
- Misses       7050     7059       +9     
- Partials     1927     1930       +3     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/kopia/kopia/pull/3495?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).


Patch:
diff --git a/go.mod b/go.mod
index e996fa13..44fdea86 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
 	github.com/gofrs/flock v0.8.1
 	github.com/golang-jwt/jwt/v4 v4.5.0
 	github.com/golang/protobuf v1.5.3
-	github.com/google/fswalker v0.3.2
+	github.com/google/fswalker v0.3.3-0.20231129010601-c0a7aa51805d
 	github.com/google/go-cmp v0.6.0
 	github.com/google/uuid v1.4.0
 	github.com/gorilla/mux v1.8.1
diff --git a/go.sum b/go.sum
index ae3dad55..207a4bf6 100644
--- a/go.sum
+++ b/go.sum
@@ -138,8 +138,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
 github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/google/fswalker v0.3.2 h1:cVUOO7Ct5kb4YFzmxirZKQSfCyTWEe7e6eBvta9h61Y=
-github.com/google/fswalker v0.3.2/go.mod h1:ZSEBqY0IHKqWPeAbTyvccv9bb9vCnaQfHe31cm911Ng=
+github.com/google/fswalker v0.3.3-0.20231129010601-c0a7aa51805d h1:8W9T0xOCXrjV6Pw5MPNDjxtTVXP5ovN0NFgjzGjX4QU=
+github.com/google/fswalker v0.3.3-0.20231129010601-c0a7aa51805d/go.mod h1:nQzkG8g6cTUBt+VpY9f3DRlhhPwC2t+J+cU8PfDfYWc=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -160,7 +160,6 @@ github.com/google/readahead v0.0.0-20161222183148-eaceba169032 h1:6Be3nkuJFyRfCg
 github.com/google/readahead v0.0.0-20161222183148-eaceba169032/go.mod h1:qYysrqQXuV4tzsizt4oOQ6mrBZQ0xnQXP3ylXX8Jk5Y=
 github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
 github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
-github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
diff --git a/internal/epoch/epoch_manager.go b/internal/epoch/epoch_manager.go
index 7eea4e44..524521d4 100644
--- a/internal/epoch/epoch_manager.go
+++ b/internal/epoch/epoch_manager.go
@@ -256,22 +256,6 @@ func (e *Manager) AdvanceDeletionWatermark(ctx context.Context, ts time.Time) er
 	return nil
 }
 
-// ForceAdvanceEpoch advances current epoch unconditionally.
-func (e *Manager) ForceAdvanceEpoch(ctx context.Context) error {
-	cs, err := e.committedState(ctx, 0)
-	if err != nil {
-		return err
-	}
-
-	e.Invalidate()
-
-	if err := e.advanceEpoch(ctx, cs); err != nil {
-		return errors.Wrap(err, "error advancing epoch")
-	}
-
-	return nil
-}
-
 // Refresh refreshes information about current epoch.
 func (e *Manager) Refresh(ctx context.Context) error {
 	e.mu.Lock()
diff --git a/repo/content/content_manager.go b/repo/content/content_manager.go
index de376a4d..73f42a6e 100644
--- a/repo/content/content_manager.go
+++ b/repo/content/content_manager.go
@@ -944,8 +944,6 @@ func (bm *WriteManager) MetadataCache() cache.ContentCache {
 type ManagerOptions struct {
 	TimeNow                func() time.Time // Time provider
 	DisableInternalLog     bool
-	RetentionMode          string
-	RetentionPeriod        time.Duration
 	PermissiveCacheLoading bool
 }
 


Test patch:
diff --git a/internal/epoch/epoch_manager_test.go b/internal/epoch/epoch_manager_test.go
index 8f007efb..a55bc7bc 100644
--- a/internal/epoch/epoch_manager_test.go
+++ b/internal/epoch/epoch_manager_test.go
@@ -436,11 +436,11 @@ func TestGetCompleteIndexSetRetriesIfTookTooLong(t *testing.T) {
 
 	// advance by 3 epochs to ensure GetCompleteIndexSet will be trying to list some blobs
 	// some blobs that were not fetched during Refresh().
-	te.mgr.ForceAdvanceEpoch(ctx)
+	te.mgr.forceAdvanceEpoch(ctx)
 	te.ft.Advance(1 * time.Hour)
-	te.mgr.ForceAdvanceEpoch(ctx)
+	te.mgr.forceAdvanceEpoch(ctx)
 	te.ft.Advance(1 * time.Hour)
-	te.mgr.ForceAdvanceEpoch(ctx)
+	te.mgr.forceAdvanceEpoch(ctx)
 	te.ft.Advance(1 * time.Hour)
 
 	// load committed state
@@ -495,7 +495,7 @@ func TestSlowWrite_MovesToNextEpoch(t *testing.T) {
 	te.faultyStorage.AddFaults(blobtesting.MethodPutBlob,
 		fault.New().Before(func() {
 			te.ft.Advance(1 * time.Hour)
-			te.mgr.ForceAdvanceEpoch(ctx)
+			te.mgr.forceAdvanceEpoch(ctx)
 		}),
 		fault.New().Before(func() { te.ft.Advance(1 * time.Hour) }))
 
@@ -522,8 +522,8 @@ func TestSlowWrite_MovesToNextEpochTwice(t *testing.T) {
 			te.ft.Advance(24 * time.Hour)
 		}),
 		fault.New().Before(func() {
-			te.mgr.ForceAdvanceEpoch(ctx)
-			te.mgr.ForceAdvanceEpoch(ctx)
+			te.mgr.forceAdvanceEpoch(ctx)
+			te.mgr.forceAdvanceEpoch(ctx)
 		}))
 
 	_, err := te.writeIndexFiles(ctx,
@@ -544,13 +544,13 @@ func TestForceAdvanceEpoch(t *testing.T) {
 	require.NoError(t, err)
 	require.Equal(t, 0, cs.WriteEpoch)
 
-	require.NoError(t, te.mgr.ForceAdvanceEpoch(ctx))
+	require.NoError(t, te.mgr.forceAdvanceEpoch(ctx))
 
 	cs, err = te.mgr.Current(ctx)
 	require.NoError(t, err)
 	require.Equal(t, 1, cs.WriteEpoch)
 
-	require.NoError(t, te.mgr.ForceAdvanceEpoch(ctx))
+	require.NoError(t, te.mgr.forceAdvanceEpoch(ctx))
 
 	cs, err = te.mgr.Current(ctx)
 	require.NoError(t, err)
@@ -581,14 +581,14 @@ func TestInvalid_ForceAdvanceEpoch(t *testing.T) {
 	ctx, cancel := context.WithCancel(testlogging.Context(t))
 	defer cancel()
 
-	err := te.mgr.ForceAdvanceEpoch(ctx)
+	err := te.mgr.forceAdvanceEpoch(ctx)
 	require.ErrorIs(t, err, ctx.Err())
 
 	ctx = testlogging.Context(t)
 	someError := errors.Errorf("failed")
 	te.faultyStorage.AddFault(blobtesting.MethodPutBlob).ErrorInstead(someError)
 
-	err = te.mgr.ForceAdvanceEpoch(ctx)
+	err = te.mgr.forceAdvanceEpoch(ctx)
 	require.ErrorIs(t, err, someError)
 }
 
@@ -816,3 +816,19 @@ type parameterProvider struct {
 func (p parameterProvider) GetParameters() (*Parameters, error) {
 	return p.Parameters, nil
 }
+
+// forceAdvanceEpoch advances current epoch unconditionally.
+func (e *Manager) forceAdvanceEpoch(ctx context.Context) error {
+	cs, err := e.committedState(ctx, 0)
+	if err != nil {
+		return err
+	}
+
+	e.Invalidate()
+
+	if err := e.advanceEpoch(ctx, cs); err != nil {
+		return errors.Wrap(err, "error advancing epoch")
+	}
+
+	return nil
+}