Commit 56b8a015 authored by Sebastian Stark's avatar Sebastian Stark

make all transition return an error

  - eliminates all remaining non-fatal log.Fatal()s
  - situation is now detected when rsync returned without an error
  but still did not create a snapshot
parent 40dbbb57
......@@ -34,7 +34,10 @@ func prune(q chan *snapshot, cl clock) {
(config.MaxKeep != 0) {
debugf("%d snapshots in oldest interval", len(iv))
log.Printf("mark oldest as obsolete: %s", iv[0])
iv[0].transObsolete()
err := iv[0].transObsolete()
if err != nil {
log.Printf("could not transition snapshot: %s", err)
}
q <- iv[0]
pruneAgain = true
}
......@@ -44,7 +47,10 @@ func prune(q chan *snapshot, cl clock) {
dist := iv[youngest].startTime.Sub(iv[secondYoungest].startTime)
if dist.Seconds() < intervals[i].Seconds() {
log.Printf("mark as obsolete: %s", iv[youngest].Name())
iv[youngest].transObsolete()
err := iv[youngest].transObsolete()
if err != nil {
log.Printf("could not transition snapshot: %s", err)
}
q <- iv[youngest]
pruneAgain = true
}
......
......@@ -144,7 +144,10 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
return nil, fmt.Errorf("rsync failed: %s", err)
}
}
newSn.transComplete(cl)
err = newSn.transComplete(cl)
if err != nil {
return nil, err
}
log.Println("finished:", newSn.Name())
return newSn, nil
}
......
......@@ -85,11 +85,11 @@ func (s *snapshot) FullName() string {
}
// transComplete transitions the receiver to complete state.
func (s *snapshot) transComplete(cl clock) {
func (s *snapshot) transComplete(cl clock) error {
oldName := s.FullName()
etime := cl.Now()
if etime.Before(s.startTime) {
log.Fatal("endTime before startTime!")
return errors.New("endTime before startTime!")
}
// make all snapshots at least 1 second long
if etime.Sub(s.startTime).Seconds() < 1 {
......@@ -102,44 +102,47 @@ func (s *snapshot) transComplete(cl clock) {
if oldName != newName {
err := os.Rename(oldName, newName)
if err != nil {
log.Fatal(err)
return err
}
}
updateSymlinks()
overwriteSymlink(filepath.Join(dataSubdir, s.Name()), filepath.Join(config.repository, "latest"))
return nil
}
// transObsolete transitions the receiver to obsolete state.
func (s *snapshot) transObsolete() {
func (s *snapshot) transObsolete() error {
oldName := s.FullName()
s.state = stateObsolete
newName := s.FullName()
if oldName != newName {
err := os.Rename(oldName, newName)
if err != nil {
log.Fatal(err)
return err
}
}
updateSymlinks()
return nil
}
// transPurging transitions the receiver to purging state.
func (s *snapshot) transPurging() {
func (s *snapshot) transPurging() error {
oldName := s.FullName()
s.state = statePurging
newName := s.FullName()
if oldName != newName {
err := os.Rename(oldName, newName)
if err != nil {
log.Fatal(err)
return err
}
}
return nil
}
// transIncomplete generates a new incomplete snapshot based on a previous one.
// Can be used to try to use previous incomplete snapshots, or even to reuse
// obsolete ones.
func (s *snapshot) transIncomplete(cl clock) {
func (s *snapshot) transIncomplete(cl clock) error {
oldName := s.FullName()
s.startTime = cl.Now()
s.endTime = time.Time{}
......@@ -149,9 +152,10 @@ func (s *snapshot) transIncomplete(cl clock) {
if oldName != newName {
err := os.Rename(oldName, newName)
if err != nil {
log.Fatal(err)
return err
}
}
return nil
}
// purge deletes the receiver snapshot from disk.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment