-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dbnode] Use already encoded tags when writing time series to commit log #1898
Changes from 9 commits
dbd2a92
58e51a7
f519dc1
6baa76f
2a08f53
40ded18
286314a
de08040
c86c69b
dedfc89
fe1475a
63c1bf2
d0dfa3c
892da81
ff0248c
d0efa4a
a35b6ad
6c44a91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,9 @@ const ( | |
) | ||
|
||
const ( | ||
defaultMaxFinalizerCapacity = 4 | ||
defaultBlockAllocSize = 16 | ||
defaultMaxFinalizerCapacity = 4 | ||
defaultBlockAllocSize = 16 | ||
defaultThriftBytesPoolMaxAllocSize = 1024 | ||
) | ||
|
||
type poolPolicyDefault struct { | ||
|
@@ -252,6 +253,9 @@ type PoolingPolicy struct { | |
// The initial alloc size for a block. | ||
BlockAllocSize *int `yaml:"blockAllocSize"` | ||
|
||
// The thrift bytes pool max bytes slice allocation for a single binary field. | ||
ThriftBytesPoolMaxAllocSize *int `yaml:"thriftBytesPoolMaxAllocSize"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not really a max is it right? its always this size? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The capacity is always this size, but the actual length/size is determined by the length of the bytes being copied. Since we suffix it with "Alloc" I'm not opposed to just calling it |
||
|
||
// The general pool type (currently only supported: simple). | ||
Type *PoolingType `yaml:"type"` | ||
|
||
|
@@ -418,6 +422,16 @@ func (p *PoolingPolicy) BlockAllocSizeOrDefault() int { | |
return defaultBlockAllocSize | ||
} | ||
|
||
// ThriftBytesPoolMaxAllocSizeOrDefault returns the configured thrift bytes pool | ||
// max alloc size if provided, or a default value otherwise. | ||
func (p *PoolingPolicy) ThriftBytesPoolMaxAllocSizeOrDefault() int { | ||
if p.ThriftBytesPoolMaxAllocSize != nil { | ||
return *p.ThriftBytesPoolMaxAllocSize | ||
} | ||
|
||
return defaultThriftBytesPoolMaxAllocSize | ||
} | ||
|
||
// TypeOrDefault returns the configured pooling type if provided, or a default | ||
// value otherwise. | ||
func (p *PoolingPolicy) TypeOrDefault() PoolingType { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1163,6 +1163,7 @@ func (s *service) WriteBatchRaw(tctx thrift.Context, req *rpc.WriteBatchRawReque | |
if err != nil { | ||
return convert.ToRPCError(err) | ||
} | ||
|
||
// The lifecycle of the annotations is more involved than the rest of the data | ||
// so we set the annotation pool put method as the finalization function and | ||
// let the database take care of returning them to the pool. | ||
|
@@ -1247,9 +1248,12 @@ func (s *service) WriteTaggedBatchRaw(tctx thrift.Context, req *rpc.WriteTaggedB | |
if err != nil { | ||
return convert.ToRPCError(err) | ||
} | ||
// The lifecycle of the annotations is more involved than the rest of the data | ||
// so we set the annotation pool put method as the finalization function and | ||
// let the database take care of returning them to the pool. | ||
|
||
// The lifecycle of the encoded tags and annotations is more involved than | ||
// the rest of the data so we set the encoded tags and annotation pool put | ||
// calls as finalization functions and let the database take care of | ||
// returning them to the pool. | ||
batchWriter.SetFinalizeEncodedTagsFn(finalizeEncodedTagsFn) | ||
batchWriter.SetFinalizeAnnotationFn(finalizeAnnotationFn) | ||
|
||
for i, elem := range req.Elements { | ||
|
@@ -1279,6 +1283,7 @@ func (s *service) WriteTaggedBatchRaw(tctx thrift.Context, req *rpc.WriteTaggedB | |
i, | ||
seriesID, | ||
dec, | ||
elem.EncodedTags, | ||
xtime.FromNormalizedTime(elem.Datapoint.Timestamp, d), | ||
elem.Datapoint.Value, | ||
unit, | ||
|
@@ -1764,7 +1769,11 @@ func (r *writeBatchPooledReq) Finalize() { | |
if r.writeTaggedReq != nil { | ||
for _, elem := range r.writeTaggedReq.Elements { | ||
apachethrift.BytesPoolPut(elem.ID) | ||
apachethrift.BytesPoolPut(elem.EncodedTags) | ||
// Ownership of the encoded tagts has been transferred to the BatchWriter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tags -> tags |
||
// so they will get returned the pool automatically by the commitlog once | ||
// it finishes writing them to disk via the finalization function that | ||
// gets set on the WriteBatch. | ||
|
||
// See comment above about not finalizing annotations here. | ||
} | ||
r.writeTaggedReq = nil | ||
|
@@ -1874,6 +1883,13 @@ func (p *writeBatchPooledReqPool) Put(v *writeBatchPooledReq) { | |
p.pool.Put(v) | ||
} | ||
|
||
// finalizeEncodedTagsFn implements ts.FinalizeEncodedTagsFn because | ||
// apachethrift.BytesPoolPut(b) returns a bool but ts.FinalizeEncodedTagsFn | ||
// does not. | ||
func finalizeEncodedTagsFn(b []byte) { | ||
apachethrift.BytesPoolPut(b) | ||
} | ||
|
||
// finalizeAnnotationFn implements ts.FinalizeAnnotationFn because | ||
// apachethrift.BytesPoolPut(b) returns a bool but ts.FinalizeAnnotationFn | ||
// does not. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ import ( | |
xtime "github.com/m3db/m3/src/x/time" | ||
) | ||
|
||
// FinalizeEncodedTagsFn is a function that will be called for each encoded tags once | ||
// the WriteBatch itself is finalized. | ||
type FinalizeEncodedTagsFn func(b []byte) | ||
|
||
// FinalizeAnnotationFn is a function that will be called for each annotation once | ||
// the WriteBatch itself is finalized. | ||
type FinalizeAnnotationFn func(b []byte) | ||
|
@@ -72,9 +76,13 @@ type Series struct { | |
// ID is the series identifier. | ||
ID ident.ID | ||
|
||
// Tags are the series tags. | ||
// Tags is the series tags. | ||
Tags ident.Tags | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's used on the read side and it was going to be very difficult to remove unfortunately. |
||
|
||
// EncodedTags are the series encoded tags, if set then call sites can | ||
// avoid needing to encoded the tags from the series tags provided. | ||
EncodedTags EncodedTags | ||
|
||
// Shard is the shard the series belongs to. | ||
Shard uint32 | ||
} | ||
|
@@ -90,6 +98,9 @@ func (d Datapoint) Equal(x Datapoint) bool { | |
return d.Timestamp.Equal(x.Timestamp) && d.Value == x.Value | ||
} | ||
|
||
// EncodedTags represents the encoded tags for the series. | ||
type EncodedTags []byte | ||
|
||
// Annotation represents information used to annotate datapoints. | ||
type Annotation []byte | ||
|
||
|
@@ -120,17 +131,20 @@ type BatchWriter interface { | |
value float64, | ||
unit xtime.Unit, | ||
annotation []byte, | ||
) | ||
) error | ||
|
||
AddTagged( | ||
originalIndex int, | ||
id ident.ID, | ||
tags ident.TagIterator, | ||
encodedTags EncodedTags, | ||
timestamp time.Time, | ||
value float64, | ||
unit xtime.Unit, | ||
annotation []byte, | ||
) | ||
) error | ||
|
||
SetFinalizeEncodedTagsFn(f FinalizeEncodedTagsFn) | ||
|
||
SetFinalizeAnnotationFn(f FinalizeAnnotationFn) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just merge this into master of our branch? Pretty confusing that we're pinned to a branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not opposed to it, problem is master is way ahead of where we are at, so we'd have to reset master all the way back to 0.9.3 on our fork which would be weird...