Skip to content

[db] Improve handling of soft-deleted entries #17081

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

Merged
merged 1 commit into from
Mar 30, 2023
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
2 changes: 1 addition & 1 deletion components/gitpod-db/src/periodic-deleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class PeriodicDbDeleter {
for (const i in rows) {
const row = rows[i];
const whereClause = whereClauseFn(row);
deletions.push(`DELETE FROM ${table.name} WHERE ${whereClause};`);
deletions.push(`DELETE FROM ${table.name} WHERE ${whereClause} AND ${deletionColumn} = true;`);
Copy link
Member

Choose a reason for hiding this comment

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

For my understanding, this ensures that between the time when we run the select, and the time when we run the DELETE, the deletion field remains unaffected

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.

}

return result;
Expand Down
7 changes: 6 additions & 1 deletion components/server/src/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ export class UserService {
if (userUpdate) {
userUpdate(newUser);
}
newUser.identities.push(identity);
// HINT: we need to specify `deleted: false` here, so that any attempt to reuse the same
// entry would converge to a valid state. The identities are identified by the external
// `authId`, and if accounts are deleted, such entries are soft-deleted until the periodic
// deleter will take care of them. Reuse of soft-deleted entries would lead to an invalid
// state. This measure of prevention is considered in the period deleter as well.
newUser.identities.push({ ...identity, deleted: false });
this.handleNewUser(newUser, isFirstUser);
newUser = await this.userDb.storeUser(newUser);
if (token) {
Expand Down