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

firehose tombstones #1017

Merged
merged 11 commits into from
Jun 26, 2023
Merged

firehose tombstones #1017

merged 11 commits into from
Jun 26, 2023

Conversation

jesopo
Copy link
Contributor

@jesopo jesopo commented May 9, 2023

to be honest this change seems so simple that i assume the reason it wasn't implemented yet is less to do with spare time and more to do with technical details that need to be worked out, but i thought i'd try my luck anyway

@jesopo
Copy link
Contributor Author

jesopo commented May 10, 2023

(test on its way...)

@dholms
Copy link
Collaborator

dholms commented May 10, 2023

it actually totally had to do with time 😅

we just have a million small things to do that would only take 20 min a piece, but haven't gotten around to

Besides getting the invalidation logic in here, it looks good!

thanks for doing this!

@jesopo jesopo force-pushed the firehose-tombstone branch from f207bce to 5a21854 Compare May 10, 2023 15:59
@@ -151,6 +167,10 @@ export const invalidatePrevHandleOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['handle'])
}

export const invalidatePrevOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['append', 'handle', 'rebase'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

enumerating all the different event types here feels sort of bad and prone to breaking next time an event type is added. i guess i could change the db query in invalidatePrevSeqEvts to just not have a where eventType = clause for this case? thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yknow what I just realized?

We actually delete all the repo_seq events for a user when they delete their account, so there won't be any events to invalidate 😅

I think you're actually good the way it was. Sorry about that!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to prevent a potential footgun where we clear out all of an account's repo_seqs after we create the tombstone op, maybe we add a where eventType != 'tombstone on the repo_seqs deletion in the repo service

@jesopo jesopo requested a review from dholms May 10, 2023 20:44
if (
(frame.header.t === "#commit" && (frame.body as CommitEvt).repo === userDid)
|| (frame.header.t === "#handle" && (frame.body as HandleEvt).did === userDid)
|| (frame.header.t === "#tombstone" && (frame.body as TombstoneEvt).did === userDid)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same thing here wrt enumerating all the types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

though in this situation i don't think there's a better way to extract a did from body without doing this

@Broken60
Copy link

it actually totally had to do with time 😅

we just have a million small things to do that would only take 20 min a piece, but haven't gotten around to

Besides getting the invalidation logic in here, it looks good!

thanks for doing this!

H

@dholms
Copy link
Collaborator

dholms commented May 26, 2023

hey @jesopo wondering if you're planning on getting back to this or if i should get it over the line?

@jesopo
Copy link
Contributor Author

jesopo commented May 26, 2023

what's missing

@dholms
Copy link
Collaborator

dholms commented May 26, 2023

The comments I left here: #1017 (comment)

I led you astray earlier & we actually don't need to invalidate events on the stream, we fully delete them on account deletion. Sorry about the confusion on this!

Plus, Adding in the extra check on account deletion to ensure that we don't delete the tombstone event

@jesopo
Copy link
Contributor Author

jesopo commented May 26, 2023

ah yeah sorry missed that. I'll look at it shortly

@jesopo jesopo closed this May 26, 2023
@jesopo jesopo reopened this May 26, 2023
@jesopo jesopo force-pushed the firehose-tombstone branch from 08b9769 to 06f240c Compare May 28, 2023 01:02
@jesopo
Copy link
Contributor Author

jesopo commented May 28, 2023

@dholms how's that?

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

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

yup this looks good! thanks for putting this together

running tests then i'll merge & deploy soon


const tombstoneEvts = getTombstoneEvts(evts.slice(-2))
verifyTombstoneEvent(tombstoneEvts[0], baddie1)
verifyTombstoneEvent(tombstoneEvts[1], baddie2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

after adding in invalidation - an extra check in this test to ensure that it properly invalidates previous handle & commit events would be cool 👌

@@ -151,6 +167,10 @@ export const invalidatePrevHandleOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['handle'])
}

export const invalidatePrevOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['append', 'handle', 'rebase'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yknow what I just realized?

We actually delete all the repo_seq events for a user when they delete their account, so there won't be any events to invalidate 😅

I think you're actually good the way it was. Sorry about that!

@@ -151,6 +167,10 @@ export const invalidatePrevHandleOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['handle'])
}

