Skip to content

Commit

Permalink
Mutually exclude gc and min replication jobs.
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
dustin committed Sep 24, 2012
1 parent 1d7971c commit 8b26e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions blobs.go
Expand Up @@ -172,6 +172,13 @@ func increaseReplicaCount(oid string, length int64, by int) error {
}

func ensureMinimumReplicaCount() error {
// Don't let this run concurrently with the garbage collector.
// They don't get along.
for taskRunning("garbageCollectBlobs") {
log.Printf("Waiting for gc to finish for ensureMinReplCount")
time.Sleep(5 * time.Second)
}

nl, err := findAllNodes()
if err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions heartbeat.go
Expand Up @@ -235,7 +235,20 @@ func checkStaleNodes() error {
return nil
}

func taskRunning(taskName string) bool {
into := map[string]interface{}{}
err := couchbase.Get("/@"+taskName, &into)
return err == nil
}

func garbageCollectBlobs() error {
// Don't let this run concurrently with the min repl thing.
// They don't get along.
for taskRunning("ensureMinReplCount") {
log.Printf("Waiting for ensureMinReplCount to finish for a gc")
time.Sleep(5 * time.Second)
}

log.Printf("Garbage collecting blobs without any file references")

viewRes := struct {
Expand Down

0 comments on commit 8b26e50

Please sign in to comment.