Skip to content

Commit 08b887e

Browse files
committed
clear cache on usr1
1 parent 688c510 commit 08b887e

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

carbon-clickhouse.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"net"
99
"net/http"
1010
"os"
11+
"os/signal"
12+
"syscall"
1113

1214
"github.com/lomik/carbon-clickhouse/carbon"
1315
"github.com/lomik/carbon-clickhouse/helper/RowBinary"
@@ -148,19 +150,16 @@ func main() {
148150
logger.Info("app started")
149151
}
150152

151-
// go func() {
152-
// c := make(chan os.Signal, 1)
153-
// signal.Notify(c, syscall.SIGHUP)
154-
// for {
155-
// <-c
156-
// logrus.Info("HUP received. Reload config")
157-
// if err := app.ReloadConfig(); err != nil {
158-
// logrus.Errorf("Config reload failed: %s", err.Error())
159-
// } else {
160-
// logrus.Info("Config successfully reloaded")
161-
// }
162-
// }
163-
// }()
153+
go func() {
154+
c := make(chan os.Signal, 1)
155+
signal.Notify(c, syscall.SIGUSR1)
156+
157+
for {
158+
<-c
159+
logger.Info("USR1 received. Clear tree cache")
160+
app.ClearTreeExistsCache()
161+
}
162+
}()
164163

165164
app.Loop()
166165

carbon/app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ func (app *App) Start() (err error) {
223223
return
224224
}
225225

226+
// ClearTreeExistsCache in Uploader
227+
func (app *App) ClearTreeExistsCache() {
228+
app.Lock()
229+
up := app.Uploader
230+
app.Unlock()
231+
232+
if up != nil {
233+
go up.ClearTreeExistsCache()
234+
}
235+
}
236+
226237
// Loop ...
227238
func (app *App) Loop() {
228239
app.RLock()

uploader/cmap.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ func (m CMap) Count() int {
4747
return count
4848
}
4949

50+
func (m CMap) Clear() int {
51+
count := 0
52+
for i := 0; i < shardCount; i++ {
53+
shard := m[i]
54+
shard.Lock()
55+
shard.items = make(map[string]bool)
56+
shard.Unlock()
57+
}
58+
return count
59+
}
60+
5061
// Returns shard under given key
5162
func (m CMap) GetShard(key string) *CMapShard {
5263
// @TODO: remove type casts

uploader/uploader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ func (u *Uploader) Stat(send func(metric string, value float64)) {
152152
send("errors", float64(errors))
153153

154154
send("unhandled", float64(atomic.LoadUint32(&u.stat.unhandled)))
155+
156+
send("treeExistsCacheSize", float64(u.treeExists.Count()))
157+
}
158+
159+
func (u *Uploader) ClearTreeExistsCache() {
160+
u.treeExists.Clear()
155161
}
156162

157163
func uploadData(chUrl string, table string, timeout time.Duration, data io.Reader) error {

0 commit comments

Comments
 (0)