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

chore: Create a new temp object when writing lease all the time. #2776

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

vrongmeal
Copy link
Contributor

@vrongmeal vrongmeal commented Mar 13, 2024

The temp path is generated with a random UUID as suffix.

The temp path is generated with a random UUID as prefix.

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
@vrongmeal vrongmeal requested a review from scsmithr March 13, 2024 09:25
@vrongmeal
Copy link
Contributor Author

@greyscaled we might need a background job to clean up these objects? Not sure if a job exists right now. If there is, might need to modify it.

…passed

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
Comment on lines +249 to +255
if expires_at - LEASE_DURATION + (LEASE_RENEW_INTERVAL / 2) > now {
// Don't acquire a new lease. Let the process use the existing
// lease. This should help in reducing the number of writes to
// the lease object.
return Ok(lease.generation);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scsmithr @tychoish ^

This should really solve everything...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to clarify things:

  • is there a way that the same catalog could be modified or accessed by two tasks/threads within the same process? My concern is that this lease could be (unintentionally) shared between two orthogonal processes.
  • what is the case when the lease is (actually) renewed, and in what cases are leases released? Does this change any of those points?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way that the same catalog could be modified or accessed by two tasks/threads within the same process? My concern is that this lease could be (unintentionally) shared between two orthogonal processes.

So, I just took a better look and process_id refers to the service and not session. So, it's most definitely possible that two threads within the same process modify the same catalog! I should undo this change.

what is the case when the lease is (actually) renewed, and in what cases are leases released? Does this change any of those points?

Lease is renewed after the given interval. A lease is released once the mutation is over (or automatically if it expires).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's most definitely possible that two threads within the same process modify the same catalog! I should undo this change.

Maybe. If this is an existing flaw, and this change doesn't increase the likelihood of a collision, then it's probably safe to commit it. We could also change to something that isn't the process_id.

Copy link
Collaborator

@tychoish tychoish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just questions.

where are the files that would need to be cleaned up in cloud? Is this a change from a previous version.

Comment on lines +249 to +255
if expires_at - LEASE_DURATION + (LEASE_RENEW_INTERVAL / 2) > now {
// Don't acquire a new lease. Let the process use the existing
// lease. This should help in reducing the number of writes to
// the lease object.
return Ok(lease.generation);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to clarify things:

  • is there a way that the same catalog could be modified or accessed by two tasks/threads within the same process? My concern is that this lease could be (unintentionally) shared between two orthogonal processes.
  • what is the case when the lease is (actually) renewed, and in what cases are leases released? Does this change any of those points?

@greyscaled
Copy link
Contributor

where are the files that would need to be cleaned up in cloud? Is this a change from a previous version.

To me, it seems like they would be in sub-dirs of databases/<id>/tmp, based from the code. There is not an existing bg job for this and I appreciate you bringing it up @vrongmeal , creating an issue for it.

@tychoish
Copy link
Collaborator

@vrongmeal I think we discussed closing this because the existing solution (retries) works, we have a longer term plan to solve this issue, and this has some larger in-process concerns.

@scsmithr
Copy link
Member

@vrongmeal I think we discussed closing this because the existing solution (retries) works, we have a longer term plan to solve this issue, and this has some larger in-process concerns.

What's the concern? The code seems reasonable to me.

@vrongmeal
Copy link
Contributor Author

What's the concern? The code seems reasonable to me.

@scsmithr does the lease retention seem fine to you? I had some doubts about retaining a lease by the same process as Sam mentioned, a process might try to modify the same catalog from two different threads. But seems like that problem exists from before. We can merge this in as it is and should be OK (after thinking about it for a bit) but want to know your opinion.

@tychoish
Copy link
Collaborator

What's the concern? The code seems reasonable to me.

Two concurrent operations on the same instance would both assume that they held the lock.

@vrongmeal vrongmeal merged commit 2af96e2 into main Mar 15, 2024
25 checks passed
@vrongmeal vrongmeal deleted the vrongmeal/lease-retries branch March 15, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants