refactor server_replication
1. refactor session  "Handling control requests"
2. fix code style problems