Skip to content

Commit

Permalink
[dbnode] Remove allocation per series ID when streaming block from di…
Browse files Browse the repository at this point in the history
…sk (#3093)
  • Loading branch information
robskillington authored Jan 15, 2021
1 parent 146cad6 commit 5b4f793
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/dbnode/network/server/tchannelthrift/node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,14 @@ func (s *service) fetchReadEncoded(ctx context.Context,
// Re-use reader and id for more memory-efficient processing of
// tags from doc.Metadata
reader := docs.NewEncodedDocumentReader()
id := ident.NewReusableBytesID()
for _, entry := range results.Map().Iter() {
idx := i
i++

id.Reset(entry.Key())
// NB(r): Use a bytes ID here so that this ID doesn't need to be
// copied by the blockRetriever in the streamRequest method when
// it checks if the ID is finalizeable or not with IsNoFinalize.
id := ident.BytesID(entry.Key())

d := entry.Value()
metadata, err := docs.MetadataFromDocument(d, reader)
Expand Down
14 changes: 11 additions & 3 deletions src/dbnode/persist/fs/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,17 @@ func (r *blockRetriever) streamRequest(
nsCtx namespace.Context,
) (bool, error) {
req.shard = shard
// NB(r): Clone the ID as we're not positive it will stay valid throughout
// the lifecycle of the async request.
req.id = r.idPool.Clone(id)

// NB(r): If the ID is a ident.BytesID then we can just hold
// onto this ID.
seriesID := id
if !seriesID.IsNoFinalize() {
// NB(r): Clone the ID as we're not positive it will stay valid throughout
// the lifecycle of the async request.
seriesID = r.idPool.Clone(id)
}

req.id = seriesID
req.start = startTime
req.blockSize = r.blockSize

Expand Down

0 comments on commit 5b4f793

Please sign in to comment.