Beispiel #1
0
/**
 * Reads the next record from stream fd
 * Records are prefixed by a 16-bit big endian length value
 * Records may not be larger than maxRecordLen
 *
 * Doesn't guard against EINTR
 *
 * p_outRecord and p_outRecordLen may not be NULL
 *
 * Return 0 on success, -1 on fail
 * Returns 0 with *p_outRecord set to NULL on end of stream
 * Returns -1 / errno = EAGAIN if it needs to read again
 */
int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 
                                    size_t *p_outRecordLen)
{
    void *ret;

    ssize_t countRead;

    /* is there one record already in the buffer? */
    ret = getNextRecord (p_rs, p_outRecordLen);

    if (ret != NULL) {
        *p_outRecord = ret;
        return 0;
    }

    // if the buffer is full and we don't have a full record
    if (p_rs->unconsumed == p_rs->buffer 
        && p_rs->read_end == p_rs->buffer_end
    ) {
        // this should never happen
        //LOGE("max record length exceeded\n");
        assert (0);
        errno = EFBIG;
        return -1;
    }

    if (p_rs->unconsumed != p_rs->buffer) {
        // move remainder to the beginning of the buffer
        size_t toMove;

        toMove = p_rs->read_end - p_rs->unconsumed;
        if (toMove) {
            memmove(p_rs->buffer, p_rs->unconsumed, toMove);
        }

        p_rs->read_end = p_rs->buffer + toMove;
        p_rs->unconsumed = p_rs->buffer;
    }

    countRead = read (p_rs->fd, p_rs->read_end, p_rs->buffer_end - p_rs->read_end);

    if (countRead <= 0) {
        /* note: end-of-stream drops through here too */
        *p_outRecord = NULL;
        return countRead;
    }

    p_rs->read_end += countRead;

    ret = getNextRecord (p_rs, p_outRecordLen);

    if (ret == NULL) {
        /* not enough of a buffer to for a whole command */
        errno = EAGAIN;
        return -1;
    }

    *p_outRecord = ret;        
    return 0;
}
bool GroupBy::init()
{
	Tokenizer groupColsTokens;
	groupColsTokens.tokenize(upCast(_context)->getGroupCols(), ',');
	int numElems = groupColsTokens.getNumValidElems();
	for (int i=0; i < numElems; i++) {
		//if the item is a range, such as 3-5,
		//must split that as well.
		const QuickString &elem = groupColsTokens.getElem(i);

		if (strchr(elem.c_str(), '-')) {
			Tokenizer rangeElems;
			rangeElems.tokenize(elem, '-');
			int startNum = str2chrPos(rangeElems.getElem(0));
			int endNum = str2chrPos(rangeElems.getElem(1));
			for (int i=startNum; i <= endNum; i++) {
				_groupCols.push_back(i);
			}
		} else {
			_groupCols.push_back(str2chrPos(elem));
		}
	}
	_queryFRM = _context->getFile(0);
	_prevFields.resize(_groupCols.size());

	_prevRecord = getNextRecord();
	return true;
}
Beispiel #3
0
    void RecordStoreV1Base::deleteRecord( TransactionExperiment* txn, const DiskLoc& dl ) {

        Record* todelete = recordFor( dl );

        /* remove ourself from the record next/prev chain */
        {
            if ( todelete->prevOfs() != DiskLoc::NullOfs ) {
                DiskLoc prev = getPrevRecordInExtent( dl );
                Record* prevRecord = recordFor( prev );
                txn->writingInt( prevRecord->nextOfs() ) = todelete->nextOfs();
            }

            if ( todelete->nextOfs() != DiskLoc::NullOfs ) {
                DiskLoc next = getNextRecord( dl );
                Record* nextRecord = recordFor( next );
                txn->writingInt( nextRecord->prevOfs() ) = todelete->prevOfs();
            }
        }

        /* remove ourself from extent pointers */
        {
            Extent *e = txn->writing( _getExtent( _getExtentLocForRecord( dl ) ) );
            if ( e->firstRecord == dl ) {
                if ( todelete->nextOfs() == DiskLoc::NullOfs )
                    e->firstRecord.Null();
                else
                    e->firstRecord.set(dl.a(), todelete->nextOfs() );
            }
            if ( e->lastRecord == dl ) {
                if ( todelete->prevOfs() == DiskLoc::NullOfs )
                    e->lastRecord.Null();
                else
                    e->lastRecord.set(dl.a(), todelete->prevOfs() );
            }
        }

        /* add to the free list */
        {
            _details->incrementStats( txn, -1 * todelete->netLength(), -1 );

            if ( _isSystemIndexes ) {
                /* temp: if in system.indexes, don't reuse, and zero out: we want to be
                   careful until validated more, as IndexDetails has pointers
                   to this disk location.  so an incorrectly done remove would cause
                   a lot of problems.
                */
                memset( txn->writingPtr(todelete, todelete->lengthWithHeaders() ),
                        0, todelete->lengthWithHeaders() );
            }
            else {
                DEV {
                    unsigned long long *p = reinterpret_cast<unsigned long long *>( todelete->data() );
                    *txn->writing(p) = 0;
                }
                addDeletedRec(txn, dl);
            }
        }

    }
