-
Notifications
You must be signed in to change notification settings - Fork 105
remove branch vs leaf node restriction in index #490
Conversation
This is mostly done, just need to add unit tests to verify that the index works for mixed branch/leaf nodes |
no significant change in performance of the index. old
new
|
38236ee
to
e6dbcfa
Compare
idx/memory/memory_test.go
Outdated
@@ -96,6 +98,7 @@ func TestGetAddKey(t *testing.T) { | |||
} | |||
|
|||
func TestFind(t *testing.T) { | |||
log.NewLogger(0, "console", fmt.Sprintf(`{"level": %d, "formatting":false}`, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this do? i don't see any log calls in any of the tests in idx/memory
or is this to make the log calls in memory.go work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just left over from me debugging (it makes the log calls in memory.go work). It should be removed.
idx/memory/memory.go
Outdated
Children []string | ||
Defs []string | ||
Leaf bool | ||
HasChildren bool | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment to the Node type here as well as the one in idx.go , explaining their respective purpose. for the reader (at least for me) it's confusing why there are two types, how and why they differ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am considering changing the struct to just
type Node struct {
Path string
Children []string
Defs []string
}
And the node is a leaf if len(n.Defs) > 0
and the node HasChildren if len(n.Children) > 0
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds fine by me. and those two concepts are independent from each other right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. a node can be a leaf node or a branch node (hasChildren) or both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment to the Node type here as well as the one in idx.go , explaining their respective purpose. for the reader (at least for me) it's confusing why there are two types, how and why they differ.
lets get PR #504 merged, then i will tackle this again. |
e6dbcfa
to
9b2623b
Compare
This is now ready for review. Unfortunately, the Grafana query editor is unable to view series that are a descendant of a leaf node as graphite still does not correctly support this. When you have a series called "foo.bar" and a second series called "foo.bar.baz", carbon will write a whisper file for each. However the graphite "/metrics/find?" query only supports sending back that a node is a leaf or a branch and not both due to:
However, if you set the Grafana queryEditor to raw mode, you can add the full series path and it will render. When we add graphite query handling directly to MT, we can fix this limitation. |
idx/memory/memory.go
Outdated
@@ -242,17 +237,17 @@ func (m *MemoryIdx) add(def *schema.MetricDefinition) error { | |||
log.Debug("memory-idx: creating branch %s with child %s", branch, nodes[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this loop startPos
is not used anymore. So instead of declaring i
and assigning the value of startPos
to it, we could also just use startPos
in place of i
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startPos is used after this loop and I dont see how i can maintain the same logic when removing i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... ok.
Basically my idea was this, but I must be missing where else it's used...
// Add missing branch nodes
for ; startPos < len(nodes); startPos++ {
branch := strings.Join(nodes[0:startPos], ".")
log.Debug("memory-idx: creating branch %s with child %s", branch, nodes[startPos])
tree.Items[branch] = &Node{
Path: branch,
Children: []string{nodes[startPos]},
Defs: make([]string, 0),
}
}
// Add leaf node
log.Debug("memory-idx: creating leaf %s", path)
tree.Items[path] = &Node{
Path: path,
Children: []string{},
Defs: []string{def.Id},
}
m.DefById[def.Id] = def
statAddOk.Inc()
return nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That definitely wont work.
The purpose of this loop is to search backwards down the tree until we find a branch that exists.
then from https://github.com/raintank/metrictank/blob/9b2623b29398feb54795eb4bf0a9ecc42f544ba0/idx/memory/memory.go#L231-L243
we walk back up the tree creating all of the needed nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, nevermind i was looking at the wrong loop. Your suggestion will work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we talking about the same loop? actually that's really not important enough to spend time arguing, but i think according to your description you're referring to the previous loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me... That's some impressive data structure management
9b2623b
to
008737c
Compare
fixes #392