Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Add delay in fileData replication #3960

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/pkg/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/gin-contrib/requestid"
"github.com/sirupsen/logrus"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -340,6 +342,10 @@ func (h *UserHandler) FinishPasskeyAuthenticationCeremony(c *gin.Context) {

err = h.UserController.PasskeyRepo.FinishAuthentication(&user, c.Request, uuid.MustParse(request.CeremonySessionID))
if err != nil {
reqID := requestid.Get(c)
logrus.WithField("req_id", reqID).
WithField("user_id", userID).
WithError(err).Error("Failed to finish passkey authentication ceremony")
handler.Error(c, stacktrace.Propagate(err, ""))
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/pkg/controller/filedata/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Controller) replicate(i int) {
}

func (c *Controller) tryReplicate() error {
newLockTime := enteTime.MicrosecondsAfterMinutes(60)
newLockTime := enteTime.MicrosecondsAfterMinutes(240)
ctx, cancelFun := context.WithTimeout(context.Background(), 20*time.Minute)
defer cancelFun()
row, err := c.Repo.GetPendingSyncDataAndExtendLock(ctx, newLockTime, false)
Expand All @@ -74,7 +74,7 @@ func (c *Controller) tryReplicate() error {
"type": row.Type,
"size": row.Size,
"userID": row.UserID,
}).Errorf("Could not delete file data: %s", err)
}).Errorf("Could not replicate file data: %s", err)
return err
} else {
// If the replication was completed without any errors, we can reset the lock time
Expand Down
6 changes: 4 additions & 2 deletions server/pkg/repo/filedata/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const (
)

func (r *Repository) InsertOrUpdate(ctx context.Context, data filedata.Row) error {
// During insert, we set the sync_locked_till to 5 minutes in the future. This is to prevent
// immediate replication of the file data row, that can result in failure of update/retry requests
query := `
INSERT INTO file_data
(file_id, user_id, data_type, size, latest_bucket)
(file_id, user_id, data_type, size, latest_bucket, sync_locked_till)
VALUES
($1, $2, $3, $4, $5)
($1, $2, $3, $4, $5, now_utc_micro_seconds() + 5 * 60 * 1000*1000)
ON CONFLICT (file_id, data_type)
DO UPDATE SET
size = EXCLUDED.size,
Expand Down
Loading