Add a method acknowledgeAll to the state.
For nonRecoverableState this removes from memory, for persistent state this removes from persistent storage, also needs to release refs as you have mentioned.
Don't worry about transactional state.
If a ref has been removed and a tx subsequently tries to ack it then it will just be ignored. Alternatively we could throw an exception at this point but I don't really see the need for that.
Also need to lock the channel exclusively for the duration of the operation.
For Topics, there is a problem with removeAllMessages() because multiple subscriptions may have different states.
e.g. There are two subscriptions for a Topic and one of them is durable but offline; another is online. Messages sent to the Topic are successfully delivered to the online subscription's receiver but are still held in the offline subscription. And if now removeAllMessages() is applied, then all held messages in the offline subscription will disappear. From the Topic's point of view, different messages are removed from different subscriptions. This makes removeAllMessages() an undefined operation.
This can be done by locking all the channels corresponding to subscriptions for the topic and removing first their in memory state, then removing the state of any surable subs for the topic directly in the db.