Fail fast for illegal state stream
Fix counter and reset counter on flush for batch operation