示例#1
0
    bool WriteBatchExecutor::applyInsert(const string& ns,
                                         const WriteBatch::WriteItem& writeItem,
                                         CurOp* currentOp) {
        OpDebug& opDebug = currentOp->debug();

        _opCounters->gotInsert();

        opDebug.op = dbInsert;

        BSONObj doc;

        string errMsg;
        bool ret = writeItem.parseInsertItem(&errMsg, &doc);
        verify(ret); // writeItem should have been already validated by WriteBatch::parse().

        try {
            // TODO Should call insertWithObjMod directly instead of checkAndInsert?  Note that
            // checkAndInsert will use mayInterrupt=false, so index builds initiated here won't
            // be interruptible.
            checkAndInsert(ns.c_str(), doc);
            getDur().commitIfNeeded();
            _le->nObjects = 1; // TODO Replace after implementing LastError::recordInsert().
            opDebug.ninserted = 1;
        }
        catch (UserException& e) {
            opDebug.exceptionInfo = e.getInfo();
            return false;
        }

        return true;
    }
int main(){
int c;
char ch;
init(); //init prlu table and cache 

do{
    printf("give the replacement policy (i->ipv,p->plru)\n");
    scanf("%c",&ch);
   // printf("read:%d\n",ch);
} while(ch!='i' && ch!='p');
strategy_type=ch=='i'?IPV:PLRU;

while(1){
    printf("give a number 1-100\n");
    scanf("%d",&c);
    if(!(c>=1 && c<=100))
        continue;
    checkAndInsert(c);
    printTableLeafs();
    if(strategy_type==PLRU)
     printPRLUTree();
    printf("---------------------\n\n\n");
    }

return 0;
}
示例#3
0
    bool WriteBatchExecutor::doInsert( const string& ns,
                                       const BSONObj& insertOp,
                                       CurOp* currentOp,
                                       WriteStats* stats,
                                       BatchedErrorDetail* error ) {
        OpDebug& opDebug = currentOp->debug();

        _opCounters->gotInsert();

        opDebug.op = dbInsert;

        try {
            // TODO Should call insertWithObjMod directly instead of checkAndInsert?  Note that
            // checkAndInsert will use mayInterrupt=false, so index builds initiated here won't
            // be interruptible.
            BSONObj doc = insertOp; // b/c we're const going in
            checkAndInsert( ns.c_str(), doc );
            getDur().commitIfNeeded();
            _le->nObjects = 1; // TODO Replace after implementing LastError::recordInsert().
            opDebug.ninserted = 1;
            stats->numInserted++;
        }
        catch ( const UserException& ex ) {
            opDebug.exceptionInfo = ex.getInfo();
            toBatchedError( ex, error );
            return false;
        }

        return true;
    }
示例#4
0
文件: instance.cpp 项目: QiuYe/mongo
    void receivedInsert(Message& m, CurOp& op) {
        DbMessage d(m);
        const char *ns = d.getns();
        op.debug().ns = ns;

        // Auth checking for index writes happens later.
        if (NamespaceString(ns).coll != "system.indexes") {
            Status status = cc().getAuthorizationManager()->checkAuthForInsert(ns);
            uassert(16544, status.reason(), status.isOK());
        }

        if( !d.moreJSObjs() ) {
            // strange.  should we complain?
            return;
        }
        BSONObj first = d.nextJsObj();

        vector<BSONObj> multi;
        while (d.moreJSObjs()){
            if (multi.empty()) // first pass
                multi.push_back(first);
            multi.push_back( d.nextJsObj() );
        }

        PageFaultRetryableSection s;
        while ( true ) {
            try {
                Lock::DBWrite lk(ns);
                
                // CONCURRENCY TODO: is being read locked in big log sufficient here?
                // writelock is used to synchronize stepdowns w/ writes
                uassert( 10058 , "not master", isMasterNs(ns) );
                
                if ( handlePossibleShardedMessage( m , 0 ) )
                    return;
                
                Client::Context ctx(ns);
                
                if( !multi.empty() ) {
                    const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError;
                    insertMulti(keepGoing, ns, multi, op);
                    return;
                }
                
                checkAndInsert(ns, first);
                globalOpCounters.incInsertInWriteLock(1);
                op.debug().ninserted = 1;
                return;
            }
            catch ( PageFaultException& e ) {
                e.touch();
            }
        }
    }
示例#5
0
    void receivedInsert(Message& m, CurOp& op) {
        DbMessage d(m);
        const char *ns = d.getns();
        op.debug().ns = ns;

        if( !d.moreJSObjs() ) {
            // strange.  should we complain?
            return;
        }
        BSONObj first = d.nextJsObj();

        vector<BSONObj> multi;
        while (d.moreJSObjs()){
            if (multi.empty()) // first pass
                multi.push_back(first);
            multi.push_back( d.nextJsObj() );
        }

        PageFaultRetryableSection s;
        while ( true ) {
            try {
                Lock::DBWrite lk(ns);
                
                // CONCURRENCY TODO: is being read locked in big log sufficient here?
                // writelock is used to synchronize stepdowns w/ writes
                uassert( 10058 , "not master", isMasterNs(ns) );
                
                if ( handlePossibleShardedMessage( m , 0 ) )
                    return;
                
                Client::Context ctx(ns);
                
                if( !multi.empty() ) {
                    const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError;
                    insertMulti(keepGoing, ns, multi);
                    return;
                }
                
                checkAndInsert(ns, first);
                globalOpCounters.incInsertInWriteLock(1);
                return;
            }
            catch ( PageFaultException& e ) {
                e.touch();
            }
        }
    }
