mongodb inline mapreduce에서 finalize에서 최종 결과 control하기

|
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 수정
/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 );
                            */
                        }

And

auto balancing chunk number 변경

|
mongodb 사이트에서 src파일을 받은후에
s/balancer_policy.cpp 에서 balance function의 const int threshold = balancedLastTime ? 2 : 8; 부분을 수정해준다
앞부분이 (2) 각 shard간의 허용 imbalance 정도이고 (이 수치까지 balance를 맞춘후에 stop)
뒷부분이 (8) 각 shard간의 min, max chunk number 가 8이상 차이날 경우 auto balancing을 실시한다는것

파일을 수정후에
scons all 로 컴파일해주자 
컴파일시 boost등의 문제가 생기면 v8 engine으로 컴파일하기쪽에서 필요한 라이브러리들을 설치하자~ 
And

mysql 초기 실행

|
/etc/mysql/my.conf 셋팅 기본은 root영역에 하니까까 바꾼다 , encoding부분도 바꿔주자

# 기본 db셋팅
mysql_install_db

# mysql 재실행
/etc/init.d/mysql restart

# root 비번 셋팅
update user set password=PASSWORD('비밀번호') where user='root';

# 사용자 추가
insert into user (Host, User, Password) values ('%', 'user명', password('비밀번호'));
# 모든 db에대한 권한 줌
grant all on *.* to user명;
flush privileges; 
And
prev | 1 | 2 | 3 | 4 | 5 | 6 | ··· | 21 | next