Skip to content

Commit

Permalink
Align snapshot times to the beginning of days when calculating the di…
Browse files Browse the repository at this point in the history
…fferences
  • Loading branch information
gilbertchen committed Sep 9, 2018
1 parent 674d35e commit 22a0b22
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/duplicacy_snapshotmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ func (collection *FossilCollection) IsEmpty() bool {
return len(collection.Fossils) == 0 && len(collection.Temporaries) == 0
}

// Calculates the number of days between two times ignoring the hours, minutes and seconds.
func getDaysBetween(start int64, end int64) int {
startTime := time.Unix(start, 0).In(time.Now().Location())
endTime := time.Unix(end, 0).In(time.Now().Location())
startDate := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 0, 0, 0, 0, startTime.Location())
endDate := time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, endTime.Location())
hours := int(endDate.Sub(startDate).Hours())
return (hours + 1) / 24
}

// SnapshotManager is mainly responsible for downloading, and deleting snapshots.
type SnapshotManager struct {

Expand Down Expand Up @@ -1907,7 +1917,7 @@ func (manager *SnapshotManager) PruneSnapshots(selfID string, snapshotID string,

// Find out which retent policy applies based on the age.
for i < len(retentionPolicies) &&
int(now-snapshot.StartTime) < retentionPolicies[i].Age*secondsInDay {
getDaysBetween(snapshot.StartTime, now) < retentionPolicies[i].Age {
i++
lastSnapshotTime = 0
}
Expand All @@ -1920,9 +1930,8 @@ func (manager *SnapshotManager) PruneSnapshots(selfID string, snapshotID string,
snapshot.Flag = true
toBeDeleted++
} else if lastSnapshotTime != 0 &&
int(snapshot.StartTime-lastSnapshotTime) < retentionPolicies[i].Interval*secondsInDay-600 {
// Delete the snapshot if it is too close to the last kept one. Note that a tolerance of 10
// minutes was subtracted from the interval.
getDaysBetween(lastSnapshotTime, snapshot.StartTime) < retentionPolicies[i].Interval {
// Delete the snapshot if it is too close to the last kept one.
LOG_DEBUG("SNAPSHOT_DELETE", "Snapshot %s at revision %d to be deleted - older than %d days, less than %d days from previous",
snapshot.ID, snapshot.Revision, retentionPolicies[i].Age, retentionPolicies[i].Interval)
snapshot.Flag = true
Expand Down

1 comment on commit 22a0b22

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

http://forum.duplicacy.com/t/impact-of-prune-on-storage-copy-operations/861/19

Please sign in to comment.