how to avoid get ErrBlockedWrites when call DB.DropPrefix and DB.Update on two threads?
You cannot avoid the blocked writes error. The current implementation of drop prefix is a stop world operation which means we stop all the writes and then perform a drop prefix on it. We do plan on making the drop prefix asynchronous (drop prefixes in the background).
How to avoid close of closed channel when DB.Flatten called in two threads?
Flatten is also a stop-world operation and currently, you cannot call it from two threads. Why would you want to make two flatten calls at the same time? The second flatten call would be a no-op anyway.
I think we can improve some of the errors returned by badger. The current behavior is to panic but we should return appropriate errors.