summaryrefslogtreecommitdiff
path: root/libpod/in_memory_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-07-24 16:11:26 -0400
committerMatthew Heon <matthew.heon@gmail.com>2018-07-24 16:12:31 -0400
commit1b51e88098e0c77cddd8de3484ef56965352bcf3 (patch)
tree6d03fc698722a711200ed41209a865f205676896 /libpod/in_memory_state.go
parenta05a97432c6e78849ffb176c929262089233838d (diff)
downloadpodman-1b51e88098e0c77cddd8de3484ef56965352bcf3.tar.gz
podman-1b51e88098e0c77cddd8de3484ef56965352bcf3.tar.bz2
podman-1b51e88098e0c77cddd8de3484ef56965352bcf3.zip
Update comments in BoltDB and In-Memory states
Better explain the inner workings of both state types in comments to make reviews and changes easier. Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/in_memory_state.go')
-rw-r--r--libpod/in_memory_state.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go
index d421a5e8b..8bdd0881c 100644
--- a/libpod/in_memory_state.go
+++ b/libpod/in_memory_state.go
@@ -14,16 +14,27 @@ import (
// An InMemoryState is a purely in-memory state store
type InMemoryState struct {
- pods map[string]*Pod
- containers map[string]*Container
- ctrDepends map[string][]string
- podContainers map[string]map[string]*Container
- nameIndex *registrar.Registrar
- idIndex *truncindex.TruncIndex
- namespace string
+ // Maps pod ID to pod struct.
+ pods map[string]*Pod
+ // Maps container ID to container struct.
+ containers map[string]*Container
+ // Maps container ID to a list of IDs of dependencies.
+ ctrDepends map[string][]string
+ // Maps pod ID to a map of container ID to container struct.
+ podContainers map[string]map[string]*Container
+ // Global name registry - ensures name uniqueness and performs lookups.
+ nameIndex *registrar.Registrar
+ // Global ID registry - ensures ID uniqueness and performs lookups.
+ idIndex *truncindex.TruncIndex
+ // Namespace the state is joined to.
+ namespace string
+ // Maps namespace name to local ID and name registries for looking up
+ // pods and containers in a specific namespace.
namespaceIndexes map[string]*namespaceIndex
}
+// namespaceIndex contains name and ID registries for a specific namespace.
+// This is used for namespaces lookup operations.
type namespaceIndex struct {
nameIndex *registrar.Registrar
idIndex *truncindex.TruncIndex
@@ -339,11 +350,7 @@ func (s *InMemoryState) ContainerInUse(ctr *Container) ([]string, error) {
func (s *InMemoryState) AllContainers() ([]*Container, error) {
ctrs := make([]*Container, 0, len(s.containers))
for _, ctr := range s.containers {
- if s.namespace != "" {
- if ctr.config.Namespace == s.namespace {
- ctrs = append(ctrs, ctr)
- }
- } else {
+ if s.namespace == "" || ctr.config.Namespace == s.namespace {
ctrs = append(ctrs, ctr)
}
}