bolt/meta.go

45 lines
931 B
Go
Raw Normal View History

2014-01-08 15:06:17 +00:00
package bolt
2014-02-04 22:30:05 +00:00
const magic uint32 = 0xED0CDAED
2014-01-10 14:32:12 +00:00
type meta struct {
2014-01-24 23:32:18 +00:00
magic uint32
version uint32
pageSize uint32
2014-01-31 18:18:51 +00:00
flags uint32
2014-02-06 05:15:47 +00:00
buckets pgid
2014-02-09 22:52:19 +00:00
freelist pgid
2014-01-31 18:18:51 +00:00
pgid pgid
txid txid
2014-01-10 14:32:12 +00:00
}
// validate checks the marker bytes and version of the meta page to ensure it matches this binary.
func (m *meta) validate() error {
if m.magic != magic {
2014-02-16 19:18:44 +00:00
return ErrInvalid
2014-01-31 17:22:58 +00:00
} else if m.version != version {
2014-02-16 19:18:44 +00:00
return ErrVersionMismatch
2014-01-10 14:32:12 +00:00
}
return nil
}
2014-01-30 03:35:58 +00:00
// copy copies one meta object to another.
func (m *meta) copy(dest *meta) {
2014-01-30 23:22:02 +00:00
dest.magic = m.magic
dest.version = m.version
2014-01-30 03:35:58 +00:00
dest.pageSize = m.pageSize
2014-02-09 22:52:19 +00:00
dest.buckets = m.buckets
dest.freelist = m.freelist
2014-01-30 03:35:58 +00:00
dest.pgid = m.pgid
dest.txid = m.txid
2014-01-30 03:35:58 +00:00
}
2014-01-30 23:22:02 +00:00
// write writes the meta onto a page.
func (m *meta) write(p *page) {
2014-03-09 03:25:37 +00:00
// Page id is either going to be 0 or 1 which we can determine by the transaction ID.
p.id = pgid(m.txid % 2)
2014-02-12 21:57:27 +00:00
p.flags |= metaPageFlag
2014-01-30 23:22:02 +00:00
m.copy(p.meta())
}