Merge pull request #1195 from weaveworks/1177-dns-disappear
Don't periodically delete all non-tombstone entries. Fixes #1177.
This commit is contained in:
commit
f1b5a00cb3
5 files changed
+18
-1
No files matched your search
@@ -131,6 +131,7 @@ func (es *Entries) merge(incoming Entries) Entries {
|
||||
return newEntries
|
||||
}
|
||||
|
||||
// f returning true means keep the entry.
|
||||
func (es *Entries) tombstone(ourname router.PeerName, f func(*Entry) bool) Entries {
|
||||
es.checkAndPanic()
|
||||
defer es.checkAndPanic()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package nameserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -82,4 +83,12 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
||||
router.Methods("DELETE").Path("/name/{container}/{ip}").HandlerFunc(deleteHandler)
|
||||
router.Methods("DELETE").Path("/name/{container}").HandlerFunc(deleteHandler)
|
||||
router.Methods("DELETE").Path("/name").HandlerFunc(deleteHandler)
|
||||
|
||||
router.Methods("GET").Path("/name").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
n.RLock()
|
||||
defer n.RUnlock()
|
||||
if err := json.NewEncoder(w).Encode(n.entries); err != nil {
|
||||
badRequest(w, fmt.Errorf("Error marshalling response: %v", err))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func (n *Nameserver) deleteTombstones() {
|
||||
defer n.Unlock()
|
||||
now := time.Now().Unix()
|
||||
n.entries.filter(func(e *Entry) bool {
|
||||
return now-e.Tombstone <= int64(tombstoneTimeout/time.Second)
|
||||
return e.Tombstone == 0 || now-e.Tombstone <= int64(tombstoneTimeout/time.Second)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +230,9 @@ func TestTombstoneDeletion(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))
|
||||
|
||||
nameserver.deleteTombstones()
|
||||
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))
|
||||
|
||||
err = nameserver.Delete("hostname", "containerid", "", address.Address(0))
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))
|
||||
|
||||
@@ -90,6 +90,10 @@ func (addr Address) IP4() (r net.IP) {
|
||||
return
|
||||
}
|
||||
|
||||
func (addr Address) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("%q", addr.String())), nil
|
||||
}
|
||||
|
||||
func (addr Address) String() string {
|
||||
return addr.IP4().String()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user