Skip to content

Commit

Permalink
update paxos logs
Browse files Browse the repository at this point in the history
  • Loading branch information
JMHOO committed Nov 21, 2016
1 parent 9342b6c commit 51e609a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Binary file not shown.
12 changes: 6 additions & 6 deletions ServerCPP/src/paxosAcceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace Paxos
uint64_t lInstanceID = m_storage.GetMaxInstanceID();
if( lInstanceID == 0 )
{// no records exist in file
lInstanceID = 1;
lInstanceID = 0;
return true;
}

// read states from file
m_storage.ReadState(m_promisedID.ProposalID, m_promisedID.NodeID, m_acceptedID.ProposalID, m_acceptedID.NodeID, m_acceptedValue);

logger->Info("Acceptor initialized, instance id:%lu, promised node id:%d, promised proposal id:%lu, accepted node id:%d, accepted proposal id:%lu, value: %s",
logger->Info("Acceptor initialized from file, instance id:%lu, promised node id:%d, promised proposal id:%lu, accepted node id:%d, accepted proposal id:%lu, value: %s",
lInstanceID, m_promisedID.NodeID, m_promisedID.ProposalID, m_acceptedID.NodeID, m_acceptedID.ProposalID, m_acceptedValue.c_str());

m_pInstance->SetInstanceID(lInstanceID);
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace Paxos

if (fromID >= m_promisedID)
{
logger->Info("Acceptor prepare [Promise] current info[Promised node=%d, proposal id=%lu], [PreAccepted node=%d, proposal id=%lu",
logger->Info(" Acceptor [Promise] current info[Promised node=%d, proposal id=%lu], [PreAccepted node=%d, proposal id=%lu]",
m_promisedID.NodeID, m_promisedID.ProposalID, m_acceptedID.NodeID, m_acceptedID.ProposalID);

response.SetPreAcceptID(m_acceptedID.ProposalID);
Expand All @@ -111,7 +111,7 @@ namespace Paxos
}
else
{
logger->Info("Acceptor prepare [Reject] current info[Promised node=%d, proposal id=%lu",
logger->Info(" Acceptor [Reject] current info[Promised node=%d, proposal id=%lu",
m_promisedID.NodeID, m_promisedID.ProposalID);

response.SetRejectPromiseID(m_promisedID.ProposalID);
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace Paxos
IDNumber fromID(pm->GetProposalID(), pm->GetNodeID());
if (fromID >= m_promisedID)
{
logger->Info("Acceptor accept [Promise] current info[Promised node=%d, proposal id=%lu], [PreAccepted node=%d, proposal id=%lu",
logger->Info(" Acceptor [Promise] current info[Promised node=%d, proposal id=%lu], [PreAccepted node=%d, proposal id=%lu]",
m_promisedID.NodeID, m_promisedID.ProposalID, m_acceptedID.NodeID, m_acceptedID.ProposalID);

m_promisedID = fromID;
Expand All @@ -151,7 +151,7 @@ namespace Paxos
}
else
{
logger->Info("Acceptor accept [Reject] current info[Promised node=%d, proposal id=%lu",
logger->Info(" Acceptor [Reject] current info[Promised node=%d, proposal id=%lu]",
m_promisedID.NodeID, m_promisedID.ProposalID);

response.SetRejectPromiseID(m_promisedID.ProposalID);
Expand Down
2 changes: 1 addition & 1 deletion ServerCPP/src/paxosInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Paxos
return false;
}

logger->Info("Paxos Instance, acceptor OK, now instance ID:%lu", m_ID64);
logger->Info("Instance::Initialize, load acceptor OK, now instance ID:%lu", m_ID64);

// set proposal id from acceptor state

Expand Down
2 changes: 1 addition & 1 deletion ServerCPP/src/paxosLearner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace Paxos
m_learnedValue = learnedValue;
m_bIsLearned = true;


logger->Info("Learner, learned value: %s", learnedValue.c_str());
// set value to kvserver
m_pInstance->OnCommitComplete(m_learnedValue);
}
Expand Down
14 changes: 10 additions & 4 deletions ServerCPP/src/paxosProposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Paxos
{
jsonPaxos* pm = (jsonPaxos*)p;

logger->Info("Proposal::OnPrepareResponse, my proposalid:%lu, receive proposalid:%lu, from node:%d, reject by id:%lu",
logger->Info("Proposal::OnPrepareResponse, my proposalid:%lu, received proposalid:%lu, from node:%d, reject by id:%lu",
m_proposalID, pm->GetProposalID(), pm->GetNodeID(), pm->GetRejectPromiseID());

if( m_state != State::Preparing )
Expand Down Expand Up @@ -162,6 +162,7 @@ namespace Paxos

if( counter.IsPassed())
{
logger->Info("Proposal::OnPrepare, majority passed, begin accept and I'm leader now.");
// prepare complete
m_bCanSkipPrepare = true;
Accept();
Expand All @@ -170,7 +171,8 @@ namespace Paxos
{
// restart wait random time
srand((unsigned int)time(NULL));
int x = rand()%10 + 10;
int x = rand()%30 + 10;
logger->Info("Proposal::OnPrepare, majority reject, wait %d ms to restart", x);
AddTimeout(TimeoutType::Proposal_Prepare, x);
}
}
Expand Down Expand Up @@ -220,12 +222,12 @@ namespace Paxos

if( pm->GetRejectPromiseID() == 0 )
{
logger->Info("Proposal::OnAcceptResponse [Accept]");
logger->Info("Proposal::OnAccept [Accept]");
counter.Add(Counter::Kinds::Promised, pm->GetNodeID());
}
else
{
logger->Info("Proposal::OnAcceptResponse [Reject]");
logger->Info("Proposal::OnAccept [Reject]");
counter.Add(Counter::Kinds::Rejected, pm->GetNodeID());

// reject by someone
Expand All @@ -238,6 +240,7 @@ namespace Paxos

if( counter.IsPassed())
{
logger->Info("Proposal::OnAccept, majority passed, notify learner.");
ExitAccept();
// send value to learner
m_pInstance->ProposalChosenValue(m_proposalID);
Expand All @@ -246,6 +249,9 @@ namespace Paxos
{
srand((unsigned int)time(NULL));
int x = rand()%30 + 10;

logger->Info("Proposal::OnAccept, majority reject, wait %d ms to restart", x);

AddTimeout(TimeoutType::Proposal_Accept, x);
}
}
Expand Down

0 comments on commit 51e609a

Please sign in to comment.