(chunkID int, data gather.Bytes)
| 184 | } |
| 185 | |
| 186 | func (w *objectWriter) prepareAndWriteContentChunk(chunkID int, data gather.Bytes) error { |
| 187 | var b gather.WriteBuffer |
| 188 | defer b.Close() |
| 189 | |
| 190 | // allocate buffer to hold either compressed bytes or the uncompressed |
| 191 | comp := content.NoCompression |
| 192 | objectComp := w.compressor |
| 193 | |
| 194 | // in super rare cases this may be stale, but if it is it will be false which is always safe. |
| 195 | supportsContentCompression := w.om.contentMgr.SupportsContentCompression() |
| 196 | |
| 197 | // do not compress in this layer, instead pass comp to the content manager. |
| 198 | if supportsContentCompression && w.compressor != nil { |
| 199 | comp = w.compressor.HeaderID() |
| 200 | objectComp = nil |
| 201 | } |
| 202 | |
| 203 | // metadata objects are ALWAYS compressed at the content layer, irrespective of the index version (1 or 1+). |
| 204 | // even if a compressor for metadata objects is set by the caller, do not compress the objects at this layer; |
| 205 | // instead, let it be handled at the content layer. |
| 206 | if w.prefix != "" { |
| 207 | objectComp = nil |
| 208 | } |
| 209 | |
| 210 | // contentBytes is what we're going to write to the content manager, it potentially uses bytes from b |
| 211 | contentBytes, isCompressed, err := maybeCompressedContentBytes(objectComp, data, &b) |
| 212 | if err != nil { |
| 213 | return errors.Wrap(err, "unable to prepare content bytes") |
| 214 | } |
| 215 | |
| 216 | contentID, err := w.om.contentMgr.WriteContent(w.ctx, contentBytes, w.prefix, comp) |
| 217 | if err != nil { |
| 218 | return errors.Wrapf(err, "unable to write content chunk %v of %v: %v", chunkID, w.description, err) |
| 219 | } |
| 220 | |
| 221 | // update index under a lock |
| 222 | w.indirectIndexGrowMutex.Lock() |
| 223 | w.indirectIndex[chunkID].Object = maybeCompressedObjectID(contentID, isCompressed) |
| 224 | w.indirectIndexGrowMutex.Unlock() |
| 225 | |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | func (w *objectWriter) saveError(err error) error { |
| 230 | if err != nil { |
no test coverage detected