Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer - Remove recursive locks in snapshot node #1004

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions utils/reposnapshot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,26 @@ func (node *Node) action(action ActionOnNodeFunc) error {

// Convert node to wrapper in order to save it to file.
func (node *Node) convertToWrapper() (wrapper *NodeExportWrapper, err error) {
var children []*Node
err = node.action(func(node *Node) error {
wrapper = &NodeExportWrapper{
Name: node.name,
Completed: node.NodeStatus == Completed,
}
for i := range node.children {
converted, err := node.children[i].convertToWrapper()
if err != nil {
return err
}
wrapper.Children = append(wrapper.Children, converted)
}
children = node.children
return nil
})
if err != nil {
return
}

for i := range children {
converted, err := children[i].convertToWrapper()
if err != nil {
return nil, err
}
wrapper.Children = append(wrapper.Children, converted)
}
return
}

Expand Down Expand Up @@ -107,17 +113,19 @@ func (node *Node) getActualPath() (actualPath string, err error) {
}

// Sets node as completed, clear its contents, notifies parent to check completion.
func (node *Node) setCompleted() error {
return node.action(func(node *Node) error {
func (node *Node) setCompleted() (err error) {
var parent *Node
err = node.action(func(node *Node) error {
node.NodeStatus = Completed
node.children = nil
parent := node.parent
parent = node.parent
node.parent = nil
if parent != nil {
return parent.CheckCompleted()
}
return nil
})
if err == nil && parent != nil {
return parent.CheckCompleted()
}
return
}

// Check if node completed - if done exploring, done handling files, children are completed.
Expand Down Expand Up @@ -233,30 +241,39 @@ func (node *Node) RestartExploring() error {
// For a structure such as repo->dir1->dir2->dir3
// The initial call will be to the root, and for an input of ({"dir1","dir2"}), and the final output will be a pointer to dir2.
func (node *Node) findMatchingNode(childrenDirs []string) (matchingNode *Node, err error) {
err = node.action(func(node *Node) error {
// The node was found in the cache. Let's return it.
if len(childrenDirs) == 0 {
matchingNode = node
return nil
}
// The node was found in the cache. Let's return it.
if len(childrenDirs) == 0 {
matchingNode = node
return
}

// Check if any of the current node's children are parents of the current node.
for i := range node.children {
if node.children[i].name == childrenDirs[0] {
matchingNode, err = node.children[i].findMatchingNode(childrenDirs[1:])
return err
}
// Check if any of the current node's children are parents of the current node.
var children []*Node
err = node.action(func(node *Node) error {
children = node.children
return nil
})
if err != nil {
return
}
for i := range children {
if children[i].name == childrenDirs[0] {
matchingNode, err = children[i].findMatchingNode(childrenDirs[1:])
return
}
}

// None of the current node's children are parents of the current node.
// This means we need to start creating the searched node parents.
newNode := CreateNewNode(childrenDirs[0], node)
newNode.parent = node
// None of the current node's children are parents of the current node.
// This means we need to start creating the searched node parents.
newNode := CreateNewNode(childrenDirs[0], node)
err = node.action(func(node *Node) error {
node.children = append(node.children, newNode)
matchingNode, err = newNode.findMatchingNode(childrenDirs[1:])
return err
return nil
})
return
if err != nil {
return
}
return newNode.findMatchingNode(childrenDirs[1:])
}

func CreateNewNode(dirName string, parent *Node) *Node {
Expand Down
Loading