Beispiel #4
0
Record* Namespace::getRecord(const char* key, const char* value)
{
	Record *rec;
	do
	{
		rec = getNextRecord();
		//LOGI("found record");
	} while (rec != NULL);

	return NULL;
}
Beispiel #5
0
Record* Namespace::getNextRecord()
{
	Record *rec;
	if (extentCursor.isNull()) // the first time after connection the extent cursor will be null
	{
		extentCursor = firstExtentLoc; // so, get the first extent of the colection
		if (_DEBUG)
			LOGI("getting first extent");
	}

	if (extentCursor.isNull()) // if first extent is null, then no extents exist
		return NULL;  // no extents

	Extent* extent = db->getExtent(extentCursor);

	if (recordCursor == -1)	// the first time the record cursor will be null as well
	{
		recordCursor = extent->firstRecord;	// get the first record of the extent

		if (recordCursor == -1)	// if first record is null, then no records exist
			return NULL;  // no records

		rec = extent->getRecord(recordCursor);
	}
	else // else, the cursor shows the previous record, should take the next one and return its data
	{
		rec = extent->getRecord(recordCursor);

		if (rec->nextRecLoc == -1) // if its next record is null, then go to next extent
		{
			if (extent->nextExtent.isNull()) // if the next extent is null, then no more extents
			{
				return NULL;  // no more records
			}
			else							// proceed with the next extent
			{
				extentCursor = extent->nextExtent;
				recordCursor = -1;
				return getNextRecord();
			}
		}
		else
		{
			recordCursor = rec->nextRecLoc;	// next record exists, so put the cursor on it
			if (_DEBUG)
				LOGI("getting next record");
			rec = extent->getRecord(recordCursor);
		}
	}
	return rec;
}
Beispiel #6
0
KRecordList *IntervalCPU::calcNext( KRecordList *displayList, bool initCalc )
{
  SemanticHighInfo highInfo;

  if( displayList == NULL )
    displayList = &myDisplayList;

  if( !initCalc )
  {
    *begin = *end;
  }

  if( intervalCompose.empty() )
    return displayList;

  if( intervalCompose[ begin->getThread() - firstThreadOnCPU ] == NULL )
  {
    int i = begin->getThread() - firstThreadOnCPU;
    intervalThread[ i ] = new IntervalThread( window, THREAD, begin->getThread() );
    intervalThread[ i ]->setNotWindowInits( true );
    intervalThread[ i ]->setSemanticFunction( functionThread );

    intervalCompose[ i ] = new IntervalCompose( window, COMPOSETHREAD, begin->getThread() );
    intervalCompose[ i ]->setNotWindowInits( true );
    intervalCompose[ i ]->setCustomChild( intervalThread[ i ] );
    intervalCompose[ i ]->setSemanticFunction( functionComposeThread );

    intervalCompose[ i ]->init( currentInitialTime, NOCREATE, NULL );
  }

  Interval *currentThread = intervalCompose[ begin->getThread() - firstThreadOnCPU ];
  highInfo.callingInterval = this;
  if( begin->getType() == STATE + END )
    highInfo.values.push_back( 0.0 );
  else
  {
    while( currentThread->getEndTime() <= begin->getTime() &&
           currentThread->getBeginTime() < window->getTrace()->getEndTime() )
      currentThread->calcNext( NULL );
    if( currentThread->getBegin()->getCPU() != order )
      highInfo.values.push_back( 0.0 );
    else
      highInfo.values.push_back( currentThread->getValue() );
  }
  currentValue = function->execute( &highInfo );
  end = getNextRecord( end, displayList );

  return displayList;
}
bool GroupBy::findNext(RecordKeyVector &hits)
{
	//get one record.
	if (_prevRecord == NULL) {
		return false;
	}
	assignPrevFields();
	hits.setKey(_prevRecord);
	hits.push_back(_prevRecord); //key should also be part of group for calculations
	while (1) {
		const Record *newRecord = getNextRecord();
		if (newRecord == NULL) {
			_prevRecord = NULL;
			break;
		} else if (canGroup(newRecord)) {
			hits.push_back(newRecord);
		} else {
			_prevRecord = newRecord;
			break;
		}
	}
	return true;
}
    void RecordStoreV1Base::deleteRecord( OperationContext* txn, const DiskLoc& dl ) {

        Record* todelete = recordFor( dl );
        invariant( todelete->netLength() >= 4 ); // this is required for defensive code

        /* remove ourself from the record next/prev chain */
        {
            if ( todelete->prevOfs() != DiskLoc::NullOfs ) {
                DiskLoc prev = getPrevRecordInExtent( txn, dl );
                Record* prevRecord = recordFor( prev );
                txn->recoveryUnit()->writingInt( prevRecord->nextOfs() ) = todelete->nextOfs();
            }

            if ( todelete->nextOfs() != DiskLoc::NullOfs ) {
                DiskLoc next = getNextRecord( txn, dl );
                Record* nextRecord = recordFor( next );
                txn->recoveryUnit()->writingInt( nextRecord->prevOfs() ) = todelete->prevOfs();
            }
        }

        /* remove ourself from extent pointers */
        {
            DiskLoc extentLoc = todelete->myExtentLoc(dl);
            Extent *e =  _getExtent( txn, extentLoc );
            if ( e->firstRecord == dl ) {
                txn->recoveryUnit()->writing(&e->firstRecord);
                if ( todelete->nextOfs() == DiskLoc::NullOfs )
                    e->firstRecord.Null();
                else
                    e->firstRecord.set(dl.a(), todelete->nextOfs() );
            }
            if ( e->lastRecord == dl ) {
                txn->recoveryUnit()->writing(&e->lastRecord);
                if ( todelete->prevOfs() == DiskLoc::NullOfs )
                    e->lastRecord.Null();
                else
                    e->lastRecord.set(dl.a(), todelete->prevOfs() );
            }
        }

        /* add to the free list */
        {
            _details->incrementStats( txn, -1 * todelete->netLength(), -1 );

            if ( _isSystemIndexes ) {
                /* temp: if in system.indexes, don't reuse, and zero out: we want to be
                   careful until validated more, as IndexDetails has pointers
                   to this disk location.  so an incorrectly done remove would cause
                   a lot of problems.
                */
                memset( txn->recoveryUnit()->writingPtr(todelete, todelete->lengthWithHeaders() ),
                        0, todelete->lengthWithHeaders() );
            }
            else {
                // this is defensive so we can detect if we are still using a location
                // that was deleted
                memset(txn->recoveryUnit()->writingPtr(todelete->data(), 4), 0xee, 4);
                addDeletedRec(txn, dl);
            }
        }

    }
