diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 10:04:09 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 10:04:09 -0600 |
commit | cdc2df19c59965149e11c3a5710458c626ea0668 (patch) | |
tree | 2e0bafd99a433d7271bf42e68ab1b5c1eba99e2b /lib/btrfsutil/rebuilt_readitem.go | |
parent | 0b092a27122fcf19479d6cdeae5f7c9493d9741a (diff) | |
parent | 94aa0ec3e9f7145cdf177ad6f6d3d8b7d5bdbef7 (diff) |
Merge branch 'lukeshu/node-cache'
Diffstat (limited to 'lib/btrfsutil/rebuilt_readitem.go')
-rw-r--r-- | lib/btrfsutil/rebuilt_readitem.go | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/btrfsutil/rebuilt_readitem.go b/lib/btrfsutil/rebuilt_readitem.go index d3a2253..73dc01e 100644 --- a/lib/btrfsutil/rebuilt_readitem.go +++ b/lib/btrfsutil/rebuilt_readitem.go @@ -8,8 +8,6 @@ import ( "context" "fmt" - "github.com/datawire/dlib/dlog" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree" @@ -26,16 +24,20 @@ func (ptr ItemPtr) String() string { return fmt.Sprintf("node@%v[%v]", ptr.Node, ptr.Slot) } -func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr, out *btrfstree.Node) { - dlog.Debugf(ctx, "cache-miss node@%v, reading...", laddr) - - graphInfo, ok := ts.graph.Nodes[laddr] +func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item { + graphInfo, ok := ts.graph.Nodes[ptr.Node] if !ok { - panic(fmt.Errorf("should not happen: node@%v is not mentioned in the in-memory graph", laddr)) + panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for node@%v not mentioned in the in-memory graph", ptr.Node)) + } + if graphInfo.Level != 0 { + panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for non-leaf node@%v", ptr.Node)) + } + if ptr.Slot < 0 { + panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for negative item slot: %v", ptr.Slot)) } - node, err := btrfstree.ReadNode[btrfsvol.LogicalAddr](ts.file, ts.sb, laddr, btrfstree.NodeExpectations{ - LAddr: containers.OptionalValue(laddr), + node, err := ts.file.AcquireNode(ctx, ptr.Node, btrfstree.NodeExpectations{ + LAddr: containers.OptionalValue(ptr.Node), Level: containers.OptionalValue(graphInfo.Level), Generation: containers.OptionalValue(graphInfo.Generation), Owner: func(treeID btrfsprim.ObjID, gen btrfsprim.Generation) error { @@ -49,22 +51,12 @@ func (ts *RebuiltForrest) readNode(ctx context.Context, laddr btrfsvol.LogicalAd MinItem: containers.OptionalValue(graphInfo.MinItem()), MaxItem: containers.OptionalValue(graphInfo.MaxItem()), }) + defer ts.file.ReleaseNode(node) if err != nil { panic(fmt.Errorf("should not happen: i/o error: %w", err)) } - *out = *node -} - -func (ts *RebuiltForrest) readItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item { - if ts.graph.Nodes[ptr.Node].Level != 0 { - panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for non-leaf node@%v", ptr.Node)) - } - if ptr.Slot < 0 { - panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for negative item slot: %v", ptr.Slot)) - } - items := ts.nodes.Acquire(ctx, ptr.Node).BodyLeaf - defer ts.nodes.Release(ptr.Node) + items := node.BodyLeaf if ptr.Slot >= len(items) { panic(fmt.Errorf("should not happen: btrfsutil.RebuiltForrest.readItem called for out-of-bounds item slot: slot=%v len=%v", |