Skip to content

Commit

Permalink
[server] Update freq for removing compliance hold (#731)
Browse files Browse the repository at this point in the history
## Description
- Taking lock at host level to avoid redundant downstream request when
multiple host pick same items.

## Tests
Tested locally.
  • Loading branch information
ua741 authored Mar 7, 2024
1 parent 2101d06 commit 8186246
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/cmd/museum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ func setupAndStartCrons(userAuthRepo *repo.UserAuthRepository, publicCollectionR
trashController.DropFileMetadataCron()
})

schedule(c, "@every 2m", func() {
schedule(c, "@every 90s", func() {
objectController.RemoveComplianceHolds()
})

Expand Down
19 changes: 16 additions & 3 deletions server/pkg/controller/object.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/ente-io/museum/pkg/controller/lock"
Expand Down Expand Up @@ -30,6 +31,10 @@ type ObjectController struct {
complianceCronRunning bool
}

const (
RemoveComplianceHoldsLock = "remove_compliance_holds_lock"
)

// RemoveComplianceHolds removes the Wasabi compliance hold from objects in
// Wasabi for files which have been deleted.
//
Expand All @@ -41,7 +46,6 @@ func (c *ObjectController) RemoveComplianceHolds() {
// Wasabi compliance is currently disabled in config, nothing to do.
return
}

if c.complianceCronRunning {
log.Info("Skipping RemoveComplianceHolds cron run as another instance is still running")
return
Expand All @@ -51,7 +55,16 @@ func (c *ObjectController) RemoveComplianceHolds() {
c.complianceCronRunning = false
}()

items, err := c.QueueRepo.GetItemsReadyForDeletion(repo.RemoveComplianceHoldQueue, 200)
lockStatus := c.LockController.TryLock(RemoveComplianceHoldsLock, time.MicrosecondsAfterHours(24))
if !lockStatus {
log.Warning(fmt.Sprintf("Failed to acquire lock %s", RemoveComplianceHoldsLock))
return
}
defer func() {
c.LockController.ReleaseLock(RemoveComplianceHoldsLock)
}()

items, err := c.QueueRepo.GetItemsReadyForDeletion(repo.RemoveComplianceHoldQueue, 1000)
if err != nil {
log.WithError(err).Error("Failed to fetch items from queue")
return
Expand All @@ -62,7 +75,7 @@ func (c *ObjectController) RemoveComplianceHolds() {
c.removeComplianceHold(i)
}

log.Infof("Revmoed compliance holds on %d deleted files", len(items))
log.Infof("Removed compliance holds on %d deleted files", len(items))
}

func (c *ObjectController) removeComplianceHold(qItem repo.QueueItem) {
Expand Down

0 comments on commit 8186246

Please sign in to comment.