export const invalidatePrevOps = async (db: Database, did: string) => {
return invalidatePrevSeqEvts(db, did, ['append', 'handle', 'rebase'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to prevent a potential footgun where we clear out all of an account's repo_seqs after we create the tombstone op, maybe we add a where eventType != 'tombstone on the repo_seqs deletion in the repo service

@jesopo
Copy link
Contributor Author

jesopo commented May 30, 2023

oh i see, your last round of comments were not actually submitted yet and now they are. i shall take a look

@jesopo
Copy link
Contributor Author

jesopo commented May 30, 2023

(also, i will fix tests)

@jesopo
Copy link
Contributor Author

jesopo commented May 30, 2023

Oh yknow what I just realized?

We actually delete all the repo_seq events for a user when they delete their account, so there won't be any events to invalidate 😅

I think you're actually good the way it was. Sorry about that!

are you sure about this? packages/pds/tests/sync/subscribe-repos.test.ts does not return invalidated events is returning a handle event for a user deleted in the previous test (account deletions invalidate all seq ops)

@jesopo
Copy link
Contributor Author

jesopo commented May 30, 2023

async deleteAccount(did: string): Promise<void> {
// Not done in transaction because it would be too long, prone to contention.
// Also, this can safely be run multiple times if it fails.
await this.db.db
.deleteFrom('refresh_token')
.where('did', '=', did)
.execute()
await this.db.db
.deleteFrom('user_account')
.where('user_account.did', '=', did)
.execute()
await this.db.db
.deleteFrom('user_state')
.where('user_state.did', '=', did)
.execute()
await this.db.db
.deleteFrom('did_handle')
.where('did_handle.did', '=', did)
.execute()
}

I don't see repo_seq in here

@dholms
Copy link
Collaborator

dholms commented May 30, 2023

yeah that delete happens in the repo service

services/repo/index.ts line 341
await this.db.db.deleteFrom('repo_seq').where('did', '=', did).execute()

i'll have to check this out to see where the hiccup is happening 🤔

@jesopo
Copy link
Contributor Author

jesopo commented May 30, 2023

race you 🏃

@jesopo jesopo force-pushed the firehose-tombstone branch from 06f240c to 7874d72 Compare May 31, 2023 16:45
@jesopo
Copy link
Contributor Author

jesopo commented May 31, 2023

figured it out - my test was only calling account delete, not repo delete

@jesopo jesopo requested a review from dholms May 31, 2023 16:46
@dholms
Copy link
Collaborator

dholms commented May 31, 2023

(I think CI should start running automatically for your PRs after this one lands)

but in the mean time, mind running yarn verify to fix linting issues?

@dholms
Copy link
Collaborator

dholms commented May 31, 2023

& then we'll finally get this in!

@jesopo
Copy link
Contributor Author

jesopo commented Jun 2, 2023

done(?)

@jesopo
Copy link
Contributor Author

jesopo commented Jun 2, 2023

i believe this won't send tombstones for account takedowns. i imagine that's desired behaviour anyway, but just wanted to check

@dholms dholms changed the base branch from main to firehose-tombstones June 7, 2023 15:49
@dholms dholms changed the base branch from firehose-tombstones to main June 7, 2023 16:00
@dholms
Copy link
Collaborator

dholms commented Jun 8, 2023

(don't hate me there's a merge conflict)

I actually tried to resolve this myself & some of the tests are failing 🤔

I'm really not sure why as none of your changes affect sequencing logic, need to look into it more...

Similar failures as over here: #1173
appears to be double-sequencing some events

@jesopo
Copy link
Contributor Author

jesopo commented Jun 8, 2023

I'll check this eve :)

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

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

:shipit:

@dholms dholms merged commit d9ac72e into bluesky-social:main Jun 26, 2023
mloar pushed a commit to mloar/atproto that referenced this pull request Sep 26, 2023
* firehose tombstones

* return tombstones from sequencer requestSeqRange

* firehose tombstone test

* oops semicolons :3

* yes this can be const

* fix verifyTombstoneEvent func signature

* invalidate all sequence events upon tombstone

* don't manually purge all seqs, test for tombstone after delete

* actually fully delete account

* fix linting

---------

Co-authored-by: Devin Ivy <devinivy@gmail.com>
mloar pushed a commit to mloar/atproto that referenced this pull request Nov 15, 2023
* firehose tombstones

* return tombstones from sequencer requestSeqRange

* firehose tombstone test

* oops semicolons :3

* yes this can be const

* fix verifyTombstoneEvent func signature

* invalidate all sequence events upon tombstone

* don't manually purge all seqs, test for tombstone after delete

* actually fully delete account

* fix linting

---------

Co-authored-by: Devin Ivy <devinivy@gmail.com>
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.

5 participants