| 148 | } |
| 149 | |
| 150 | int Instance :: ProtectionLogic_IsCheckpointInstanceIDCorrect(const uint64_t llCPInstanceID, const uint64_t llLogMaxInstanceID) |
| 151 | { |
| 152 | if (llCPInstanceID <= llLogMaxInstanceID + 1) |
| 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | //checkpoint_instanceid larger than log_maxinstanceid+1 will appear in the following situations |
| 158 | //1. Pull checkpoint from other node automatically and restart. (normal case) |
| 159 | //2. Paxos log was manually all deleted. (may be normal case) |
| 160 | //3. Paxos log is lost because Options::bSync set as false. (bad case) |
| 161 | //4. Checkpoint data corruption results an error checkpoint_instanceid. (bad case) |
| 162 | //5. Checkpoint data copy from other node manually. (bad case) |
| 163 | //In these bad cases, paxos log between [log_maxinstanceid, checkpoint_instanceid) will not exist |
| 164 | //and checkpoint data maybe wrong, we can't ensure consistency in this case. |
| 165 | |
| 166 | if (llLogMaxInstanceID == 0) |
| 167 | { |
| 168 | //case 1. Automatically pull checkpoint will delete all paxos log first. |
| 169 | //case 2. No paxos log. |
| 170 | //If minchosen instanceid < checkpoint instanceid. |
| 171 | //Then Fix minchosen instanceid to avoid that paxos log between [log_maxinstanceid, checkpoint_instanceid) not exist. |
| 172 | //if minchosen isntanceid > checkpoint.instanceid. |
| 173 | //That probably because the automatic pull checkpoint did not complete successfully. |
| 174 | uint64_t llMinChosenInstanceID = m_oCheckpointMgr.GetMinChosenInstanceID(); |
| 175 | if (m_oCheckpointMgr.GetMinChosenInstanceID() != llCPInstanceID) |
| 176 | { |
| 177 | int ret = m_oCheckpointMgr.SetMinChosenInstanceID(llCPInstanceID); |
| 178 | if (ret != 0) |
| 179 | { |
| 180 | PLGErr("SetMinChosenInstanceID fail, now minchosen %lu max instanceid %lu checkpoint instanceid %lu", |
| 181 | m_oCheckpointMgr.GetMinChosenInstanceID(), llLogMaxInstanceID, llCPInstanceID); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | PLGStatus("Fix minchonse instanceid ok, old minchosen %lu now minchosen %lu max %lu checkpoint %lu", |
| 186 | llMinChosenInstanceID, m_oCheckpointMgr.GetMinChosenInstanceID(), |
| 187 | llLogMaxInstanceID, llCPInstanceID); |
| 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | //other case. |
| 195 | PLGErr("checkpoint instanceid %lu larger than log max instanceid %lu. " |
| 196 | "Please ensure that your checkpoint data is correct. " |
| 197 | "If you ensure that, just delete all paxos log data and restart.", |
| 198 | llCPInstanceID, llLogMaxInstanceID); |
| 199 | return -2; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | int Instance :: InitLastCheckSum() |
| 204 | { |
nothing calls this directly
no outgoing calls
no test coverage detected