How does hot-swapping work ? Isn’t that possible in Java too ?
It’s possible in Java, but dynamic classloaders are much more limited in what they can change I think. The Erlang VM and language are designed to have hot-swapping as a core part of the language. It’s really interesting how it all works, but essentially the next time a function from the hot-swapped library is called, it calls the old function and then compiles and maps all the old functions to the new ones. This can work because of really interesting design decisions by the Erlang team.
I am also by no means an expert, so if I’ve made a mistake let me know.
That’s what confuses me. The dependencies have to be hot-swapped too right ?
I suppose the virtual machine performs a transaction on the function lookup table.
What if we get two requests and in-between them the hot-swap occurs ?
Won’t the requests be confused by the new functions ?
When you replace a module the VM maintains two copies of that module, old and current. Existing processes may continue to call the old code. If you replace it again then your old module gets nuked and any processes still using it will get nuked, your current module becomes your old one, and the new one you’re swapping in becomes your current.
Is there a way to monitor the old copy and effectively discard it ?