Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your emulation must be wrong, or my understanding of release handler is wrong (could genuinely be either).
What should happen, I think, is that, when downgrading, the current version of the module is called with code_change with {down, 2}, this returns a state that the old version (1) can understand.
If it isn't that, I don't see how you're supposed to write downgrade clauses.
src/mem3_shards.erl
Outdated
twig:log(notice, "~p code_change ~p ~p", [?MODULE, OldVsn, St]), | ||
upgrade(MaxSize, CurSize, ChangesPid); | ||
|
||
code_change(OldVsn, {st, MaxSize, CurSize, ChangesPid, _, _} = St, _Extra) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this matches the arity of the current state record, this clause will be executed on all future hot upgrades, activating the downgrade code and crashing. You'll need to match the OldVsn here as {down, 2}
to be sure we only do this on actual downgrade.
src/mem3_shards.erl
Outdated
@@ -242,7 +242,48 @@ terminate(_Reason, #st{changes_pid=Pid}) -> | |||
exit(Pid, kill), | |||
ok. | |||
|
|||
code_change(_OldVsn, #st{}=St, _Extra) -> | |||
code_change(OldVsn, {st, MaxSize, CurSize, ChangesPid} = St, _Extra) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would, for safety, match OldVsn as 1
.
2f0ade8
to
22298a7
Compare
@@ -242,7 +242,49 @@ terminate(_Reason, #st{changes_pid=Pid}) -> | |||
exit(Pid, kill), | |||
ok. | |||
|
|||
code_change(_OldVsn, #st{}=St, _Extra) -> | |||
code_change(1 = OldVsn, {st, MaxSize, CurSize, ChangesPid} = St, _Extra) -> | |||
twig:log(notice, "~p code_change ~p ~p", [?MODULE, OldVsn, St]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log line was just for you while figuring this out or is it useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was helpful for debugging, and since it should only happen once, I figured I might as well leave it in. Do you want me to remove the logging?
src/mem3_shards.erl
Outdated
code_change({down, 2} = OldVsn, St, _Extra) -> | ||
{st, MaxSize, CurSize, ChangesPid, _, _} = St, | ||
twig:log(notice, "~p code_change ~p ~p", [?MODULE, OldVsn, St]), | ||
downgrade(MaxSize, CurSize, ChangesPid). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep a code change clause that matches on #st{} so we don't screw ourselves over on the next release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call -- PR updated with default clause
I tested the upgrade and downgrade paths by first making sure mem3_shards was compiled from tag 3.9.2, then updating the source with this patch, recompiling, then in a remsh