From faea63b9cbc050e35490c6cc90ee0900558d1aca Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 20 Jan 2017 10:10:24 -0600 Subject: [PATCH] MCOL-455: fix crash caused by rewind of unopened redistribute plan file during display when no partitions have been planned to be moved. --- .../we_redistributecontrolthread.cpp | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/writeengine/redistribute/we_redistributecontrolthread.cpp b/writeengine/redistribute/we_redistributecontrolthread.cpp index dd498dd2a..c43f83c3b 100644 --- a/writeengine/redistribute/we_redistributecontrolthread.cpp +++ b/writeengine/redistribute/we_redistributecontrolthread.cpp @@ -316,7 +316,7 @@ int RedistributeControlThread::makeRedistributePlan() targetDbroots.insert(*j); } } - // At this point, there are two concepts of target. (1)Those fTargetSet, which is the + // At this point, there are two concepts of target. (1)Those in fTargetSet, which is the // set of dbroots the user wants partitions on and (2) those in targetDbroots, a subset of // fTargetSet, which is those that actually have room, based on average, for more data. @@ -423,6 +423,7 @@ int RedistributeControlThread::makeRedistributePlan() if (dbPartVec[*targetDbroot].size() < partCount) { tdbroot = *targetDbroot; + partCount = dbPartVec[*targetDbroot].size(); } } if (tdbroot == 0) @@ -495,15 +496,22 @@ void RedistributeControlThread::dumpPlanToFile(uint64_t oid, vectorfPlanFilePtr); - - ByteStream bs; - uint32_t entryId = 0; - long entrySize = sizeof(RedistributePlanEntry); - fControl->logMessage(string("Redistribution Plan:")); - while (entryId++ < fEntryCount) + try { - try + if (!fControl->fPlanFilePtr) + { + ostringstream oss; + oss << "No data is schefuled to be moved" << endl; + fControl->logMessage(oss.str()); + return; + } + rewind(fControl->fPlanFilePtr); + + ByteStream bs; + uint32_t entryId = 0; + long entrySize = sizeof(RedistributePlanEntry); + fControl->logMessage(string("Redistribution Plan:")); + while (entryId++ < fEntryCount) { RedistributePlanEntry entry; errno = 0; @@ -522,14 +530,18 @@ void RedistributeControlThread::displayPlan() << " moves from dbroot " << entry.source << " to " << entry.destination << endl; fControl->logMessage(oss.str()); } - catch (std::exception &e) - { - cout << "exception during display of plan: " << e.what() << endl; - } - catch (...) - { - cout << "exception during display of plan" << endl; - } + } + catch (std::exception &e) + { + ostringstream oss; + oss << "exception during display of plan: " << e.what() << endl; + fControl->logMessage(oss.str()); + } + catch (...) + { + ostringstream oss; + oss << "exception during display of plan" << endl; + fControl->logMessage(oss.str()); } }