diff options
| author | Ben Johnson <benbjohnson@yahoo.com> | 2015-05-18 10:14:47 -0600 |
|---|---|---|
| committer | Ben Johnson <benbjohnson@yahoo.com> | 2015-05-18 10:14:47 -0600 |
| commit | bf5458de2f302248c02015a7439104baa9b0b103 (patch) | |
| tree | d95895e201fb3ec26c3ca8982efabba3010aa63c /tx.go | |
| parent | fix `slice bounds out of range`/maxAllocSize bugs (diff) | |
| download | dedo-bf5458de2f302248c02015a7439104baa9b0b103.tar.gz dedo-bf5458de2f302248c02015a7439104baa9b0b103.tar.xz | |
Add inline documentation for bdc109b.
This commit simply adds some additional comments to the commit provided
by sasha-s that fixes the "slice out of bounds" errors.
Diffstat (limited to 'tx.go')
| -rw-r--r-- | tx.go | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -422,26 +422,38 @@ func (tx *Tx) write() error { for _, p := range pages { size := (int(p.overflow) + 1) * tx.db.pageSize offset := int64(p.id) * int64(tx.db.pageSize) + + // Write out page in "max allocation" sized chunks. ptr := (*[maxAllocSize]byte)(unsafe.Pointer(p)) for { + // Limit our write to our max allocation size. sz := size if sz > maxAllocSize-1 { sz = maxAllocSize - 1 } + + // Write chunk to disk. buf := ptr[:sz] if _, err := tx.db.ops.writeAt(buf, offset); err != nil { return err } + // Update statistics. tx.stats.Write++ + + // Exit inner for loop if we've written all the chunks. size -= sz if size == 0 { break } + + // Otherwise move offset forward and move pointer to next chunk. offset += int64(sz) ptr = (*[maxAllocSize]byte)(unsafe.Pointer(&ptr[sz])) } } + + // Ignore file sync if flag is set on DB. if !tx.db.NoSync || IgnoreNoSync { if err := fdatasync(tx.db); err != nil { return err |
