func()

in tx.go [777:804]


func (tx *Tx) getPage(op string, id PageID) (*Page, error) {
	inBounds := id >= 2
	if tx.flags.readonly {
		inBounds = inBounds && id < tx.dataEndID
	} else {
		inBounds = inBounds && id < tx.file.allocator.data.endMarker
	}
	if !inBounds {
		return nil, tx.errWrap(op, raiseOutOfBounds(id))
	}

	if tx.alloc.data.freed.Has(id) || tx.alloc.meta.freed.Has(id) {
		return nil, tx.err(op).of(InvalidOp).
			report("trying to access an already freed page")
	}

	if p := tx.pages[id]; p != nil {
		return p, nil
	}

	page := newPage(tx, id)
	if walID := tx.file.wal.Get(id); walID != 0 {
		page.ondiskID = walID
	}

	tx.pages[id] = page
	return page, nil
}