go: make object reclaim age configurable

Change-Id: I960756762e8e46a613f14a2b01189748e65841f0
This commit is contained in:
Greg Lange
2016-03-09 21:33:25 +00:00
parent 3c4468b821
commit 05c87dbab5
4 changed files with 23 additions and 17 deletions

View File

@@ -196,7 +196,7 @@ func InvalidateHash(hashDir string) error {
return tempFile.Save()
}
func HashCleanupListDir(hashDir string, logger hummingbird.LoggingContext) ([]string, *hummingbird.BackendError) {
func HashCleanupListDir(hashDir string, reclaimAge int64, logger hummingbird.LoggingContext) ([]string, *hummingbird.BackendError) {
fileList, err := hummingbird.ReadDirNames(hashDir)
returnList := []string{}
if err != nil {
@@ -219,7 +219,7 @@ func HashCleanupListDir(hashDir string, logger hummingbird.LoggingContext) ([]st
withoutSuffix = strings.Split(withoutSuffix, "_")[0]
}
timestamp, _ := strconv.ParseFloat(withoutSuffix, 64)
if time.Now().Unix()-int64(timestamp) > int64(hummingbird.ONE_WEEK) {
if time.Now().Unix()-int64(timestamp) > reclaimAge {
os.RemoveAll(hashDir + "/" + filename)
return returnList, nil
}
@@ -249,7 +249,7 @@ func HashCleanupListDir(hashDir string, logger hummingbird.LoggingContext) ([]st
return returnList, nil
}
func RecalculateSuffixHash(suffixDir string, logger hummingbird.LoggingContext) (string, *hummingbird.BackendError) {
func RecalculateSuffixHash(suffixDir string, reclaimAge int64, logger hummingbird.LoggingContext) (string, *hummingbird.BackendError) {
// the is hash_suffix in swift
h := md5.New()
@@ -262,7 +262,7 @@ func RecalculateSuffixHash(suffixDir string, logger hummingbird.LoggingContext)
}
for _, fullHash := range hashList {
hashPath := suffixDir + "/" + fullHash
fileList, err := HashCleanupListDir(hashPath, logger)
fileList, err := HashCleanupListDir(hashPath, reclaimAge, logger)
if err != nil {
if err.Code == hummingbird.PathNotDirErrorCode {
if QuarantineHash(hashPath) == nil {
@@ -283,7 +283,7 @@ func RecalculateSuffixHash(suffixDir string, logger hummingbird.LoggingContext)
return hex.EncodeToString(h.Sum(nil)), nil
}
func GetHashes(driveRoot string, device string, partition string, recalculate []string, logger hummingbird.LoggingContext) (map[string]string, *hummingbird.BackendError) {
func GetHashes(driveRoot string, device string, partition string, recalculate []string, reclaimAge int64, logger hummingbird.LoggingContext) (map[string]string, *hummingbird.BackendError) {
partitionDir := filepath.Join(driveRoot, device, "objects", partition)
pklFile := filepath.Join(partitionDir, "hashes.pkl")
@@ -329,7 +329,7 @@ func GetHashes(driveRoot string, device string, partition string, recalculate []
if hash == "" {
modified = true
suffixDir := driveRoot + "/" + device + "/objects/" + partition + "/" + suffix
recalc_hash, err := RecalculateSuffixHash(suffixDir, logger)
recalc_hash, err := RecalculateSuffixHash(suffixDir, reclaimAge, logger)
if err == nil {
hashes[suffix] = recalc_hash
} else {
@@ -359,7 +359,7 @@ func GetHashes(driveRoot string, device string, partition string, recalculate []
return hashes, nil
}
logger.LogError("Made recursive call to GetHashes: %s", partitionDir)
return GetHashes(driveRoot, device, partition, recalculate, logger)
return GetHashes(driveRoot, device, partition, recalculate, reclaimAge, logger)
}
}
return hashes, nil

View File

@@ -22,6 +22,8 @@ import (
"strings"
"testing"
"github.com/openstack/swift/go/hummingbird"
"github.com/stretchr/testify/assert"
)
@@ -59,7 +61,7 @@ func TestGetHashes(t *testing.T) {
f, _ = os.Create(driveRoot + "/sda/objects/1/abc/00000000000000000000000000000abc/67890.data")
defer f.Close()
hashes, err := GetHashes(driveRoot, "sda", "1", nil, nil)
hashes, err := GetHashes(driveRoot, "sda", "1", nil, int64(hummingbird.ONE_WEEK), nil)
assert.Nil(t, err)
assert.Equal(t, "b1589029b7db9d01347caece2159d588", hashes["abc"])
@@ -68,12 +70,12 @@ func TestGetHashes(t *testing.T) {
f.Close()
// make sure hash for "abc" isn't recalculated yet.
hashes, err = GetHashes(driveRoot, "sda", "1", nil, nil)
hashes, err = GetHashes(driveRoot, "sda", "1", nil, int64(hummingbird.ONE_WEEK), nil)
assert.Nil(t, err)
assert.Equal(t, "b1589029b7db9d01347caece2159d588", hashes["abc"])
// force recalculate of "abc"
hashes, err = GetHashes(driveRoot, "sda", "1", []string{"abc"}, nil)
hashes, err = GetHashes(driveRoot, "sda", "1", []string{"abc"}, int64(hummingbird.ONE_WEEK), nil)
assert.Nil(t, err)
assert.Equal(t, "8834e84467693c2e8f670f4afbea5334", hashes["abc"])
}

View File

@@ -55,6 +55,7 @@ type ObjectServer struct {
expiringDivisor int64
updateClient *http.Client
replicateTimeout time.Duration
reclaimAge int64
}
func (server *ObjectServer) ObjGetHandler(writer http.ResponseWriter, request *http.Request) {
@@ -312,7 +313,7 @@ func (server *ObjectServer) ObjPutHandler(writer http.ResponseWriter, request *h
return
}
go func() {
HashCleanupListDir(hashDir, hummingbird.GetLogger(request))
HashCleanupListDir(hashDir, server.reclaimAge, hummingbird.GetLogger(request))
if fd, err := syscall.Open(hashDir, syscall.O_DIRECTORY|os.O_RDONLY, 0666); err == nil {
syscall.Fsync(fd)
syscall.Close(fd)
@@ -427,7 +428,7 @@ func (server *ObjectServer) ObjDeleteHandler(writer http.ResponseWriter, request
return
}
go func() {
HashCleanupListDir(hashDir, hummingbird.GetLogger(request))
HashCleanupListDir(hashDir, server.reclaimAge, hummingbird.GetLogger(request))
if fd, err := syscall.Open(hashDir, syscall.O_DIRECTORY|os.O_RDONLY, 0666); err == nil {
syscall.Fsync(fd)
syscall.Close(fd)
@@ -445,7 +446,7 @@ func (server *ObjectServer) ObjReplicateHandler(writer http.ResponseWriter, requ
if len(vars["suffixes"]) > 0 {
recalculate = strings.Split(vars["suffixes"], "-")
}
hashes, err := GetHashes(server.driveRoot, vars["device"], vars["partition"], recalculate, hummingbird.GetLogger(request))
hashes, err := GetHashes(server.driveRoot, vars["device"], vars["partition"], recalculate, server.reclaimAge, hummingbird.GetLogger(request))
if err != nil {
hummingbird.StandardResponse(writer, http.StatusInternalServerError)
return
@@ -489,7 +490,7 @@ func (server *ObjectServer) ObjRepConnHandler(writer http.ResponseWriter, reques
var hashes map[string]string
if brr.NeedHashes {
var herr *hummingbird.BackendError
hashes, herr = GetHashes(server.driveRoot, brr.Device, brr.Partition, nil, hummingbird.GetLogger(request))
hashes, herr = GetHashes(server.driveRoot, brr.Device, brr.Partition, nil, server.reclaimAge, hummingbird.GetLogger(request))
if herr != nil {
hummingbird.GetLogger(request).LogError("[ObjRepConnHandler] Error getting hashes: %v", herr)
writer.WriteHeader(http.StatusInternalServerError)
@@ -548,7 +549,7 @@ func (server *ObjectServer) ObjRepConnHandler(writer http.ResponseWriter, reques
return rc.SendMessage(FileUploadResponse{Msg: "upload failed"})
}
if dataFile != "" || metaFile != "" {
HashCleanupListDir(hashDir, hummingbird.GetLogger(request))
HashCleanupListDir(hashDir, server.reclaimAge, hummingbird.GetLogger(request))
}
InvalidateHash(hashDir)
err = rc.SendMessage(FileUploadResponse{Success: true, Msg: "YAY"})
@@ -720,6 +721,7 @@ func GetServer(conf string, flags *flag.FlagSet) (bindIP string, bindPort int, s
server.logger = hummingbird.SetupLogger(serverconf.GetDefault("app:object-server", "log_facility", "LOG_LOCAL1"), "object-server", "")
server.replicationMan = NewReplicationManager(serverconf.GetLimit("app:object-server", "replication_limit", 3, 100))
server.updateClient = &http.Client{Timeout: time.Second * 15}
server.reclaimAge = int64(serverconf.GetInt("app:object-server", "reclaim_age", int64(hummingbird.ONE_WEEK)))
deviceLockUpdateSeconds := serverconf.GetInt("app:object-server", "device_lock_update_seconds", 0)
if deviceLockUpdateSeconds > 0 {

View File

@@ -88,6 +88,7 @@ type Replicator struct {
partitions []string
priRepChans map[int]chan PriorityRepJob
priRepM sync.Mutex
reclaimAge int64
/* stats accounting */
startTime time.Time
@@ -343,7 +344,7 @@ func (r *Replicator) replicateLocal(j *job, nodes []*hummingbird.Device, moreNod
startGetHashesLocal := time.Now()
recalc := []string{}
hashes, herr := GetHashes(r.driveRoot, j.dev.Device, j.partition, recalc, r)
hashes, herr := GetHashes(r.driveRoot, j.dev.Device, j.partition, recalc, r.reclaimAge, r)
if herr != nil {
r.LogError("[replicateLocal] error getting local hashes: %v", herr)
return
@@ -356,7 +357,7 @@ func (r *Replicator) replicateLocal(j *job, nodes []*hummingbird.Device, moreNod
}
}
}
hashes, herr = GetHashes(r.driveRoot, j.dev.Device, j.partition, recalc, r)
hashes, herr = GetHashes(r.driveRoot, j.dev.Device, j.partition, recalc, r.reclaimAge, r)
if herr != nil {
r.LogError("[replicateLocal] error recalculating local hashes: %v", herr)
return
@@ -753,6 +754,7 @@ func NewReplicator(conf string, flags *flag.FlagSet) (hummingbird.Daemon, error)
replicator.bindIp = serverconf.GetDefault("object-replicator", "bind_ip", "0.0.0.0")
replicator.bindPort = int(serverconf.GetInt("object-replicator", "replicator_bind_port", int64(replicator.port+500)))
replicator.quorumDelete = serverconf.GetBool("object-replicator", "quorum_delete", false)
replicator.reclaimAge = int64(serverconf.GetInt("object-replicator", "reclaim_age", int64(hummingbird.ONE_WEEK)))
replicator.logger = hummingbird.SetupLogger(serverconf.GetDefault("object-replicator", "log_facility", "LOG_LOCAL0"), "object-replicator", "")
if serverconf.GetBool("object-replicator", "vm_test_mode", false) {
replicator.timePerPart = time.Duration(serverconf.GetInt("object-replicator", "ms_per_part", 2000)) * time.Millisecond