Skip to content

Commit

Permalink
Merge branch 'main' into korniltsev/compactor_concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev authored Oct 15, 2024
2 parents 248dea8 + 596641b commit c1fc040
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 152 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ $(BIN)/mockery: Makefile go.mod

$(BIN)/updater: Makefile
@mkdir -p $(@D)
GOBIN=$(abspath $(@D)) GOPRIVATE=github.com/grafana/deployment_tools $(GO) install github.com/grafana/deployment_tools/drone/plugins/cmd/updater@d64d509
GOBIN=$(abspath $(@D)) GOPRIVATE=github.com/grafana/deployment_tools $(GO) install github.com/grafana/deployment_tools/docker/updater/cmd/updater@bd5794b4e488

# Note: When updating the goreleaser version also update .github/workflow/release.yml and .git/workflow/weekly-release.yaml
$(BIN)/goreleaser: Makefile go.mod
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ To start contributing, check out our [Contributing Guide](docs/internal/contribu
<a href="https://github.com/pavelpashkovsky"><img src="https://avatars.githubusercontent.com/u/7372044?v=4" title="pavelpashkovsky" width="80" height="80"></a>
<a href="https://github.com/bryanhuhta"><img src="https://avatars.githubusercontent.com/u/32787160?v=4" title="bryanhuhta" width="80" height="80"></a>
<a href="https://github.com/Rustin170506"><img src="https://avatars.githubusercontent.com/u/29879298?v=4" title="Rustin170506" width="80" height="80"></a>
<a href="https://github.com/LouisInFlow"><img src="https://avatars.githubusercontent.com/u/84481279?v=4" title="LouisInFlow" width="80" height="80"></a>
<a href="https://github.com/darrenjaneczek"><img src="https://avatars.githubusercontent.com/u/38694490?v=4" title="darrenjaneczek" width="80" height="80"></a>
<a href="https://github.com/LouisInFlow"><img src="https://avatars.githubusercontent.com/u/84481279?v=4" title="LouisInFlow" width="80" height="80"></a>
<a href="https://github.com/knylander-grafana"><img src="https://avatars.githubusercontent.com/u/104772500?v=4" title="knylander-grafana" width="80" height="80"></a>
<a href="https://github.com/jdbaldry"><img src="https://avatars.githubusercontent.com/u/4599384?v=4" title="jdbaldry" width="80" height="80"></a>
<a href="https://github.com/shaleynikov"><img src="https://avatars.githubusercontent.com/u/8720058?v=4" title="shaleynikov" width="80" height="80"></a>
Expand All @@ -190,23 +190,23 @@ To start contributing, check out our [Contributing Guide](docs/internal/contribu
<a href="https://github.com/cristiangreco"><img src="https://avatars.githubusercontent.com/u/316923?v=4" title="cristiangreco" width="80" height="80"></a>
<a href="https://github.com/cjsampson"><img src="https://avatars.githubusercontent.com/u/8391857?v=4" title="cjsampson" width="80" height="80"></a>
<a href="https://github.com/RichiH"><img src="https://avatars.githubusercontent.com/u/754723?v=4" title="RichiH" width="80" height="80"></a>
<a href="https://github.com/marcsanmi"><img src="https://avatars.githubusercontent.com/u/8235696?v=4" title="marcsanmi" width="80" height="80"></a>
<a href="https://github.com/ekpatrice"><img src="https://avatars.githubusercontent.com/u/77462462?v=4" title="ekpatrice" width="80" height="80"></a>
<a href="https://github.com/robbymilo"><img src="https://avatars.githubusercontent.com/u/8106669?v=4" title="robbymilo" width="80" height="80"></a>
<a href="https://github.com/gawicks"><img src="https://avatars.githubusercontent.com/u/1481491?v=4" title="gawicks" width="80" height="80"></a>
<a href="https://github.com/marcsanmi"><img src="https://avatars.githubusercontent.com/u/8235696?v=4" title="marcsanmi" width="80" height="80"></a>
<a href="https://github.com/StasDachinsky"><img src="https://avatars.githubusercontent.com/u/23450818?v=4" title="StasDachinsky" width="80" height="80"></a>
<a href="https://github.com/ruslanpascoal2"><img src="https://avatars.githubusercontent.com/u/61955096?v=4" title="ruslanpascoal2" width="80" height="80"></a>
<a href="https://github.com/StasDachinsky"><img src="https://avatars.githubusercontent.com/u/23450818?v=4" title="StasDachinsky" width="80" height="80"></a>
<a href="https://github.com/gawicks"><img src="https://avatars.githubusercontent.com/u/1481491?v=4" title="gawicks" width="80" height="80"></a>
<a href="https://github.com/scottzhlin"><img src="https://avatars.githubusercontent.com/u/37504582?v=4" title="scottzhlin" width="80" height="80"></a>
<a href="https://github.com/alsoba13"><img src="https://avatars.githubusercontent.com/u/3586560?v=4" title="alsoba13" width="80" height="80"></a>
<a href="https://github.com/omarabid"><img src="https://avatars.githubusercontent.com/u/909237?v=4" title="omarabid" width="80" height="80"></a>
<a href="https://github.com/cstyan"><img src="https://avatars.githubusercontent.com/u/3246492?v=4" title="cstyan" width="80" height="80"></a>
<a href="https://github.com/EgorMozheiko"><img src="https://avatars.githubusercontent.com/u/90687109?v=4" title="EgorMozheiko" width="80" height="80"></a>
<a href="https://github.com/cmonez"><img src="https://avatars.githubusercontent.com/u/39146411?v=4" title="cmonez" width="80" height="80"></a>
<a href="https://github.com/nlamirault"><img src="https://avatars.githubusercontent.com/u/29233?v=4" title="nlamirault" width="80" height="80"></a>
<a href="https://github.com/rajat2004"><img src="https://avatars.githubusercontent.com/u/37938604?v=4" title="rajat2004" width="80" height="80"></a>
<a href="https://github.com/wilfriedroset"><img src="https://avatars.githubusercontent.com/u/12611310?v=4" title="wilfriedroset" width="80" height="80"></a>
<a href="https://github.com/cuishuang"><img src="https://avatars.githubusercontent.com/u/15921519?v=4" title="cuishuang" width="80" height="80"></a>
<a href="https://github.com/Skemba"><img src="https://avatars.githubusercontent.com/u/8813875?v=4" title="Skemba" width="80" height="80"></a>
<a href="https://github.com/cuishuang"><img src="https://avatars.githubusercontent.com/u/15921519?v=4" title="cuishuang" width="80" height="80"></a>
<a href="https://github.com/wilfriedroset"><img src="https://avatars.githubusercontent.com/u/12611310?v=4" title="wilfriedroset" width="80" height="80"></a>
<a href="https://github.com/rajat2004"><img src="https://avatars.githubusercontent.com/u/37938604?v=4" title="rajat2004" width="80" height="80"></a>
<a href="https://github.com/nlamirault"><img src="https://avatars.githubusercontent.com/u/29233?v=4" title="nlamirault" width="80" height="80"></a>
<a href="https://github.com/cmonez"><img src="https://avatars.githubusercontent.com/u/39146411?v=4" title="cmonez" width="80" height="80"></a>
<a href="https://github.com/EgorMozheiko"><img src="https://avatars.githubusercontent.com/u/90687109?v=4" title="EgorMozheiko" width="80" height="80"></a>
<a href="https://github.com/cstyan"><img src="https://avatars.githubusercontent.com/u/3246492?v=4" title="cstyan" width="80" height="80"></a>
<a href="https://github.com/QuantumEnigmaa"><img src="https://avatars.githubusercontent.com/u/64951262?v=4" title="QuantumEnigmaa" width="80" height="80"></a>
<a href="https://github.com/Pranay0302"><img src="https://avatars.githubusercontent.com/u/55592629?v=4" title="Pranay0302" width="80" height="80"></a>
<a href="https://github.com/juliosaraiva"><img src="https://avatars.githubusercontent.com/u/6595701?v=4" title="juliosaraiva" width="80" height="80"></a>
Expand Down
12 changes: 6 additions & 6 deletions pkg/experiment/metastore/metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"flag"
"fmt"

"net"
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/go-kit/log"
Expand Down Expand Up @@ -40,8 +40,6 @@ const (
raftTrailingLogs = 18 << 10
raftSnapshotInterval = 180 * time.Second
raftSnapshotThreshold = 8 << 10

metastoreRaftLeaderHealthServiceName = "metastore.v1.MetastoreService.RaftLeader"
)

type Config struct {
Expand Down Expand Up @@ -135,8 +133,10 @@ type Metastore struct {

walDir string

metrics *metastoreMetrics
client *metastoreclient.Client
metrics *metastoreMetrics
client *metastoreclient.Client

readyOnce sync.Once
readySince time.Time

dnsProvider *dns.Provider
Expand Down Expand Up @@ -174,7 +174,7 @@ func (m *Metastore) Shutdown() error {
return nil
}

func (m *Metastore) starting(ctx context.Context) error {
func (m *Metastore) starting(context.Context) error {
if err := m.db.open(false); err != nil {
return fmt.Errorf("failed to initialize database: %w", err)
}
Expand Down
62 changes: 62 additions & 0 deletions pkg/experiment/metastore/metastore_read_index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package metastore

import (
"context"
"fmt"
"time"

metastorev1 "github.com/grafana/pyroscope/api/gen/proto/go/metastore/v1"
)

// ReadIndex returns the current commit index and verifies leadership.
func (m *Metastore) ReadIndex(context.Context, *metastorev1.ReadIndexRequest) (*metastorev1.ReadIndexResponse, error) {
commitIndex := m.raft.CommitIndex()
if err := m.raft.VerifyLeader().Error(); err != nil {
return nil, wrapRetryableErrorWithRaftDetails(err, m.raft)
}
return &metastorev1.ReadIndexResponse{ReadIndex: commitIndex}, nil
}

// waitLeaderCommitIndexAppliedLocally ensures the node is up-to-date for read operations,
// providing linearizable read semantics. It calls metastore client ReadIndex
// and waits for the local applied index to catch up to the returned read index.
// This method should be used before performing local reads to ensure consistency.
func (m *Metastore) waitLeaderCommitIndexAppliedLocally(ctx context.Context) error {
r, err := m.client.ReadIndex(ctx, &metastorev1.ReadIndexRequest{})
if err != nil {
return err
}
if m.raft.AppliedIndex() >= r.ReadIndex {
return nil
}

t := time.NewTicker(10 * time.Millisecond)
defer t.Stop()

// Wait for the read index to be applied
for {
select {
case <-t.C:
if m.raft.AppliedIndex() >= r.ReadIndex {
return nil
}
case <-ctx.Done():
return ctx.Err()
}
}
}

// CheckReady verifies if the metastore is ready to serve requests by
// ensuring the node is up-to-date with the leader's commit index.
func (m *Metastore) CheckReady(ctx context.Context) error {
if err := m.waitLeaderCommitIndexAppliedLocally(ctx); err != nil {
return err
}
m.readyOnce.Do(func() {
m.readySince = time.Now()
})
if w := m.config.MinReadyDuration - time.Since(m.readySince); w > 0 {
return fmt.Errorf("%v before reporting readiness", w)
}
return nil
}
132 changes: 0 additions & 132 deletions pkg/experiment/metastore/metastore_readindex.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"math"
"sync"

"github.com/go-kit/log/level"

metastorev1 "github.com/grafana/pyroscope/api/gen/proto/go/metastore/v1"
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1"
"github.com/grafana/pyroscope/pkg/experiment/metastore/index"
Expand All @@ -14,7 +16,10 @@ func (m *Metastore) GetProfileStats(
ctx context.Context,
r *metastorev1.GetProfileStatsRequest,
) (*typesv1.GetProfileStatsResponse, error) {
// TODO(kolesnikovae): ReadIndex
if err := m.waitLeaderCommitIndexAppliedLocally(ctx); err != nil {
level.Error(m.logger).Log("msg", "failed to wait for leader commit index", "err", err)
return nil, err
}
return m.state.getProfileStats(r.TenantId, ctx)
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/experiment/metastore/metastore_state_query_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func (m *Metastore) QueryMetadata(
ctx context.Context,
request *metastorev1.QueryMetadataRequest,
) (*metastorev1.QueryMetadataResponse, error) {
// TODO(kolesnikovae): ReadIndex
if err := m.waitLeaderCommitIndexAppliedLocally(ctx); err != nil {
level.Error(m.logger).Log("msg", "failed to wait for leader commit index", "err", err)
return nil, err
}
return m.state.listBlocksForQuery(ctx, request)
}

Expand Down

0 comments on commit c1fc040

Please sign in to comment.