init initializes the transaction.
(db *DB)
| 45 | |
| 46 | // init initializes the transaction. |
| 47 | func (tx *Tx) init(db *DB) { |
| 48 | tx.db = db |
| 49 | tx.pages = nil |
| 50 | |
| 51 | // Copy the meta page since it can be changed by the writer. |
| 52 | tx.meta = &common.Meta{} |
| 53 | db.meta().Copy(tx.meta) |
| 54 | |
| 55 | // Copy over the root bucket. |
| 56 | tx.root = newBucket(tx) |
| 57 | tx.root.InBucket = &common.InBucket{} |
| 58 | *tx.root.InBucket = *(tx.meta.RootBucket()) |
| 59 | |
| 60 | // Increment the transaction id and add a page cache for writable transactions. |
| 61 | if tx.writable { |
| 62 | tx.pages = make(map[common.Pgid]*common.Page) |
| 63 | tx.meta.IncTxid() |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // ID returns the transaction id. |
| 68 | func (tx *Tx) ID() int { |