示例#6
0
    NOINLINE_DECL void insertMulti(bool keepGoing, const char *ns, vector<BSONObj>& objs) {
        size_t i;
        for (i=0; i<objs.size(); i++){
            try {
                checkAndInsert(ns, objs[i]);
                getDur().commitIfNeeded();
            } catch (const UserException&) {
                if (!keepGoing || i == objs.size()-1){
                    globalOpCounters.incInsertInWriteLock(i);
                    throw;
                }
                // otherwise ignore and keep going
            }
        }

        globalOpCounters.incInsertInWriteLock(i);
    }
示例#7
0
    void receivedInsert(Message& m, CurOp& op) {
        DbMessage d(m);
        const char *ns = d.getns();
        op.debug().ns = ns;

        bool isIndexWrite = NamespaceString(ns).coll == "system.indexes";

        // Auth checking for index writes happens further down in this function.
        if (!isIndexWrite) {
            Status status = cc().getAuthorizationManager()->checkAuthForInsert(ns);
            uassert(16544, status.reason(), status.isOK());
        }

        if( !d.moreJSObjs() ) {
            // strange.  should we complain?
            return;
        }

        vector<BSONObj> multi;
        while (d.moreJSObjs()){
            BSONObj obj = d.nextJsObj();
            multi.push_back(obj);
            if (isIndexWrite) {
                string indexNS = obj.getStringField("ns");
                uassert(16548,
                        mongoutils::str::stream() << "not authorized to create index on "
                                << indexNS,
                        cc().getAuthorizationManager()->checkAuthorization(
                                indexNS, ActionType::ensureIndex));
            }
        }

        PageFaultRetryableSection s;
        while ( true ) {
            try {
                Lock::DBWrite lk(ns);
                
                // CONCURRENCY TODO: is being read locked in big log sufficient here?
                // writelock is used to synchronize stepdowns w/ writes
                uassert( 10058 , "not master", isMasterNs(ns) );
                
                if ( handlePossibleShardedMessage( m , 0 ) )
                    return;
                
                Client::Context ctx(ns);
                
                if (multi.size() > 1) {
                    const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError;
                    insertMulti(keepGoing, ns, multi, op);
                } else {
                    checkAndInsert(ns, multi[0]);
                    globalOpCounters.incInsertInWriteLock(1);
                    op.debug().ninserted = 1;
                }
                return;
            }
            catch ( PageFaultException& e ) {
                e.touch();
            }
        }
    }
示例#8
0
int HttpRange::parse( const char * pRange )
{
    m_list.clear();
    if ( strncasecmp( pRange, "bytes=", 6 ) != 0 )
        return SC_400;
    char ch;
    pRange+= 6;
    while( isspace(( ch = *pRange++ )) )
        ;
    if ( !ch )
        return SC_400;
    int state = 0;
    ByteRange range(-1,-1);
    long lValue = 0;
    while( state != 6 )
    {
        switch( ch )
        {
        case ' ':
        case '\t':
            switch( state )
            {
            case 0: case 2: case 4: case 5:
                break;
            case 1:
                state = 4;
                range.setBegin( lValue );
                lValue = 0;
                break;
            case 3:
                state = 5;
                range.setEnd( lValue );
                lValue = 0;
                break;
            }
            break;
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
            switch( state )
            {
            case 0: case 2:
                lValue = ch - '0';
                ++state;
                break;
            case 1: case 3:
                lValue = (lValue << 3 ) + (lValue << 1 ) + (ch - '0');
                break;
            case 4: case 5:
                state = 6; //error,
                break;
            }
            break;
        case '-':
            switch( state )
            {
            case 1:
                range.setBegin( lValue );
                lValue = 0;
                //don't break, fall through
            case 0: case 4:
                state = 2;
                break;
            case 2: case 3: case 5:
                state = 6;
                break;
            }
            break;
        case '\r': case '\n':
            ch = 0;
            //fall through
        case ',': case '\0': 
            switch( state )
            {
            case 3:
                range.setEnd( lValue );
                lValue = 0;
                //don't break, fall through
            case 2:  case 5:
                if ( checkAndInsert( range ) == -1 )
                {
                    state = 6;
                    break;
                }
                range.setBegin( -1 );
                range.setEnd( -1 );
                state = 0;
                break;
            case 1: case 4:
                state = 6;
                break;
            case 0:
                if ( ch )
                    state = 6;
                break;
            }
            break;
        default:
            state = 6;
            break;
        }
        if ( !ch )
            break;
        ch = *pRange++;
    }
    if ( state == 6 )
    {
        m_list.clear();
        return SC_400;
    }
    if ( m_list.empty() )
        return SC_416; //range not satisfiable
    return 0;
}