Skip to content

Commit a13f783

Browse files
committed
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>
1 parent 71e14dd commit a13f783

File tree

6 files changed

+447
-277
lines changed

6 files changed

+447
-277
lines changed

libnetwork/bitseq/sequence.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ func NewHandle(app string, ds datastore.DataStore, id string, numElements uint32
5757
return h, nil
5858
}
5959

60-
// Register for status changes
61-
h.watchForChanges()
62-
6360
// Get the initial status from the ds if present.
6461
if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
6562
return nil, err
@@ -252,6 +249,12 @@ func (h *Handle) set(ordinal, start, end uint32, any bool, release bool) (uint32
252249
)
253250

254251
for {
252+
if h.store != nil {
253+
if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
254+
return ret, err
255+
}
256+
}
257+
255258
h.Lock()
256259
// Get position if available
257260
if release {

libnetwork/bitseq/store.go

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,47 @@ func (h *Handle) Exists() bool {
7070
return h.dbExists
7171
}
7272

73+
// New method returns a handle based on the receiver handle
74+
func (h *Handle) New() datastore.KVObject {
75+
h.Lock()
76+
defer h.Unlock()
77+
78+
return &Handle{
79+
app: h.app,
80+
id: h.id,
81+
store: h.store,
82+
}
83+
}
84+
85+
// CopyTo deep copies the handle into the passed destination object
86+
func (h *Handle) CopyTo(o datastore.KVObject) error {
87+
h.Lock()
88+
defer h.Unlock()
89+
90+
dstH := o.(*Handle)
91+
dstH.bits = h.bits
92+
dstH.unselected = h.unselected
93+
dstH.head = h.head.getCopy()
94+
dstH.app = h.app
95+
dstH.id = h.id
96+
dstH.dbIndex = h.dbIndex
97+
dstH.dbExists = h.dbExists
98+
dstH.store = h.store
99+
100+
return nil
101+
}
102+
73103
// Skip provides a way for a KV Object to avoid persisting it in the KV Store
74104
func (h *Handle) Skip() bool {
75105
return false
76106
}
77107

78108
// DataScope method returns the storage scope of the datastore
79-
func (h *Handle) DataScope() datastore.DataScope {
80-
return datastore.GlobalScope
81-
}
82-
83-
func (h *Handle) watchForChanges() error {
109+
func (h *Handle) DataScope() string {
84110
h.Lock()
85-
store := h.store
86-
h.Unlock()
87-
88-
if store == nil {
89-
return nil
90-
}
111+
defer h.Unlock()
91112

92-
kvpChan, err := store.KVStore().Watch(datastore.Key(h.Key()...), nil)
93-
if err != nil {
94-
return err
95-
}
96-
go func() {
97-
for {
98-
select {
99-
case kvPair := <-kvpChan:
100-
// Only process remote update
101-
if kvPair != nil && (kvPair.LastIndex != h.Index()) {
102-
err := h.fromDsValue(kvPair.Value)
103-
if err != nil {
104-
log.Warnf("Failed to reconstruct bitseq handle from ds watch: %s", err.Error())
105-
} else {
106-
h.SetIndex(kvPair.LastIndex)
107-
}
108-
}
109-
}
110-
}
111-
}()
112-
return nil
113+
return h.store.Scope()
113114
}
114115

115116
func (h *Handle) fromDsValue(value []byte) error {

0 commit comments

Comments
 (0)