registor.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "registor.h"
  2. // local
  3. #include "comm.h"
  4. int CRegistor::Regist() {
  5. DTC::SvrAdminRequest rq(_master);
  6. rq.SetAdminCode(DTC::RegisterHB);
  7. // 发送自己的JournalID
  8. JournalID self = _controller.JournalId();
  9. log4cplus_info("registed to master, master[serial=%u, offset=%u]",
  10. self.serial , self.offset);
  11. rq.SetHotBackupID((uint64_t) self);
  12. DTC::Result rs;
  13. rq.Execute(rs);
  14. switch (rs.ResultCode()) {
  15. case -DTC::EC_INC_SYNC_STAGE:
  16. {
  17. log4cplus_warning("server report: \"INC-SYNC\"");
  18. _master_ctime = QueryMemoryCreateTime(_master, 1);
  19. if (_master_ctime <= 0)
  20. {
  21. log4cplus_debug("master mem time: %lld",(long long int)_master_ctime);
  22. log4cplus_error("share memory create time changed");
  23. return -DTC::EC_ERR_SYNC_STAGE;
  24. }
  25. return -DTC::EC_INC_SYNC_STAGE;
  26. }
  27. break;
  28. case -DTC::EC_FULL_SYNC_STAGE:
  29. {
  30. log4cplus_warning("server report: \"FULL-SYNC\"");
  31. _master_ctime = QueryMemoryCreateTime(_master, 1);
  32. if (_master_ctime <= 0)
  33. {
  34. log4cplus_debug("master mem time: %lld",(long long int)_master_ctime);
  35. log4cplus_error("share memory create time changed");
  36. return -DTC::EC_ERR_SYNC_STAGE;
  37. }
  38. _controller.JournalId() = rs.HotBackupID();
  39. log4cplus_info
  40. ("registed to master, master[serial=%u, offset=%u]",
  41. _controller.JournalId().serial,
  42. _controller.JournalId().offset);
  43. return -DTC::EC_FULL_SYNC_STAGE;
  44. }
  45. break;
  46. default:
  47. {
  48. log4cplus_warning("server report: \"ERR-SYNC\"");
  49. return -DTC::EC_ERR_SYNC_STAGE;
  50. }
  51. break;
  52. }
  53. return 0;
  54. };