Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Add preupgrade hook #129

Closed
wants to merge 15 commits into from
Closed

Add preupgrade hook #129

wants to merge 15 commits into from

Conversation

kasperisager
Copy link
Contributor

@kasperisager kasperisager commented Aug 11, 2022

Closes #128

index.js Outdated Show resolved Hide resolved
@mafintosh
Copy link
Collaborator

@kasperisager whats the preupgradeLength needed for here?

@kasperisager
Copy link
Contributor Author

@mafintosh It's returned from core.length if set.

@mafintosh
Copy link
Collaborator

and we can't just use the snapshot mechanic for that always?

@kasperisager
Copy link
Contributor Author

@mafintosh We can totally do that, that should simplify things a tad 👍

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
}

onupgrade (request) {
if (this.active) this.active.cancel()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures that only 1 upgrade is active at a time by cancelling previous upgrades as new ones are applied. Not 100% sure if that's what we're after though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

either this, or it "debounces", ie reruns the hook

lib/upgrader.js Outdated Show resolved Hide resolved
lib/upgrader.js Outdated Show resolved Hide resolved

if (this.upgrader.preupgrade) session._updateSnapshot()

let upgraded = await request
Copy link
Collaborator

Choose a reason for hiding this comment

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

whats stopping us from awating the request in update itself? seems cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to do session._updateSnapshot() before the update is applied to the core to keep the session on the preupgrade length.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is session here, the session the user called .update on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep (this):

this._upgrader = new Upgrader(this, opts)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, will see what we can do to improve this, but ok for now.

@kasperisager kasperisager marked this pull request as ready for review August 15, 2022 11:40
@kasperisager kasperisager requested a review from mafintosh August 15, 2022 11:40
@mafintosh
Copy link
Collaborator

@kasperisager sorry to do this, but can you move this to hypercore-protocol/hypercore ?

@kasperisager
Copy link
Contributor Author

@mafintosh No problem at all! Rebased onto latest master and moved to holepunchto/hypercore#300.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

preupgrade hook
2 participants