Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/phxpaxos/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class Node

virtual int SetMasterLease(const int iGroupIdx, const int iLeaseTimeMs) = 0;

virtual int SetMasterRenewInterval(const int iGroupIdx, const int iRenewIntervalTimeMs) = 0;

virtual int DropMaster(const int iGroupIdx) = 0;

//Qos
Expand Down
9 changes: 8 additions & 1 deletion src/master/master_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MasterMgr :: MasterMgr(
: m_oDefaultMasterSM(poLogStorage, poPaxosNode->GetMyNodeID(), iGroupIdx, pMasterChangeCallback)
{
m_iLeaseTime = 10000;
m_iRenewIntervalTimeMs = 0;

m_poPaxosNode = (Node *)poPaxosNode;
m_iMyGroupIdx = iGroupIdx;
Expand Down Expand Up @@ -63,6 +64,11 @@ void MasterMgr :: SetLeaseTime(const int iLeaseTimeMs)
m_iLeaseTime = iLeaseTimeMs;
}

void MasterMgr :: SetMasterRenewInterval(const int iRenewIntervalTimeMs)
{
m_iRenewIntervalTimeMs = iRenewIntervalTimeMs;
}

void MasterMgr :: DropMaster()
{
m_bNeedDropMaster = true;
Expand Down Expand Up @@ -94,12 +100,13 @@ void MasterMgr :: run()
}

int iLeaseTime = m_iLeaseTime;
int iRenewIntervalTimeMs = m_iRenewIntervalTimeMs;

uint64_t llBeginTime = Time::GetSteadyClockMS();

TryBeMaster(iLeaseTime);

int iContinueLeaseTimeout = (iLeaseTime - 100) / 4;
int iContinueLeaseTimeout = iRenewIntervalTimeMs ? iRenewIntervalTimeMs : (iLeaseTime - 100) / 4;
iContinueLeaseTimeout = iContinueLeaseTimeout / 2 + OtherUtils::FastRand() % iContinueLeaseTimeout;

if (m_bNeedDropMaster)
Expand Down
3 changes: 3 additions & 0 deletions src/master/master_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class MasterMgr : public Thread

void SetLeaseTime(const int iLeaseTimeMs);

void SetMasterRenewInterval(const int iRenewIntervalTimeMs);

void TryBeMaster(const int iLeaseTime);

void DropMaster();
Expand All @@ -62,6 +64,7 @@ class MasterMgr : public Thread

private:
int m_iLeaseTime;
int m_iRenewIntervalTimeMs;

bool m_bIsEnd;
bool m_bIsStarted;
Expand Down
11 changes: 11 additions & 0 deletions src/node/pnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,17 @@ int PNode :: SetMasterLease(const int iGroupIdx, const int iLeaseTimeMs)
return 0;
}

int PNode :: SetMasterRenewInterval(const int iGroupIdx, const int iRenewIntervalTimeMs)
{
if (!CheckGroupID(iGroupIdx))
{
return Paxos_GroupIdxWrong;
}

m_vecMasterList[iGroupIdx]->SetMasterRenewInterval(iRenewIntervalTimeMs);
return 0;
}

int PNode :: DropMaster(const int iGroupIdx)
{
if (!CheckGroupID(iGroupIdx))
Expand Down
1 change: 1 addition & 0 deletions src/node/pnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class PNode : public Node
const NodeInfo GetMasterWithVersion(const int iGroupIdx, uint64_t & llVersion);
const bool IsIMMaster(const int iGroupIdx);
int SetMasterLease(const int iGroupIdx, const int iLeaseTimeMs);
int SetMasterRenewInterval(const int iGroupIdx, const int iRenewIntervalTimeMs);
int DropMaster(const int iGroupIdx);

public:
Expand Down