Skip to content
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

Prevent read on TSDB once closeAllTSDB function has been called #4304

Merged
merged 15 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master / unreleased

* [CHANGE] Querier / ruler: Change `-querier.max-fetched-chunks-per-query` configuration to limit to maximum number of chunks that can be fetched in a single query. The number of chunks fetched by ingesters AND long-term storare combined should not exceed the value configured on `-querier.max-fetched-chunks-per-query`. #4260
* [BUGFIX] Ingester: Prevent any reads on TSDBs when the ingester is stopping. #4304

## 1.10.0-rc.0 / 2021-06-28

Expand Down
45 changes: 45 additions & 0 deletions pkg/ingester/ingester_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,10 @@ func (i *Ingester) v2Query(ctx context.Context, req *client.QueryRequest) (*clie

i.metrics.queries.Inc()

if i.checkIfAllTSDBClosing() {
return &client.QueryResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.QueryResponse{}, nil
Expand Down Expand Up @@ -1048,6 +1052,10 @@ func (i *Ingester) v2QueryExemplars(ctx context.Context, req *client.ExemplarQue

i.metrics.queries.Inc()

if i.checkIfAllTSDBClosing() {
return &client.ExemplarQueryResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.ExemplarQueryResponse{}, nil
Expand Down Expand Up @@ -1093,6 +1101,10 @@ func (i *Ingester) v2LabelValues(ctx context.Context, req *client.LabelValuesReq
return nil, err
}

if i.checkIfAllTSDBClosing() {
return &client.LabelValuesResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.LabelValuesResponse{}, nil
Expand Down Expand Up @@ -1125,6 +1137,10 @@ func (i *Ingester) v2LabelNames(ctx context.Context, req *client.LabelNamesReque
return nil, err
}

if i.checkIfAllTSDBClosing() {
return &client.LabelNamesResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.LabelNamesResponse{}, nil
Expand Down Expand Up @@ -1157,6 +1173,10 @@ func (i *Ingester) v2MetricsForLabelMatchers(ctx context.Context, req *client.Me
return nil, err
}

if i.checkIfAllTSDBClosing() {
return &client.MetricsForLabelMatchersResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.MetricsForLabelMatchersResponse{}, nil
Expand Down Expand Up @@ -1224,6 +1244,10 @@ func (i *Ingester) v2UserStats(ctx context.Context, req *client.UserStatsRequest
return nil, err
}

if i.checkIfAllTSDBClosing() {
return &client.UserStatsResponse{}, nil
}

db := i.getTSDB(userID)
if db == nil {
return &client.UserStatsResponse{}, nil
Expand All @@ -1236,6 +1260,10 @@ func (i *Ingester) v2AllUserStats(ctx context.Context, req *client.UserStatsRequ
i.userStatesMtx.RLock()
defer i.userStatesMtx.RUnlock()

if i.checkIfAllTSDBClosing() {
return &client.UsersStatsResponse{}, nil
}

users := i.TSDBState.dbs

response := &client.UsersStatsResponse{
Expand Down Expand Up @@ -1280,6 +1308,10 @@ func (i *Ingester) v2QueryStream(req *client.QueryRequest, stream client.Ingeste

i.metrics.queries.Inc()

if i.checkIfAllTSDBClosing() {
return nil
}

db := i.getTSDB(userID)
if db == nil {
return nil
Expand Down Expand Up @@ -1787,6 +1819,11 @@ func (i *Ingester) getMemorySeriesMetric() float64 {
defer i.userStatesMtx.RUnlock()

count := uint64(0)

if i.checkIfAllTSDBClosing() {
return 0
}

for _, db := range i.TSDBState.dbs {
count += db.Head().NumSeries()
}
Expand Down Expand Up @@ -2245,3 +2282,11 @@ func (i *Ingester) getInstanceLimits() *InstanceLimits {

return l
}

func (i *Ingester) checkIfAllTSDBClosing() bool {
ilangofman marked this conversation as resolved.
Show resolved Hide resolved
if i.State() == services.Stopping {
level.Debug(i.logger).Log("msg", "TSDB is unavailable, as the Ingester is in the process of stopping and closing all TSDB")
return true
}
return false
}