-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Bloomshipper: Use model.Time
in MetaRef
and BlockRef
#11566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,15 +33,15 @@ type Ref struct { | |
TenantID string | ||
TableName string | ||
MinFingerprint, MaxFingerprint uint64 | ||
StartTimestamp, EndTimestamp int64 | ||
StartTimestamp, EndTimestamp model.Time | ||
Checksum uint32 | ||
} | ||
|
||
// Cmp returns the fingerprint's position relative to the bounds | ||
func (b Ref) Cmp(fp uint64) v1.BoundsCheck { | ||
if fp < b.MinFingerprint { | ||
func (r Ref) Cmp(fp uint64) v1.BoundsCheck { | ||
if fp < r.MinFingerprint { | ||
return v1.Before | ||
} else if fp > b.MaxFingerprint { | ||
} else if fp > r.MaxFingerprint { | ||
return v1.After | ||
} | ||
return v1.Overlap | ||
|
@@ -67,11 +67,9 @@ type Meta struct { | |
} | ||
|
||
type MetaSearchParams struct { | ||
TenantID string | ||
MinFingerprint uint64 | ||
MaxFingerprint uint64 | ||
StartTimestamp int64 | ||
EndTimestamp int64 | ||
TenantID string | ||
MinFingerprint, MaxFingerprint model.Fingerprint | ||
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. I think it's good to use If you are changing 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. Yes, we can change it in the Ref as well. I would create a separate PR for that, though. |
||
StartTimestamp, EndTimestamp model.Time | ||
} | ||
|
||
type MetaClient interface { | ||
|
@@ -128,9 +126,7 @@ type BloomClient struct { | |
} | ||
|
||
func (b *BloomClient) GetMetas(ctx context.Context, params MetaSearchParams) ([]Meta, error) { | ||
start := model.TimeFromUnix(params.StartTimestamp) | ||
end := model.TimeFromUnix(params.EndTimestamp) | ||
tablesByPeriod := tablesByPeriod(b.periodicConfigs, start, end) | ||
tablesByPeriod := tablesByPeriod(b.periodicConfigs, params.StartTimestamp, params.EndTimestamp) | ||
|
||
var metas []Meta | ||
for periodFrom, tables := range tablesByPeriod { | ||
|
@@ -146,8 +142,8 @@ func (b *BloomClient) GetMetas(ctx context.Context, params MetaSearchParams) ([] | |
if err != nil { | ||
return nil, err | ||
} | ||
if metaRef.MaxFingerprint < params.MinFingerprint || params.MaxFingerprint < metaRef.MinFingerprint || | ||
metaRef.StartTimestamp < params.StartTimestamp || params.EndTimestamp < metaRef.EndTimestamp { | ||
if metaRef.MaxFingerprint < uint64(params.MinFingerprint) || uint64(params.MaxFingerprint) < metaRef.MinFingerprint || | ||
metaRef.StartTimestamp.Before(params.StartTimestamp) || metaRef.EndTimestamp.After(params.EndTimestamp) { | ||
continue | ||
} | ||
meta, err := b.downloadMeta(ctx, metaRef, periodClient) | ||
|
@@ -176,24 +172,23 @@ func (b *BloomClient) PutMeta(ctx context.Context, meta Meta) error { | |
|
||
func createBlockObjectKey(meta Ref) string { | ||
blockParentFolder := fmt.Sprintf("%x-%x", meta.MinFingerprint, meta.MaxFingerprint) | ||
filename := fmt.Sprintf("%v-%v-%x", meta.StartTimestamp, meta.EndTimestamp, meta.Checksum) | ||
filename := fmt.Sprintf("%d-%d-%x", meta.StartTimestamp, meta.EndTimestamp, meta.Checksum) | ||
return strings.Join([]string{rootFolder, meta.TableName, meta.TenantID, bloomsFolder, blockParentFolder, filename}, delimiter) | ||
} | ||
|
||
func createMetaObjectKey(meta Ref) string { | ||
filename := fmt.Sprintf("%x-%x-%v-%v-%x", meta.MinFingerprint, meta.MaxFingerprint, meta.StartTimestamp, meta.EndTimestamp, meta.Checksum) | ||
filename := fmt.Sprintf("%x-%x-%d-%d-%x", meta.MinFingerprint, meta.MaxFingerprint, meta.StartTimestamp, meta.EndTimestamp, meta.Checksum) | ||
return strings.Join([]string{rootFolder, meta.TableName, meta.TenantID, metasFolder, filename}, delimiter) | ||
} | ||
|
||
func findPeriod(configs []config.PeriodConfig, timestamp int64) (config.DayTime, error) { | ||
ts := model.TimeFromUnix(timestamp) | ||
func findPeriod(configs []config.PeriodConfig, ts model.Time) (config.DayTime, error) { | ||
for i := len(configs) - 1; i >= 0; i-- { | ||
periodConfig := configs[i] | ||
if periodConfig.From.Before(ts) || periodConfig.From.Equal(ts) { | ||
return periodConfig.From, nil | ||
} | ||
} | ||
return config.DayTime{}, fmt.Errorf("can not find period for timestamp %d", timestamp) | ||
return config.DayTime{}, fmt.Errorf("can not find period for timestamp %d", ts) | ||
} | ||
|
||
func (b *BloomClient) DeleteMeta(ctx context.Context, meta Meta) error { | ||
|
@@ -289,7 +284,6 @@ func (b *BloomClient) downloadMeta(ctx context.Context, metaRef MetaRef, client | |
return meta, nil | ||
} | ||
|
||
// todo cover with tests | ||
func createMetaRef(objectKey string, tenantID string, tableName string) (MetaRef, error) { | ||
fileName := objectKey[strings.LastIndex(objectKey, delimiter)+1:] | ||
parts := strings.Split(fileName, fileNamePartDelimiter) | ||
|
@@ -323,8 +317,8 @@ func createMetaRef(objectKey string, tenantID string, tableName string) (MetaRef | |
TableName: tableName, | ||
MinFingerprint: minFingerprint, | ||
MaxFingerprint: maxFingerprint, | ||
StartTimestamp: startTimestamp, | ||
EndTimestamp: endTimestamp, | ||
StartTimestamp: model.Time(startTimestamp), | ||
EndTimestamp: model.Time(endTimestamp), | ||
Checksum: uint32(checksum), | ||
}, | ||
FilePath: objectKey, | ||
|
@@ -354,9 +348,9 @@ func tablesByPeriod(periodicConfigs []config.PeriodConfig, start, end model.Time | |
|
||
func tablesForRange(periodConfig config.PeriodConfig, from, to int64) []string { | ||
interval := periodConfig.IndexTables.Period | ||
intervalSeconds := interval.Seconds() | ||
lower := from / int64(intervalSeconds) | ||
upper := to / int64(intervalSeconds) | ||
step := int64(interval.Seconds()) | ||
lower := from / step | ||
upper := to / step | ||
tables := make([]string, 0, 1+upper-lower) | ||
prefix := periodConfig.IndexTables.Prefix | ||
for i := lower; i <= upper; i++ { | ||
|
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.
doesn't this complain?
min/maxFp
aremodel.Fingerprint