| 61 | } |
| 62 | |
| 63 | int LearnerState :: LearnValue(const uint64_t llInstanceID, const BallotNumber & oLearnedBallot, |
| 64 | const std::string & sValue, const uint32_t iLastChecksum) |
| 65 | { |
| 66 | if (llInstanceID > 0 && iLastChecksum == 0) |
| 67 | { |
| 68 | m_iNewChecksum = 0; |
| 69 | } |
| 70 | else if (sValue.size() > 0) |
| 71 | { |
| 72 | m_iNewChecksum = crc32(iLastChecksum, (const uint8_t *)sValue.data(), sValue.size(), CRC32SKIP); |
| 73 | } |
| 74 | |
| 75 | AcceptorStateData oState; |
| 76 | oState.set_instanceid(llInstanceID); |
| 77 | oState.set_acceptedvalue(sValue); |
| 78 | oState.set_promiseid(oLearnedBallot.m_llProposalID); |
| 79 | oState.set_promisenodeid(oLearnedBallot.m_llNodeID); |
| 80 | oState.set_acceptedid(oLearnedBallot.m_llProposalID); |
| 81 | oState.set_acceptednodeid(oLearnedBallot.m_llNodeID); |
| 82 | oState.set_checksum(m_iNewChecksum); |
| 83 | |
| 84 | WriteOptions oWriteOptions; |
| 85 | oWriteOptions.bSync = false; |
| 86 | |
| 87 | int ret = m_oPaxosLog.WriteState(oWriteOptions, m_poConfig->GetMyGroupIdx(), llInstanceID, oState); |
| 88 | if (ret != 0) |
| 89 | { |
| 90 | PLGErr("LogStorage.WriteLog fail, InstanceID %lu ValueLen %zu ret %d", |
| 91 | llInstanceID, sValue.size(), ret); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | LearnValueWithoutWrite(llInstanceID, sValue, m_iNewChecksum); |
| 96 | |
| 97 | PLGDebug("OK, InstanceID %lu ValueLen %zu checksum %u", |
| 98 | llInstanceID, sValue.size(), m_iNewChecksum); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | const std::string & LearnerState :: GetLearnValue() |
| 104 | { |