From 7501cfc1f064ea49f8e1f80812752e0468a1e973 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Fri, 16 Jun 2017 12:22:53 +0100 Subject: [PATCH] MCOL-769 Add command to get the uncommitted lbids We need this to be able to commit them --- versioning/BRM/brmtypes.h | 1 + versioning/BRM/masterdbrmnode.cpp | 93 +++++++++++++++++++++++++++++++ versioning/BRM/masterdbrmnode.h | 2 + 3 files changed, 96 insertions(+) diff --git a/versioning/BRM/brmtypes.h b/versioning/BRM/brmtypes.h index 7fa32de64..8dad327b7 100644 --- a/versioning/BRM/brmtypes.h +++ b/versioning/BRM/brmtypes.h @@ -438,6 +438,7 @@ const uint8_t GET_SYSTEM_STATE = 54; const uint8_t SET_SYSTEM_STATE = 55; const uint8_t GET_UNIQUE_UINT64 = 56; const uint8_t CLEAR_SYSTEM_STATE = 57; +const uint8_t GET_UNCOMMITTED_LBIDS = 58; /* OID Manager interface */ const uint8_t ALLOC_OIDS = 60; diff --git a/versioning/BRM/masterdbrmnode.cpp b/versioning/BRM/masterdbrmnode.cpp index 46f49906f..ff1b70b8e 100644 --- a/versioning/BRM/masterdbrmnode.cpp +++ b/versioning/BRM/masterdbrmnode.cpp @@ -379,6 +379,7 @@ void MasterDBRMNode::msgProcessor() case SET_SYSTEM_STATE: doSetSystemState(msg, p); continue; case CLEAR_SYSTEM_STATE: doClearSystemState(msg, p); continue; case SM_RESET: doSessionManagerReset(msg, p); continue; + case GET_UNCOMMITTED_LBIDS: doGetUncommittedLbids(msg, p); continue; } /* Process TableLock calls */ @@ -1292,6 +1293,98 @@ void MasterDBRMNode::doSIDTIDMap(ByteStream &msg, ThreadParams *p) catch (...) { } } +void MasterDBRMNode::doGetUncommittedLbids(ByteStream &msg, ThreadParams *p) +{ + ByteStream reply; + vector lbidList; + VSS vss; + ExtentMap em; + bool locked = false; + vector::iterator lbidIt; + typedef pair range_t; + range_t range; + vector ranges; + vector::iterator rangeIt; + ByteStream::byte cmd; + ByteStream::quadbyte transID; + msg >> cmd; + msg >> transID; + try { + vss.lock(VSS::READ); + locked = true; + + // Get a full list of uncommitted LBIDs related to this transactin. + vss.getUncommittedLBIDs(transID, lbidList); + + vss.release(VSS::READ); + locked = false; + + if(lbidList.size() > 0) { + + // Sort the vector. + std::sort::iterator>(lbidList.begin(), lbidList.end()); + + // Get the LBID range for the first block in the list. + lbidIt = lbidList.begin(); + if (em.lookup(*lbidIt, range.first, range.second) < 0) { + reply.reset(); + reply << (uint8_t) ERR_FAILURE; + try { + p->sock->write(reply); + } + catch (...) { } + + return; + } + ranges.push_back(range); + + // Loop through the LBIDs and add the new ranges. + ++lbidIt; + while(lbidIt != lbidList.end()) { + if (*lbidIt > range.second) { + if (em.lookup(*lbidIt, range.first, range.second) < 0) { + reply.reset(); + reply << (uint8_t) ERR_FAILURE; + try { + p->sock->write(reply); + } + catch (...) { } + return; + + } + ranges.push_back(range); + } + ++lbidIt; + } + + // Reset the lbidList and return only the first LBID in each extent that was changed + // in the transaction. + lbidList.clear(); + for (rangeIt = ranges.begin(); rangeIt != ranges.end(); rangeIt++) { + lbidList.push_back(rangeIt->first); + } + } + reply << (uint8_t) ERR_OK; + serializeInlineVector(reply, lbidList); + try { + p->sock->write(reply); + } + catch (...) { } + return; + } + catch (exception &e) { + if (locked) + vss.release(VSS::READ); + reply.reset(); + reply << (uint8_t) ERR_FAILURE; + try { + p->sock->write(reply); + } + catch (...) { } + return; + } +} + void MasterDBRMNode::doGetUniqueUint32(ByteStream &msg, ThreadParams *p) { ByteStream reply; diff --git a/versioning/BRM/masterdbrmnode.h b/versioning/BRM/masterdbrmnode.h index 0ce98fe8b..dcbd2d453 100644 --- a/versioning/BRM/masterdbrmnode.h +++ b/versioning/BRM/masterdbrmnode.h @@ -193,6 +193,8 @@ private: void doSetSystemState(messageqcpp::ByteStream &msg, ThreadParams *p); void doClearSystemState(messageqcpp::ByteStream &msg, ThreadParams *p); void doSessionManagerReset(messageqcpp::ByteStream &msg, ThreadParams *p); + void doGetUncommittedLbids(messageqcpp::ByteStream &msg, ThreadParams *p); + /* OID Manager interface */ OIDServer oids;