summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state_internal.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-10 16:44:38 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-12 14:28:07 +0000
commitde737c150a00d54b44f4caabc01ec11c26488230 (patch)
tree0c13d0ba43cbb78d08d8fcadf1225ffc0a2f3e01 /libpod/boltdb_state_internal.go
parentdc6a99df4c5ea7facaca20129b2b6c5b53ddb3c1 (diff)
downloadpodman-de737c150a00d54b44f4caabc01ec11c26488230.tar.gz
podman-de737c150a00d54b44f4caabc01ec11c26488230.tar.bz2
podman-de737c150a00d54b44f4caabc01ec11c26488230.zip
Add buckets for all containers and all pods
Now, we don't need to use the global ID registry to iterate - we can iterate only through containers or only through pods, without having to iterate through both. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #184 Approved by: baude
Diffstat (limited to 'libpod/boltdb_state_internal.go')
-rw-r--r--libpod/boltdb_state_internal.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index f26a60905..033dbe8bd 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -15,7 +15,9 @@ const (
idRegistryName = "id-registry"
nameRegistryName = "name-registry"
ctrName = "ctr"
+ allCtrsName = "all-ctrs"
podName = "pod"
+ allPodsName = "allPods"
runtimeConfigName = "runtime-config"
configName = "config"
@@ -30,7 +32,9 @@ var (
idRegistryBkt = []byte(idRegistryName)
nameRegistryBkt = []byte(nameRegistryName)
ctrBkt = []byte(ctrName)
+ allCtrsBkt = []byte(allCtrsName)
podBkt = []byte(podName)
+ allPodsBkt = []byte(allPodsName)
runtimeConfigBkt = []byte(runtimeConfigName)
configKey = []byte(configName)
@@ -138,6 +142,14 @@ func getCtrBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return bkt, nil
}
+func getAllCtrsBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
+ bkt := tx.Bucket(allCtrsBkt)
+ if bkt == nil {
+ return nil, errors.Wrapf(ErrDBBadConfig, "all containers bucket not found in DB")
+ }
+ return bkt, nil
+}
+
func getPodBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
bkt := tx.Bucket(podBkt)
if bkt == nil {
@@ -146,6 +158,14 @@ func getPodBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return bkt, nil
}
+func getAllPodsBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
+ bkt := tx.Bucket(allPodsBkt)
+ if bkt == nil {
+ return nil, errors.Wrapf(ErrDBBadConfig, "all pods bucket not found in DB")
+ }
+ return bkt, nil
+}
+
func getRuntimeConfigBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
bkt := tx.Bucket(runtimeConfigBkt)
if bkt == nil {
@@ -279,6 +299,11 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
return err
}
+ allCtrsBucket, err := getAllCtrsBucket(tx)
+ if err != nil {
+ return err
+ }
+
// If a pod was given, check if it exists
var podDB *bolt.Bucket
var podCtrs *bolt.Bucket
@@ -319,6 +344,9 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
if err := namesBucket.Put(ctrName, ctrID); err != nil {
return errors.Wrapf(err, "error adding container %s name (%s) to DB", ctr.ID(), ctr.Name())
}
+ if err := allCtrsBucket.Put(ctrID, ctrName); err != nil {
+ return errors.Wrapf(err, "error adding container %s to all containers bucket in DB", ctr.ID())
+ }
newCtrBkt, err := ctrBucket.CreateBucket(ctrID)
if err != nil {
@@ -405,6 +433,11 @@ func removeContainer(ctr *Container, pod *Pod, tx *bolt.Tx) error {
return err
}
+ allCtrsBucket, err := getAllCtrsBucket(tx)
+ if err != nil {
+ return err
+ }
+
// Does the pod exist?
var podDB *bolt.Bucket
if pod != nil {
@@ -475,6 +508,9 @@ func removeContainer(ctr *Container, pod *Pod, tx *bolt.Tx) error {
if err := namesBucket.Delete(ctrName); err != nil {
return errors.Wrapf(err, "error deleting container %s name in DB", ctr.ID())
}
+ if err := allCtrsBucket.Delete(ctrID); err != nil {
+ return errors.Wrapf(err, "error deleting container %s from all containers bucket in DB", ctr.ID())
+ }
depCtrs := ctr.Dependencies()