Page returns page information for a given page number. This is only safe for concurrent use when used by a writable transaction.
(id int)
| 666 | // Page returns page information for a given page number. |
| 667 | // This is only safe for concurrent use when used by a writable transaction. |
| 668 | func (tx *Tx) Page(id int) (*common.PageInfo, error) { |
| 669 | if tx.db == nil { |
| 670 | return nil, berrors.ErrTxClosed |
| 671 | } else if common.Pgid(id) >= tx.meta.Pgid() { |
| 672 | return nil, nil |
| 673 | } |
| 674 | |
| 675 | if tx.db.freelist == nil { |
| 676 | return nil, berrors.ErrFreePagesNotLoaded |
| 677 | } |
| 678 | |
| 679 | // Build the page info. |
| 680 | p := tx.db.page(common.Pgid(id)) |
| 681 | info := &common.PageInfo{ |
| 682 | ID: id, |
| 683 | Count: int(p.Count()), |
| 684 | OverflowCount: int(p.Overflow()), |
| 685 | } |
| 686 | |
| 687 | // Determine the type (or if it's free). |
| 688 | if tx.db.freelist.Freed(common.Pgid(id)) { |
| 689 | info.Type = "free" |
| 690 | } else { |
| 691 | info.Type = p.Typ() |
| 692 | } |
| 693 | |
| 694 | return info, nil |
| 695 | } |
| 696 | |
| 697 | // TxStats represents statistics about the actions performed by the transaction. |
| 698 | type TxStats struct { |