summaryrefslogtreecommitdiff
path: root/libnetwork/bitseq
diff options
context:
space:
mode:
authorJana Radhakrishnan <mrjana@docker.com>2015-10-05 04:24:44 -0700
committerJana Radhakrishnan <mrjana@docker.com>2015-10-06 14:16:06 -0700
commita13f78369f2af8d4694c9725d250da36e07e08cf (patch)
treefadecc4d3b648ef222f0181598529edf842cf2cb /libnetwork/bitseq
parent71e14dd52a3e8f728d4b4997f2441fcc1dcde16c (diff)
downloaddocker-a13f78369f2af8d4694c9725d250da36e07e08cf.tar.gz
IPAM watch removal and multistore support
Remove the need for watching for IPAM data structures and add multi store support code and data reorganization to simplify address space management. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Diffstat (limited to 'libnetwork/bitseq')
-rw-r--r--libnetwork/bitseq/sequence.go9
-rw-r--r--libnetwork/bitseq/store.go65
2 files changed, 39 insertions, 35 deletions
diff --git a/libnetwork/bitseq/sequence.go b/libnetwork/bitseq/sequence.go
index 1120ac77c8..20c50c91ed 100644
--- a/libnetwork/bitseq/sequence.go
+++ b/libnetwork/bitseq/sequence.go
@@ -57,9 +57,6 @@ func NewHandle(app string, ds datastore.DataStore, id string, numElements uint32
return h, nil
}
- // Register for status changes
- h.watchForChanges()
-
// Get the initial status from the ds if present.
if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
return nil, err
@@ -252,6 +249,12 @@ func (h *Handle) set(ordinal, start, end uint32, any bool, release bool) (uint32
)
for {
+ if h.store != nil {
+ if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
+ return ret, err
+ }
+ }
+
h.Lock()
// Get position if available
if release {
diff --git a/libnetwork/bitseq/store.go b/libnetwork/bitseq/store.go
index 8012a413d2..ef7fe33400 100644
--- a/libnetwork/bitseq/store.go
+++ b/libnetwork/bitseq/store.go
@@ -70,46 +70,47 @@ func (h *Handle) Exists() bool {
return h.dbExists
}
+// New method returns a handle based on the receiver handle
+func (h *Handle) New() datastore.KVObject {
+ h.Lock()
+ defer h.Unlock()
+
+ return &Handle{
+ app: h.app,
+ id: h.id,
+ store: h.store,
+ }
+}
+
+// CopyTo deep copies the handle into the passed destination object
+func (h *Handle) CopyTo(o datastore.KVObject) error {
+ h.Lock()
+ defer h.Unlock()
+
+ dstH := o.(*Handle)
+ dstH.bits = h.bits
+ dstH.unselected = h.unselected
+ dstH.head = h.head.getCopy()
+ dstH.app = h.app
+ dstH.id = h.id
+ dstH.dbIndex = h.dbIndex
+ dstH.dbExists = h.dbExists
+ dstH.store = h.store
+
+ return nil
+}
+
// Skip provides a way for a KV Object to avoid persisting it in the KV Store
func (h *Handle) Skip() bool {
return false
}
// DataScope method returns the storage scope of the datastore
-func (h *Handle) DataScope() datastore.DataScope {
- return datastore.GlobalScope
-}
-
-func (h *Handle) watchForChanges() error {
+func (h *Handle) DataScope() string {
h.Lock()
- store := h.store
- h.Unlock()
-
- if store == nil {
- return nil
- }
+ defer h.Unlock()
- kvpChan, err := store.KVStore().Watch(datastore.Key(h.Key()...), nil)
- if err != nil {
- return err
- }
- go func() {
- for {
- select {
- case kvPair := <-kvpChan:
- // Only process remote update
- if kvPair != nil && (kvPair.LastIndex != h.Index()) {
- err := h.fromDsValue(kvPair.Value)
- if err != nil {
- log.Warnf("Failed to reconstruct bitseq handle from ds watch: %s", err.Error())
- } else {
- h.SetIndex(kvPair.LastIndex)
- }
- }
- }
- }
- }()
- return nil
+ return h.store.Scope()
}
func (h *Handle) fromDsValue(value []byte) error {