Beispiel #9
0
// Gets the next reference section from the file & stores it in the
// passed in section.  It will read until a new section is found.
bool GlfFile::getNextRefSection(GlfRefSection& refSection)
{
    if(myIsOpenForRead == false)
    {
        // File is not open for read
        myStatus.setStatus(GlfStatus::FAIL_ORDER, 
                           "Cannot read reference section since the file is not open for reading");
        throw(GlfException(myStatus));
        return(false);
    }

    if(myNextSection == HEADER)
    {
        // The header has not yet been read.
        // TODO - maybe just read the header.
        myStatus.setStatus(GlfStatus::FAIL_ORDER, 
                           "Cannot read reference section since the header has not been read.");
        throw(GlfException(myStatus));
        return(false);
    }

    // Keep reading until the next section is found.
    if(myNextSection == RECORD)
    {
        GlfRecord record;
        while(getNextRecord(record))
        {
            // Nothing to do, with the record.
        }
    }

    // Check for end of file.  If end of file, return false.
    if(isEOF())
    {
        return(false);
    }

    if(myNextSection != REF_SECTION)
    {
        // Failed reading all the records, so throw exception.
        myStatus.setStatus(GlfStatus::FAIL_IO, 
                           "Failed to get to a reference section.");
        throw(GlfException(myStatus));
        return(false);
    }

    // Ready to read the section:
    if(refSection.read(myFilePtr))
    {
        myStatus = GlfStatus::SUCCESS;
        // Next a record should be read.
        myNextSection = RECORD;
        return(true);
    }

    // If it is the EOF, just return false.
    if(isEOF())
    {
        return(false);
    }
    myStatus.setStatus(GlfStatus::UNKNOWN, 
                       "Failed reading a reference section from the file.");
    throw(GlfException(myStatus));
    return(false);
}
Beispiel #10
0
std::string Fasta::getNext() {
    return getNextRecord().second;
}