-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
etcd: Treat etcd watcher errors by restarting the watcher
etcd does not support watching on a compacted revision and will error out. Do a fresh get on the latest revision and restart the watcher. In order to continue maintaining the proper order of events, a local cache is introduced. The ListDone signal is only emitted once at the beginning. On ReList, deletion events are sent for keys which can no longer be found. Fixes: #3010 Signed-off-by: Thomas Graf <thomas@cilium.io>
- Loading branch information
Showing
2 changed files
with
121 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2018 Authors of Cilium | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kvstore | ||
|
||
type watchState struct { | ||
deletionMark bool | ||
} | ||
|
||
type watcherCache map[string]watchState | ||
|
||
func (wc watcherCache) Exists(key []byte) bool { | ||
if _, ok := wc[string(key)]; ok { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (wc watcherCache) RemoveDeleted(f func(string)) { | ||
for k, localKey := range wc { | ||
if localKey.deletionMark { | ||
f(k) | ||
delete(wc, k) | ||
} | ||
} | ||
} | ||
|
||
func (wc watcherCache) MarkAllForDeletion() { | ||
for k := range wc { | ||
wc[k] = watchState{deletionMark: true} | ||
} | ||
} | ||
|
||
func (wc watcherCache) MarkInUse(key []byte) { | ||
wc[string(key)] = watchState{deletionMark: false} | ||
} | ||
|
||
func (wc watcherCache) RemoveKey(key []byte) { | ||
delete(wc, string(key)) | ||
} |