Exemplo n.º 1
0
    void BtreeBuilder<V>::addKey(BSONObj& _key, DiskLoc loc) {

        auto_ptr< KeyOwned > key( new KeyOwned(_key) );
        if ( key->dataSize() > BtreeBucket<V>::KeyMax ) {
            problem() << "Btree::insert: key too large to index, skipping " << idx.indexNamespace() 
                      << ' ' << key->dataSize() << ' ' << key->toString() << endl;
            return;
        }

        if( !dupsAllowed ) {
            if( n > 0 ) {
                int cmp = keyLast->woCompare(*key, ordering);
                massert( 10288 ,  "bad key order in BtreeBuilder - server internal error", cmp <= 0 );
                if( cmp == 0 ) {
                    //if( !dupsAllowed )
                    uasserted( ASSERT_ID_DUPKEY , BtreeBucket<V>::dupKeyError( idx , *keyLast ) );
                }
            }
        }

        if ( ! b->_pushBack(loc, *key, ordering, DiskLoc()) ) {
            // bucket was full
            newBucket();
            b->pushBack(loc, *key, ordering, DiskLoc());
        }
        keyLast = key;
        n++;
        mayCommitProgressDurably();
    }
Exemplo n.º 2
0
    void BtreeBuilder<V>::addKey(BSONObj& _key, DiskLoc loc) {
        auto_ptr< KeyOwned > key( new KeyOwned(_key) );
        if ( key->dataSize() > BtreeBucket<V>::KeyMax ) {
            string msg = str::stream() << "Btree::insert: key too large to index, failing "
                                       << _btreeState->descriptor()->indexNamespace()
                                       << ' ' << key->dataSize() << ' ' << key->toString();
            problem() << msg << endl;
            keyTooLongAssert( 17282, msg );
            return;
        }

        if( !_dupsAllowed ) {
            if( _numAdded > 0 ) {
                int cmp = keyLast->woCompare(*key, _btreeState->ordering());
                massert( 10288 ,  "bad key order in BtreeBuilder - server internal error", cmp <= 0 );
                if( cmp == 0 ) {
                    //if( !dupsAllowed )
                    uasserted( ASSERT_ID_DUPKEY, BtreeBucket<V>::dupKeyError( _btreeState->descriptor(),
                                                                              *keyLast ) );
                }
            }
        }

        if ( ! b->_pushBack(loc, *key, _btreeState->ordering(), DiskLoc()) ) {
            // bucket was full
            newBucket();
            b->pushBack(loc, *key, _btreeState->ordering(), DiskLoc());
        }
        keyLast = key;
        _numAdded++;
        mayCommitProgressDurably();
    }
Exemplo n.º 3
0
void
BucketReply::remapBucketId(const BucketId& bucket) {
    if (_originalBucket.getRawId() == 0) {
        _originalBucket = _bucket.getBucketId();
    }
    Bucket newBucket(_bucket.getBucketSpace(), bucket);
    _bucket = newBucket;
}
Exemplo n.º 4
0
struct bucket *createAndAppendBucket(struct bucketString *pStr) {
    struct bucket *pBkt;

    if (pStr == NULL) return NULL;

    /* Initialize and append new bucket */
    pBkt = newBucket(pStr->defSize);
    appendBucket(pStr, pBkt);

    return pBkt;
}
Exemplo n.º 5
0
void refactorString(struct bucketString *pStr) {
    struct bucket *pResult;
    struct bucket *pBkt;
    int i, j;

    /* Exit if string is empty, or only one bucket exists */
    if (pStr == NULL) return;
    if (pStr->pBkt == NULL) {
        pStr->pLast = NULL;
        return;
    }
    if (pStr->pBkt->pNext == NULL) {
        if (isBucketNonEmpty(pStr->pBkt)==0) {
            /* Dump bucket */
            clearString(pStr);
            return;

        } else {
            /* Already have only one valid bucket */
            pStr->pLast = pStr->pBkt;
            return;
        }
    }

    /* Attempt to create new bucket */
    pResult = newBucket(getStringLen(pStr));

    if (pResult == NULL) {
        /* Failed to create bucket. Clear string (probably empty) */
        clearString(pStr);
        return;
    }

    /* Copy over data from existing buckets */
    i = 0;
    for (pBkt = pStr->pBkt; pBkt != NULL; pBkt = pBkt->pNext) {
        /* Skip empty buckets */
        if (isBucketNonEmpty(pBkt) == 0) continue;

        /* Copy buffers. i accumulates continuously */
        for (j = 0; j < pBkt->size; i++, j++) {
            pResult->pBuf[i] = pBkt->pBuf[j];
        }
    }

    /* Remove old buckets and reassign to new bucket */
    clearString(pStr);
    pStr->pBkt = pResult;
    pStr->pLast = pResult;
}
Exemplo n.º 6
0
void InMemoryStorageBackend::createBucket(const PolicyBucketId &bucketId,
                                          const PolicyResult &defaultPolicy) {
    PolicyBucket newBucket(bucketId, defaultPolicy);
    buckets().insert({ bucketId, newBucket });
}
Exemplo n.º 7
0
/* shorthand constructor for the first test bucket */
Bucket * firstTestBucket() {
    char * test_key = "thing";
    char * test_value = "This is a string";
    return newBucket(test_key, "string", (void *)test_value, strlen(test_value));
}
Exemplo n.º 8
0
/* shorthand constructor for the third test bucket */
Bucket * thirdTestBucket() {
    char * test_key = "pikachu";
    char * test_value = "Pika pika piiiii";
    return newBucket(test_key, "string", (void *)test_value, strlen(test_value));
}
Exemplo n.º 9
0
/* shorthand constructor for the second test bucket */
Bucket * secondTestBucket() {
    char * test_key = "potato";
    char * test_value = "This is a different string";
    return newBucket(test_key, "string", (void *)test_value, strlen(test_value));
}
Exemplo n.º 10
0
void QAuServer::play(const QString& filename)
{
    QAuBucket* b = newBucket(filename);
    play(b);
    deleteBucket(b);
}