From 52d6c0b12660fa9fd70785420e8d611f9d18cd31 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 15 Jan 2023 19:35:13 +0000 Subject: [PATCH] as per https://github.com/go-gitea/gitea/issues/22279\#issuecomment-1367904046 Signed-off-by: Andrew Thornton --- contentcoder.go | 4 +++- docvalues.go | 6 +++--- intDecoder.go | 6 +++--- intcoder.go | 6 +++--- new.go | 6 +++--- posting.go | 12 ++++++------ segment.go | 8 ++++---- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/contentcoder.go b/contentcoder.go index b6e7336f..288898a6 100644 --- a/contentcoder.go +++ b/contentcoder.go @@ -37,6 +37,9 @@ var ( ) type chunkedContentCoder struct { + // atomic access to this variable + bytesWritten uint64 + final []byte chunkSize uint64 currChunk uint64 @@ -45,7 +48,6 @@ type chunkedContentCoder struct { compressed []byte // temp buf for snappy compression w io.Writer - bytesWritten uint64 // atomic access to this variable progressiveWrite bool chunkMeta []MetaData diff --git a/docvalues.go b/docvalues.go index bd3574da..384e6f49 100644 --- a/docvalues.go +++ b/docvalues.go @@ -43,6 +43,9 @@ type docVisitState struct { } type docValueReader struct { + // atomic access to this variable + bytesRead uint64 + field string curChunkNum uint64 chunkOffsets []uint64 @@ -50,9 +53,6 @@ type docValueReader struct { curChunkHeader []MetaData curChunkData []byte // compressed data cache uncompressed []byte // temp buf for snappy decompression - - // atomic access to this variable - bytesRead uint64 } func (di *docValueReader) size() int { diff --git a/intDecoder.go b/intDecoder.go index 6b8396aa..bf5b41b0 100644 --- a/intDecoder.go +++ b/intDecoder.go @@ -21,15 +21,15 @@ import ( ) type chunkedIntDecoder struct { + // atomic access to this variable + bytesRead uint64 + startOffset uint64 dataStartOffset uint64 chunkOffsets []uint64 curChunkBytes []byte data []byte r *memUvarintReader - - // atomic access to this variable - bytesRead uint64 } // newChunkedIntDecoder expects an optional or reset chunkedIntDecoder for better reuse. diff --git a/intcoder.go b/intcoder.go index 2957fbd0..35e4efbf 100644 --- a/intcoder.go +++ b/intcoder.go @@ -28,6 +28,9 @@ import ( const termNotEncoded = 0 type chunkedIntCoder struct { + // atomic access to this variable + bytesWritten uint64 + final []byte chunkSize uint64 chunkBuf bytes.Buffer @@ -35,9 +38,6 @@ type chunkedIntCoder struct { currChunk uint64 buf []byte - - // atomic access to this variable - bytesWritten uint64 } // newChunkedIntCoder returns a new chunk int coder which packs data into diff --git a/new.go b/new.go index f659a5d0..3616699f 100644 --- a/new.go +++ b/new.go @@ -96,6 +96,9 @@ var interimPool = sync.Pool{New: func() interface{} { return &interim{} }} // interim holds temporary working data used while converting from // analysis results to a zap-encoded segment type interim struct { + // atomic access to this variable + bytesWritten uint64 + results []index.Document chunkMode uint32 @@ -146,9 +149,6 @@ type interim struct { lastNumDocs int lastOutSize int - - // atomic access to this variable - bytesWritten uint64 } func (s *interim) reset() (err error) { diff --git a/posting.go b/posting.go index dcae817f..0c6c4faa 100644 --- a/posting.go +++ b/posting.go @@ -96,6 +96,9 @@ var NormBits1Hit = uint64(1) // PostingsList is an in-memory representation of a postings list type PostingsList struct { + // atomic access to this variable + bytesRead uint64 + sb *SegmentBase postingsOffset uint64 freqOffset uint64 @@ -109,9 +112,6 @@ type PostingsList struct { normBits1Hit uint64 chunkSize uint64 - - // atomic access to this variable - bytesRead uint64 } // represents an immutable, empty postings list @@ -324,6 +324,9 @@ func (rv *PostingsList) init1Hit(fstVal uint64) error { // PostingsIterator provides a way to iterate through the postings list type PostingsIterator struct { + // atomic access to this variable + bytesRead uint64 + postings *PostingsList all roaring.IntPeekable Actual roaring.IntPeekable @@ -344,9 +347,6 @@ type PostingsIterator struct { includeFreqNorm bool includeLocs bool - - // atomic access to this variable - bytesRead uint64 } var emptyPostingsIterator = &PostingsIterator{} diff --git a/segment.go b/segment.go index f62918c8..0ebeea71 100644 --- a/segment.go +++ b/segment.go @@ -89,6 +89,10 @@ func (*ZapPlugin) Open(path string) (segment.Segment, error) { // SegmentBase is a memory only, read-only implementation of the // segment.Segment interface, using zap's data representation. type SegmentBase struct { + // atomic access to this variable + bytesRead uint64 + bytesWritten uint64 + mem []byte memCRC uint32 chunkMode uint32 @@ -103,10 +107,6 @@ type SegmentBase struct { fieldDvNames []string // field names cached in fieldDvReaders size uint64 - // atomic access to this variable - bytesRead uint64 - bytesWritten uint64 - m sync.Mutex fieldFSTs map[uint16]*vellum.FST }