void Set_C::Union(__int64_t x, __int64_t y) { if(x == y) return; if(IsSameGroup(x, y)) return; if(-1 == pnGroupIdx[x] || -1 == pnGroupIdx[y]) return; __int64_t rootX = GetGroupIdx(x); __int64_t rootY = GetGroupIdx(y); if(pnGroupSize[rootX] < pnGroupSize[rootY]) { pnGroupIdx[rootX] = rootY; pnGroupSize[rootY] += pnGroupSize[rootX]; pnGroupSize[rootX] = 0; } else { pnGroupIdx[rootY] = rootX; pnGroupSize[rootX] += pnGroupSize[rootY]; pnGroupSize[rootY] = 0; } --nGroupNum; }
int PhxKV :: KVPropose(const std::string & sKey, const std::string & sPaxosValue, PhxKVSMCtx & oPhxKVSMCtx) { int iGroupIdx = GetGroupIdx(sKey); SMCtx oCtx; //smid must same to PhxKVSM.SMID(). oCtx.m_iSMID = 1; oCtx.m_pCtx = (void *)&oPhxKVSMCtx; uint64_t llInstanceID = 0; int ret = m_poPaxosNode->Propose(iGroupIdx, sPaxosValue, llInstanceID, &oCtx); if (ret != 0) { PLErr("paxos propose fail, key %s groupidx %d ret %d", iGroupIdx, ret); return ret; } return 0; }
const bool PhxKV :: IsIMMaster(const std::string & sKey) { int iGroupIdx = GetGroupIdx(sKey); return m_poPaxosNode->IsIMMaster(iGroupIdx); }
const phxpaxos::NodeInfo PhxKV :: GetMaster(const std::string & sKey) { int iGroupIdx = GetGroupIdx(sKey); return m_poPaxosNode->GetMaster(iGroupIdx); }
bool Set_C::IsSameGroup(__int64_t x, __int64_t y) { return GetGroupIdx(x) == GetGroupIdx(y); }