From 26f6fefeadf1b3e38b86a0a12ba8d1cbb7f347d3 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 30 Jan 2014 18:22:02 -0500 Subject: Add RWTransaction.write(). --- db.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'db.go') diff --git a/db.go b/db.go index 3bee89a..7ffbe09 100644 --- a/db.go +++ b/db.go @@ -118,7 +118,9 @@ func (db *DB) mmap() error { } else if int(info.Size()) < db.pageSize*2 { return &Error{"file size too small", err} } - size := int(info.Size()) + + // TEMP(benbjohnson): Set max size to 1MB. + size := 2 << 20 // Memory-map the data file as a byte slice. if db.data, err = db.syscall.Mmap(int(db.file.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED); err != nil { @@ -159,7 +161,9 @@ func (db *DB) init() error { m.pageSize = uint32(db.pageSize) m.version = Version m.free = 2 - m.sys.root = 3 + m.sys = 3 + m.pgid = 4 + m.txnid = txnid(i) } // Write an empty freelist at page 3. @@ -171,7 +175,7 @@ func (db *DB) init() error { // Write an empty leaf page at page 4. p = db.pageInBuffer(buf[:], pgid(3)) p.id = pgid(3) - p.flags = p_leaf + p.flags = p_sys p.count = 0 // Write the buffer to our data file. @@ -206,7 +210,7 @@ func (db *DB) Transaction() (*Transaction, error) { // Create a transaction associated with the database. t := &Transaction{} - t.init(db, db.meta()) + t.init(db) return t, nil } @@ -230,7 +234,7 @@ func (db *DB) RWTransaction() (*RWTransaction, error) { branches: make(map[pgid]*branch), leafs: make(map[pgid]*leaf), } - t.init(db, db.meta()) + t.init(db) return t, nil } -- cgit v1.2.3