From 1627d234da06dc8128d166691dfc1323bc5affb3 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:55:43 +0530 Subject: [PATCH] Moves the atomically accessed member to the top of the struct (#7365) * Moves the 64bit atomically accessed field to the top of the struct. Signed-off-by: Bryan Varner <1652015+bvarner@users.noreply.github.com> * Moves the 64bit atomically accessed field to the top of the struct. Signed-off-by: Bryan Varner <1652015+bvarner@users.noreply.github.com> * Fixing up go fmt formatting issues. Signed-off-by: Bryan Varner <1652015+bvarner@users.noreply.github.com> Co-authored-by: Bryan Varner <1652015+bvarner@users.noreply.github.com> --- tsdb/chunks/head_chunks.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsdb/chunks/head_chunks.go b/tsdb/chunks/head_chunks.go index 486d498d8..a7edbe982 100644 --- a/tsdb/chunks/head_chunks.go +++ b/tsdb/chunks/head_chunks.go @@ -78,13 +78,16 @@ func (e *CorruptionErr) Error() string { // ChunkDiskMapper is for writing the Head block chunks to the disk // and access chunks via mmapped file. type ChunkDiskMapper struct { + // Keep all 64bit atomically accessed variables at the top of this struct. + // See https://golang.org/pkg/sync/atomic/#pkg-note-BUG for more info. + curFileNumBytes int64 // Bytes written in current open file. + /// Writer. dir *os.File curFile *os.File // File being written to. curFileSequence int // Index of current open file being appended to. curFileMaxt int64 // Used for the size retention. - curFileNumBytes int64 // Bytes written in current open file. byteBuf [MaxHeadChunkMetaSize]byte // Buffer used to write the header of the chunk. chkWriter *bufio.Writer // Writer for the current open file.