diff options
| author | Shulhan <ms@kilabit.info> | 2019-03-02 07:29:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-03-02 07:29:06 +0700 |
| commit | d267665e5f008994ada9a87b42d259b3b0980dd6 (patch) | |
| tree | be24e674a4008f167b09883e64a4539679986efc | |
| parent | b6e119a7130f0a6cfdfe2f279b2d01995744fb67 (diff) | |
| download | rescached-d267665e5f008994ada9a87b42d259b3b0980dd6.tar.xz | |
cacheworker: remove method update()
Method update() on cacheworker basically contains one line statement.
Also, update the log format to print ID of query and response and
total caches.
| -rw-r--r-- | cacheworker.go | 16 | ||||
| -rw-r--r-- | cacheworker_test.go | 13 | ||||
| -rw-r--r-- | cmd/rescached/main.go | 2 | ||||
| -rw-r--r-- | rescached.go | 17 | ||||
| -rw-r--r-- | response.go | 5 |
5 files changed, 25 insertions, 28 deletions
diff --git a/cacheworker.go b/cacheworker.go index 208e6b9..2bcfa78 100644 --- a/cacheworker.go +++ b/cacheworker.go @@ -100,7 +100,8 @@ func (cw *cacheWorker) upsert(msg *dns.Message, isLocal bool) bool { cw.cachesList.fix(res) if debug.Value >= 1 { - fmt.Printf("+ update : %4c %10d %s\n", '-', res.accessedAt, + fmt.Printf("+ update : Total:%-4d ID:%-5d %s\n", + cw.cachesList.length(), res.message.Header.ID, res.message.Question) } } @@ -124,22 +125,13 @@ func (cw *cacheWorker) push(qname string, msg *dns.Message, isLocal bool) { cw.cachesList.push(res) if debug.Value >= 1 { - fmt.Printf("+ caching: %4d %10d %s\n", - cw.cachesList.length(), res.accessedAt, + fmt.Printf("+ insert : Total:%-4d ID:%-5d %s\n", + cw.cachesList.length(), res.message.Header.ID, res.message.Question) } } } -func (cw *cacheWorker) update(res *response) { - cw.cachesList.fix(res) - - if debug.Value >= 1 { - fmt.Printf("= cache : %4d %10d %s\n", cw.cachesList.length(), - res.accessedAt, res.message.Question) - } -} - func (cw *cacheWorker) remove(res *response) { if res == nil || res.message == nil { return diff --git a/cacheworker_test.go b/cacheworker_test.go index bafbd89..31ef2f7 100644 --- a/cacheworker_test.go +++ b/cacheworker_test.go @@ -151,19 +151,14 @@ func TestCacheWorkerUpsert(t *testing.T) { test.Assert(t, "return value", c.expReturn, gotReturn, true) assertCaches(t, c.expCaches) - assertCachesList(t, c.expCachesList) } -} -func TestCacheWorkerUpdate(t *testing.T) { first := testCacheWorker.cachesList.v.Front() - res := first.Value.(*response) - - testCacheWorker.update(res) - - exp := `^cachesList\[&{\d{10} \d{10} &{Name:test1 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test2 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test1 Type:2 Class:1}}\]$` // nolint: lll - assertCachesList(t, exp) + if first != nil { + res := first.Value.(*response) + testCacheWorker.cachesList.fix(res) + } } func TestCacheWorkerRemove(t *testing.T) { diff --git a/cmd/rescached/main.go b/cmd/rescached/main.go index 2672f07..feb9376 100644 --- a/cmd/rescached/main.go +++ b/cmd/rescached/main.go @@ -60,7 +60,7 @@ func debugRuntime(rcd *rescached.Server) { memHeap.Collect() println(rcd.CachesStats()) - fmt.Printf("= rescached.MemHeap: {RelHeapAlloc:%d RelHeapObjects:%d DiffHeapObjects:%d}\n", + fmt.Printf("= rescached: MemHeap{RelHeapAlloc:%d RelHeapObjects:%d DiffHeapObjects:%d}\n", memHeap.RelHeapAlloc, memHeap.RelHeapObjects, memHeap.DiffHeapObjects) } diff --git a/rescached.go b/rescached.go index 812d4ed..0c38dc6 100644 --- a/rescached.go +++ b/rescached.go @@ -81,7 +81,7 @@ func New(opts *Options) *Server { } func (srv *Server) CachesStats() string { - return fmt.Sprintf("= rescached.CachesStats: {caches:%d cachesList:%d}", + return fmt.Sprintf("= rescached: CachesStats{caches:%d cachesList:%d}", srv.cw.caches.length(), srv.cw.cachesList.length()) } @@ -379,7 +379,9 @@ func (srv *Server) processRequest(req *dns.Request) { return } if debug.Value >= 1 { - fmt.Printf("< request: %4d %10c %s\n", req.Kind, '-', req.Message.Question) + fmt.Printf("< request: Kind:%-4s ID:%-5d %s\n", + dns.ConnTypeNames[req.Kind], + req.Message.Header.ID, req.Message.Question) } // Check if request query name exist in cache. @@ -400,10 +402,17 @@ func (srv *Server) processRequest(req *dns.Request) { // Ignore update on local caches if res.receivedAt == 0 { if debug.Value >= 1 { - fmt.Printf("= local : %s\n", res.message.Question) + fmt.Printf("= local : ID:%-5d %s\n", + res.message.Header.ID, res.message.Question) } } else { - srv.cw.update(res) + if debug.Value >= 1 { + fmt.Printf("= cache : Total:%-4d ID:%-5d %s\n", + srv.cw.cachesList.length(), + res.message.Header.ID, res.message.Question) + } + + srv.cw.cachesList.fix(res) } } diff --git a/response.go b/response.go index 301727f..016f232 100644 --- a/response.go +++ b/response.go @@ -70,8 +70,9 @@ func (res *response) isExpired() bool { if res.message.IsExpired(elapSeconds) { if debug.Value >= 1 { - fmt.Printf("- expired: %4d %10d %s\n", elapSeconds, - res.receivedAt, res.message.Question) + fmt.Printf("- expired: Elaps:%-4d ID:%-5d %s\n", + elapSeconds, + res.message.Header.ID, res.message.Question) } return true |
