StatusWith<DiskLoc> HeapRecordStore::insertRecord(OperationContext* txn,
                                                      const DocWriter* doc,
                                                      bool enforceQuota) {
        const int len = doc->documentSize();
        if (_isCapped && len > _cappedMaxSize) {
            // We use dataSize for capped rollover and we don't want to delete everything if we know
            // this won't fit.
            return StatusWith<DiskLoc>(ErrorCodes::BadValue,
                                       "object to insert exceeds cappedMaxSize");
        }

        // TODO padding?
        const int lengthWithHeaders = len + HeapRecord::HeaderSize;
        boost::shared_array<char> buf(new char[lengthWithHeaders]);
        HeapRecord* rec = reinterpret_cast<HeapRecord*>(buf.get());
        rec->lengthWithHeaders() = lengthWithHeaders;
        doc->writeDocument(rec->data());

        const DiskLoc loc = allocateLoc();
        _records[loc] = buf;
        _dataSize += len;

        cappedDeleteAsNeeded(txn);

        return StatusWith<DiskLoc>(loc);
    }
Exemple #2
0
    StatusWith<DiskLoc> HeapRecordStore::insertRecord(OperationContext* txn,
                                                      const DocWriter* doc,
                                                      bool enforceQuota) {
        const int len = doc->documentSize();
        if (_isCapped && len > _cappedMaxSize) {
            // We use dataSize for capped rollover and we don't want to delete everything if we know
            // this won't fit.
            return StatusWith<DiskLoc>(ErrorCodes::BadValue,
                                       "object to insert exceeds cappedMaxSize");
        }

        HeapRecord rec(len);
        doc->writeDocument(rec.data.get());

        DiskLoc loc;
        if (_data->isOplog) {
            StatusWith<DiskLoc> status = extractAndCheckLocForOplog(rec.data.get(), len);
            if (!status.isOK())
                return status;
            loc = status.getValue();
        }
        else {
            loc = allocateLoc();
        }

        txn->recoveryUnit()->registerChange(new InsertChange(_data, loc));
        _data->dataSize += len;
        _data->records[loc] = rec;

        cappedDeleteAsNeeded(txn);

        return StatusWith<DiskLoc>(loc);
    }
    StatusWith<DiskLoc> HeapRecordStoreBtree::insertRecord(OperationContext* txn,
                                                           const DocWriter* doc,
                                                           bool enforceQuota) {
        Record rec(doc->documentSize());
        doc->writeDocument(rec.data.get());

        const DiskLoc loc = allocateLoc();
        _records[loc] = rec;

        return StatusWith<DiskLoc>(loc);
    }
    StatusWith<DiskLoc> HeapRecordStoreBtree::insertRecord(OperationContext* txn,
                                                           const char* data,
                                                           int len,
                                                           bool enforceQuota) {
        Record rec(len);
        memcpy(rec.data.get(), data, len);

        const DiskLoc loc = allocateLoc();
        _records[loc] = rec;

        return StatusWith<DiskLoc>(loc);
    }
StatusWith<RecordId> HeapRecordStoreBtree::insertRecord(OperationContext* txn,
                                                        const DocWriter* doc,
                                                        bool enforceQuota) {
    Record rec(doc->documentSize());
    doc->writeDocument(rec.data.get());

    const RecordId loc = allocateLoc();
    _records[loc] = rec;

    HeapRecordStoreBtreeRecoveryUnit::notifyInsert(txn, this, loc);

    return StatusWith<RecordId>(loc);
}
StatusWith<RecordId> HeapRecordStoreBtree::insertRecord(OperationContext* txn,
                                                        const char* data,
                                                        int len,
                                                        bool enforceQuota) {
    Record rec(len);
    memcpy(rec.data.get(), data, len);

    const RecordId loc = allocateLoc();
    _records[loc] = rec;

    HeapRecordStoreBtreeRecoveryUnit::notifyInsert(txn, this, loc);

    return StatusWith<RecordId>(loc);
}