meta retrieves the current meta page reference.
()
| 1139 | |
| 1140 | // meta retrieves the current meta page reference. |
| 1141 | func (db *DB) meta() *common.Meta { |
| 1142 | // We have to return the meta with the highest txid which doesn't fail |
| 1143 | // validation. Otherwise, we can cause errors when in fact the database is |
| 1144 | // in a consistent state. metaA is the one with the higher txid. |
| 1145 | metaA := db.meta0 |
| 1146 | metaB := db.meta1 |
| 1147 | if db.meta1.Txid() > db.meta0.Txid() { |
| 1148 | metaA = db.meta1 |
| 1149 | metaB = db.meta0 |
| 1150 | } |
| 1151 | |
| 1152 | // Use higher meta page if valid. Otherwise, fallback to previous, if valid. |
| 1153 | if err := metaA.Validate(); err == nil { |
| 1154 | return metaA |
| 1155 | } else if err := metaB.Validate(); err == nil { |
| 1156 | return metaB |
| 1157 | } |
| 1158 | |
| 1159 | // This should never be reached, because both meta1 and meta0 were validated |
| 1160 | // on mmap() and we do fsync() on every write. |
| 1161 | panic("bolt.DB.meta(): invalid meta pages") |
| 1162 | } |
| 1163 | |
| 1164 | // allocate returns a contiguous block of memory starting at a given page. |
| 1165 | func (db *DB) allocate(txid common.Txid, count int) (*common.Page, error) { |
no test coverage detected