Skip to content

Commit

Permalink
Add unreferenced fossils to the fossil collection instead of deleting…
Browse files Browse the repository at this point in the history
… them immediately
  • Loading branch information
gilbertchen committed May 29, 2018
1 parent f80a5b1 commit e03cd2a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/duplicacy_snapshotmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,13 +2184,9 @@ func (manager *SnapshotManager) pruneSnapshotsExhaustive(referencedFossils map[s
if _, found := referencedChunks[chunk]; found {
manager.resurrectChunk(chunkDir+file, chunk)
} else {
err := manager.storage.DeleteFile(0, chunkDir+file)
if err != nil {
LOG_WARN("FOSSIL_DELETE", "Failed to remove the unreferenced fossil %s: %v", file, err)
} else {
LOG_DEBUG("FOSSIL_DELETE", "Deleted unreferenced fossil %s", file)
fmt.Fprintf(logFile, "Deleted unreferenced fossil %s\n", file)
}
collection.AddFossil(chunkDir + file)
LOG_DEBUG("FOSSIL_FIND", "Found unreferenced fossil %s", file)
fmt.Fprintf(logFile, "Found unreferenced fossil %s\n", file)
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/duplicacy_snapshotmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,36 @@ func TestPruneWithRetentionPolicyAndTag(t *testing.T) {
snapshotManager.PruneSnapshots("vm1@host1", "vm1@host1", []int{}, []string{"manual"}, []string{"0:7"}, false, true, []string{}, false, false, false)
checkTestSnapshots(snapshotManager, 22, 0)
}

// Test that an unreferenced fossil shouldn't be removed as it may be the result of another prune job in-progress.
func TestPruneWithFossils(t *testing.T) {
setTestingT(t)

testDir := path.Join(os.TempDir(), "duplicacy_test", "snapshot_test")

snapshotManager := createTestSnapshotManager(testDir)

chunkSize := 1024
chunkHash1 := uploadRandomChunk(snapshotManager, chunkSize)
chunkHash2 := uploadRandomChunk(snapshotManager, chunkSize)
chunkHash3 := uploadRandomChunk(snapshotManager, chunkSize)
// Create an unreferenced fossil
snapshotManager.storage.UploadFile(0, "chunks/113b6a2350dcfd836829c47304dd330fa6b58b93dd7ac696c6b7b913e6868662.fsl", []byte("this is a test fossil"))

now := time.Now().Unix()
day := int64(24 * 3600)
t.Logf("Creating 2 snapshots")
createTestSnapshot(snapshotManager, "vm1@host1", 1, now-3*day-3600, now-3*day-60, []string{chunkHash1, chunkHash2}, "tag")
createTestSnapshot(snapshotManager, "vm1@host1", 2, now-2*day-3600, now-2*day-60, []string{chunkHash2, chunkHash3}, "tag")
checkTestSnapshots(snapshotManager, 2, 1)

t.Logf("Prune without removing any snapshots but with --exhaustive")
// The unreferenced fossil shouldn't be removed
snapshotManager.PruneSnapshots("vm1@host1", "vm1@host1", []int{}, []string{}, []string{}, true, false, []string{}, false, false, false)
checkTestSnapshots(snapshotManager, 2, 1)

t.Logf("Prune without removing any snapshots but with --exclusive")
// Now the unreferenced fossil should be removed
snapshotManager.PruneSnapshots("vm1@host1", "vm1@host1", []int{}, []string{}, []string{}, false, true, []string{}, false, false, false)
checkTestSnapshots(snapshotManager, 2, 0)
}

0 comments on commit e03cd2a

Please sign in to comment.