Move thread_id generation code from database.cc to message.cc