MCPcopy
hub / github.com/etcd-io/bbolt / allocate

Method allocate

tx.go:501–517  ·  view source on GitHub ↗

allocate returns a contiguous block of memory starting at a given page.

(count int)

Source from the content-addressed store, hash-verified

499
500// allocate returns a contiguous block of memory starting at a given page.
501func (tx *Tx) allocate(count int) (*common.Page, error) {
502 lg := tx.db.Logger()
503 p, err := tx.db.allocate(tx.meta.Txid(), count)
504 if err != nil {
505 lg.Errorf("allocating failed, txid: %d, count: %d, error: %v", tx.meta.Txid(), count, err)
506 return nil, err
507 }
508
509 // Save to our page cache.
510 tx.pages[p.Id()] = p
511
512 // Update statistics.
513 tx.stats.IncPageCount(int64(count))
514 tx.stats.IncPageAlloc(int64(count * tx.db.pageSize))
515
516 return p, nil
517}
518
519// write writes any dirty pages to disk.
520func (tx *Tx) write() error {

Callers 3

TestTx_allocatePageStatsFunction · 0.95
commitFreelistMethod · 0.95
spillMethod · 0.45

Calls 6

LoggerMethod · 0.80
TxidMethod · 0.80
IdMethod · 0.80
IncPageCountMethod · 0.80
IncPageAllocMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestTx_allocatePageStatsFunction · 0.76