Cleanup the dead nodes when pruning the tree [v9.18]

While sending the node to prune_tree(), we can also cleanup dead nodes because we already hold the tree and node bucket write locks.

(cherry picked from commit be204bf4)

Closes #3641 (closed)

Edited by Ondřej Surý

Merge request reports