Skip to content

Commit

Permalink
hokud: range check epoch for topk queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski committed Jun 1, 2014
1 parent 9f30d02 commit 2fcfbc5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hokud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ func topkHandler(w http.ResponseWriter, r *http.Request) {
}

// FIXME(dgryski): racey once we move to a ring-buffer?
tk := TopKs[(int64(epoch)-Epoch0)/WindowSize]
t := (int64(epoch) - Epoch0) / WindowSize
if t < 0 || t > int64(len(TopKs)) {
http.Error(w, "bad epoch", http.StatusBadRequest)
return
}
tk := TopKs[t]
response := tk.Keys()

w.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -217,6 +222,8 @@ func loadDataFrom(file string, epoch0 int64, intervals uint, width, depth, topks

scanner := bufio.NewScanner(f)

Epoch0 = epoch0

Hoku = sketch.NewHokusai(epoch0, int64(WindowSize), intervals, width, depth)
TopKs = append(TopKs, topk.New(topks))

Expand Down

0 comments on commit 2fcfbc5

Please sign in to comment.