closes #5930. Merge branch '5930-smalldocfix'
[arvados.git] / services / keepstore / handlers.go
index cf5dfcac57a2e93b1bde9fa8a2bfcc60d01a186c..8930b79c338883327b404c2a39375f54cdf3dec3 100644 (file)
@@ -19,7 +19,6 @@ import (
        "net/http"
        "os"
        "regexp"
-       "runtime"
        "strconv"
        "strings"
        "syscall"
@@ -126,10 +125,6 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 }
 
 func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
-       // Garbage collect after each PUT. Fixes #2865.
-       // See also GetBlockHandler.
-       defer runtime.GC()
-
        hash := mux.Vars(req)["hash"]
 
        // Detect as many error conditions as possible before reading
@@ -525,6 +520,7 @@ func GetBlock(hash string, update_timestamp bool) ([]byte, error) {
                        log.Printf("%s: checksum mismatch for request %s (actual %s)\n",
                                vol, hash, filehash)
                        error_to_caller = DiskHashError
+                       bufs.Put(buf)
                        continue
                }
                if error_to_caller == DiskHashError {
@@ -536,6 +532,7 @@ func GetBlock(hash string, update_timestamp bool) ([]byte, error) {
                                error_to_caller = GenericError
                                log.Printf("%s: Touch %s failed: %s",
                                        vol, hash, error_to_caller)
+                               bufs.Put(buf)
                                continue
                        }
                }
@@ -586,6 +583,7 @@ func PutBlock(block []byte, hash string) error {
        // so there is nothing special to do if err != nil.
        //
        if oldblock, err := GetBlock(hash, true); err == nil {
+               defer bufs.Put(oldblock)
                if bytes.Compare(block, oldblock) == 0 {
                        // The block already exists; return success.
                        return nil