'2011/10/26'에 해당되는 글 1건
inline map/reduce의 경우 mongodb에서 하나의 object 16MB를 넘으면 안되기 때문에
최종 finalize한 결과값이 16MB안에 들어가야한다
요것을 수정해주려면 소스 코드에 박혀있는 메모리값을 수정해주던지
finalize에서 필요 없는 결과의 key값을 최종 inline map/reduce결과에서 제거해주면 해결될수도있다 (이부분은 mongodb의 용도에 따라 다르겠지만
내 용도에 한해서는 finalize에서 필요없는 key값 자체를 제거하므로 해결이 가능하다)
기본환경은 shard환경에서의 mongodb이다
finalize script에서 return null; 이거나 return을 안한 결과에 대해서는 해당 key값을 inline map/reduce 최종 값에서 제거해버리도록 코드를 수정해보자
(현재 mongodb jira에 등록은 되어있지만 2.1 버전정도에서 해결해준다고 하는데 크게 의지는 없는듯)
single server 환경에서의 inline map/reduce 수정
sharded 환경에서 inline map/reduce 수정
/db/commands/mr.cpp
최종 finalize한 결과값이 16MB안에 들어가야한다
요것을 수정해주려면 소스 코드에 박혀있는 메모리값을 수정해주던지
finalize에서 필요 없는 결과의 key값을 최종 inline map/reduce결과에서 제거해주면 해결될수도있다 (이부분은 mongodb의 용도에 따라 다르겠지만
내 용도에 한해서는 finalize에서 필요없는 key값 자체를 제거하므로 해결이 가능하다)
기본환경은 shard환경에서의 mongodb이다
finalize script에서 return null; 이거나 return을 안한 결과에 대해서는 해당 key값을 inline map/reduce 최종 값에서 제거해버리도록 코드를 수정해보자
(현재 mongodb jira에 등록은 되어있지만 2.1 버전정도에서 해결해준다고 하는데 크게 의지는 없는듯)
single server 환경에서의 inline map/reduce 수정
/db/commands/mr.cpp
/** * Applies last reduce and finalize. * After calling this method, the temp collection will be completed. * If inline, the results will be in the in memory map */ void State::finalReduce( CurOp * op , ProgressMeterHolder& pm ) { // 변경전 if ( ! _onDisk ) { // all data has already been reduced, just finalize if ( _config.finalizer ) { long size = 0; for ( InMemory::iterator i=_temp->begin(); i!=_temp->end();i++) { BSONObj key = i->first; BSONList& all = i->second; assert( all.size() == 1 ); BSONObj res = _config.finalizer->finalize( all[0] ); all.clear(); all.push_back( res ); size += res.objsize(); } _size = size; } return; } // 변경후 if ( ! _onDisk ) { // all data has already been reduced, just finalize if ( _config.finalizer ) { long size = 0; for ( InMemory::iterator i=_temp->begin(); i!=_temp->end();) { BSONObj key = i->first; BSONList& all = i->second; assert( all.size() == 1 ); BSONObj res = _config.finalizer->finalize( all[0] ); // finalize가 null을 반환하면 해당 key값은 삭제한다 if (res["value"].isNull()) { _temp->erase(i++); } else { all.clear(); all.push_back( res ); size += res.objsize(); i++; } } _size = size; } return; }
sharded 환경에서 inline map/reduce 수정
/db/commands/mr.cpp
class MapReduceFinishCommand : public Command { while ( cursor.more() || !values.empty() ) { BSONObj t; if (cursor.more()) { t = cursor.next().getOwned(); if ( values.size() == 0 ) { values.push_back( t ); continue; } if ( t.woSortOrder( *(values.begin()) , sortKey ) == 0 ) { values.push_back( t ); continue; } } BSONObj res = config.reducer->finalReduce( values , config.finalizer.get()); // finalize가 null을 반환하면 해당 key값은 삭제한다 (변경후) if (!res["value"].isNull()) { if (state.isOnDisk()) state.insertToInc(res); else state.emit(res); } values.clear(); if (!t.isEmpty()) values.push_back( t ); /* 변경전 if (state.isOnDisk()) state.insertToInc(res); else state.emit(res); values.clear(); if (!t.isEmpty()) values.push_back( t ); */ }