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

Allow coordinator to serve multiple clients #597

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 22 additions & 2 deletions coordinator/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
"github.com/pg-sharding/spqr/coordinator/provider"
"github.com/pg-sharding/spqr/pkg/config"
protos "github.com/pg-sharding/spqr/pkg/protos"

"golang.org/x/sync/semaphore"
)

type App struct {
coordinator coordinator.Coordinator
sem *semaphore.Weighted
}

const (
maxWorkers = 50
)

func NewApp(c coordinator.Coordinator) *App {
return &App{
coordinator: c,
sem: semaphore.NewWeighted(int64(maxWorkers)),
}
}

Expand Down Expand Up @@ -83,8 +91,20 @@

for {
conn, err := listener.Accept()
spqrlog.Zero.Error().Err(err).Msg("")
_ = app.coordinator.ProcClient(context.TODO(), conn)
if err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
}

app.sem.Acquire(context.Background(), 1)

Check failure on line 98 in coordinator/app/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.sem.Acquire` is not checked (errcheck)

Check failure on line 98 in coordinator/app/app.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `app.sem.Acquire` is not checked (errcheck)

go func() {
defer app.sem.Release(1)

err := app.coordinator.ProcClient(context.TODO(), conn)
if err != nil {
spqrlog.Zero.Error().Err(err).Msg("failed to serve client")
}
}()
}
}(l)
}
Expand Down
2 changes: 1 addition & 1 deletion qdb/etcdqdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const (
)

func keyLockPath(key string) string {
return path.Join("lock", key)
return path.Join("/lock", key)
}

func keyRangeNodePath(key string) string {
Expand Down
1 change: 1 addition & 0 deletions qdb/memqdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func (q *MemQDB) UpdateCoordinator(ctx context.Context, address string) error {
}

func (q *MemQDB) GetCoordinator(ctx context.Context) (string, error) {
spqrlog.Zero.Debug().Str("address", q.Coordinator).Msg("memqdb: get coordinator address")
return q.Coordinator, nil
}

Expand Down
Loading