File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,14 @@ func managerPerTenantDir(parent string) string {
231
231
}
232
232
233
233
func (m * HeadManager ) Rotate (t time.Time ) error {
234
+ m .mtx .Lock ()
235
+ defer m .mtx .Unlock ()
236
+
237
+ if m .activeHeads != nil && m .period .PeriodFor (t ) == m .period .PeriodFor (m .activeHeads .start ) {
238
+ // no-op, we've already rotated to the desired period
239
+ return nil
240
+ }
241
+
234
242
// create new wal
235
243
nextWALPath := walPath (m .dir , t )
236
244
nextWAL , err := newHeadWAL (m .log , nextWALPath , t )
@@ -255,12 +263,10 @@ func (m *HeadManager) Rotate(t time.Time) error {
255
263
}
256
264
257
265
stopPrev ("previous cycle" ) // stop the previous wal if it hasn't been cleaned up yet
258
- m .mtx .Lock ()
259
266
m .prev = m .active
260
267
m .prevHeads = m .activeHeads
261
268
m .active = nextWAL
262
269
m .activeHeads = nextHeads
263
- m .mtx .Unlock ()
264
270
stopPrev ("freshly rotated" ) // stop the newly rotated-out wal
265
271
266
272
// build tsdb from rotated-out period
@@ -292,10 +298,8 @@ func (m *HeadManager) Rotate(t time.Time) error {
292
298
}
293
299
294
300
// Now that the tsdbManager has the updated TSDBs, we can remove our references
295
- m .mtx .Lock ()
296
301
m .prevHeads = nil
297
302
m .prev = nil
298
- m .mtx .Unlock ()
299
303
return nil
300
304
}
301
305
You can’t perform that action at this time.
0 commit comments