Skip to content

Commit

Permalink
del tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
vadiminshakov committed Dec 21, 2023
1 parent 5c814fd commit 73efa2d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 83 deletions.
25 changes: 2 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,18 @@ prepare:

run-example-coordinator:
@rm -rf ./badger/coordinator
@go run . -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=./badger/coordinator -whitelist=127.0.0.1 -withtrace=true
@go run . -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=./badger/coordinator -whitelist=127.0.0.1

run-example-follower:
@rm -rf ./badger/follower
@go run . -role=follower -coordinator=localhost:3000 -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=./badger/follower -whitelist=127.0.0.1 -withtrace=true
@go run . -role=follower -coordinator=localhost:3000 -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=./badger/follower -whitelist=127.0.0.1

run-example-client:
@go run ./examples/client

show-trace: start-zipkin show-trace-coordinator show-trace-follower1 show-trace-follower2 show-trace-follower3 show-trace-client

start-zipkin:
docker rm -f zipkin
docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin
show-trace-coordinator:
rm -rf ./badger/coordinator
go run . -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001,localhost:3002,localhost:3003 -committype=three-phase -timeout=1000 -dbpath=./badger/coordinator -whitelist=127.0.0.1 -withtrace=true
show-trace-follower1:
sleep 2
rm -rf ./badger/follower1
go run . -role=follower -coordinator=localhost:3000 -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=./badger/follower1 -whitelist=127.0.0.1 -withtrace=true
show-trace-follower2:
sleep 2
rm -rf ./badger/follower2
go run . -role=follower -coordinator=localhost:3000 -nodeaddr=localhost:3002 -committype=three-phase -timeout=1000 -dbpath=./badger/follower2 -whitelist=127.0.0.1 -withtrace=true
show-trace-follower3:
sleep 2
rm -rf ./badger/follower3
go run . -role=follower -coordinator=localhost:3000 -nodeaddr=localhost:3003 -committype=three-phase -timeout=1000 -dbpath=./badger/follower3 -whitelist=127.0.0.1 -withtrace=true
show-trace-client:
sleep 5
go run ./examples/client
echo "please open http://localhost:9411/zipkin/dependency"

tests:
@/usr/local/go/bin/go test ./...
Expand Down
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ All config parameters may be specified via command-line flags

example **follower**:
```
./committer -withtrace=false -role=follower -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/follower
./committer -role=follower -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/follower
```

example **coordinator**:
```
./committer -withtrace=false -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/coordinator
./committer -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/coordinator
```

<br>
Expand All @@ -56,20 +56,6 @@ Example hooks can be found at [hooks/src/hooks.go](https://github.com/vadiminsha

You can replace code in the [hooks/src/hooks.go](https://github.com/vadiminshakov/committer/blob/master/core/algorithm/hooks/src/hooks.go) file used by committer to inject your validation logic into the handlers.

**Tracing**

Start Zipkin:

```
docker run -d -p 9411:9411 openzipkin/zipkin
```

Set `--withtrace true` command-line flag or `withtrace: true` config option in config file _before starting committer_.

Start committer, open [http://localhost:9411/zipkin](http://localhost:9411/zipkin)

<br>

**Testing**

functional tests: `make tests`
Expand Down
4 changes: 1 addition & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Config struct {
Followers []string
Whitelist []string
Timeout uint64
WithTrace bool
}

type followers []string
Expand Down Expand Up @@ -48,7 +47,6 @@ func Get() *Config {
committype := flag.String("committype", "two-phase", "two-phase or three-phase commit mode")
timeout := flag.Uint64("timeout", 1000, "ms, timeout after which the message is considered unacknowledged (only for three-phase mode, because two-phase is blocking by design)")
dbpath := flag.String("dbpath", "./badger", "database path on filesystem")
withTrace := flag.Bool("withtrace", false, "use distributed tracer or not (true/false)")
followers := flag.String("followers", "", "follower's addresses")
whitelist := flag.String("whitelist", "127.0.0.1", "allowed hosts")
flag.Parse()
Expand All @@ -62,7 +60,7 @@ func Get() *Config {
whitelistArray := strings.Split(*whitelist, ",")
return &Config{Role: *role, Nodeaddr: *nodeaddr, Coordinator: *coordinator,
CommitType: *committype, DBPath: *dbpath, Followers: followersArray, Whitelist: whitelistArray,
Timeout: *timeout, WithTrace: *withTrace}
Timeout: *timeout}

}

Expand Down
33 changes: 1 addition & 32 deletions core/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package coordinator
import (
"context"
"fmt"
"github.com/openzipkin/zipkin-go"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/vadiminshakov/committer/config"
Expand All @@ -23,7 +22,6 @@ type coordinatorImpl struct {
vlog voteslog.Log
database db.Repository
followers map[string]*client.CommitClient
tracer *zipkin.Tracer
config *config.Config
height uint64
}
Expand All @@ -48,16 +46,6 @@ func New(conf *config.Config, vlog voteslog.Log, database db.Repository) (*coord
}

func (c *coordinatorImpl) Broadcast(ctx context.Context, req dto.BroadcastRequest) (*dto.BroadcastResponse, error) {
var (
err error
span zipkin.Span
)

if c.tracer != nil {
span, ctx = c.tracer.StartSpanFromContext(ctx, "PutHandle")
defer span.Finish()
}

// propose
log.Infof("propose key %s", req.Key)
if err := c.propose(ctx, req); err != nil {
Expand Down Expand Up @@ -90,7 +78,7 @@ func (c *coordinatorImpl) Broadcast(ctx context.Context, req dto.BroadcastReques
if !ok {
return nil, status.Error(codes.Internal, "can't to find msg in the coordinator's cache")
}
if err = c.database.Put(key, value); err != nil {
if err := c.database.Put(key, value); err != nil {
return &dto.BroadcastResponse{Type: dto.ResponseTypeNack}, status.Error(codes.Internal, "failed to save msg on coordinator")
}

Expand All @@ -109,7 +97,6 @@ func (c *coordinatorImpl) propose(ctx context.Context, req dto.BroadcastRequest)
}

votes := make([]*dto.Vote, 0, len(c.followers))
var span zipkin.Span
for nodename, follower := range c.followers {
var (
resp *pb.Response
Expand All @@ -122,9 +109,6 @@ func (c *coordinatorImpl) propose(ctx context.Context, req dto.BroadcastRequest)
Value: req.Value,
CommitType: ctype,
Index: c.height})
if c.tracer != nil && span != nil {
span.Finish()
}
if err != nil {
log.Errorf(err.Error())
isAccepted = false
Expand Down Expand Up @@ -158,17 +142,9 @@ func (c *coordinatorImpl) preCommit(ctx context.Context, req dto.BroadcastReques
return nil
}

var span zipkin.Span
for _, follower := range c.followers {
if c.tracer != nil {
span, ctx = c.tracer.StartSpanFromContext(ctx, "Precommit")
}

votes := votesToProto(c.vlog.GetVotes(c.height))
resp, err := follower.Precommit(ctx, &pb.PrecommitRequest{Index: c.height, Votes: votes})
if c.tracer != nil && span != nil {
span.Finish()
}
if err != nil {
return err
}
Expand Down Expand Up @@ -196,15 +172,8 @@ func (c *coordinatorImpl) preCommit(ctx context.Context, req dto.BroadcastReques
}

func (c *coordinatorImpl) commit(ctx context.Context) error {
var span zipkin.Span
for _, follower := range c.followers {
if c.tracer != nil {
span, ctx = c.tracer.StartSpanFromContext(ctx, "Commit")
}
r, err := follower.Commit(ctx, &pb.CommitRequest{Index: c.height})
if c.tracer != nil && span != nil {
span.Finish()
}
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions io/gateway/grpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/openzipkin/zipkin-go"
"github.com/pkg/errors"
"github.com/vadiminshakov/committer/io/gateway/grpc/proto"
"google.golang.org/grpc"
Expand All @@ -14,7 +13,6 @@ import (

type CommitClient struct {
Connection proto.CommitClient
Tracer *zipkin.Tracer
}

// New creates instance of peer client.
Expand Down
14 changes: 7 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ var (
COORDINATOR_TYPE: {
{Nodeaddr: "localhost:3000", Role: "coordinator",
Followers: []string{"localhost:3001", "localhost:3002", "localhost:3003", "localhost:3004", "localhost:3005"},
Whitelist: whitelist, CommitType: "two-phase", Timeout: 100, WithTrace: false},
Whitelist: whitelist, CommitType: "two-phase", Timeout: 100},
{Nodeaddr: "localhost:5002", Role: "coordinator",
Followers: []string{"localhost:3001", "localhost:3002", "localhost:3003", "localhost:3004", "localhost:3005"},
Whitelist: whitelist, CommitType: "three-phase", Timeout: 100, WithTrace: false},
Whitelist: whitelist, CommitType: "three-phase", Timeout: 100},
},
FOLLOWER_TYPE: {
&config.Config{Nodeaddr: "localhost:3001", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, WithTrace: false, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3002", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, WithTrace: false, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3003", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, WithTrace: false, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3004", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, WithTrace: false, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3005", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, WithTrace: false, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3001", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3002", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3003", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3004", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, CommitType: "three-phase"},
&config.Config{Nodeaddr: "localhost:3005", Role: "follower", Coordinator: "localhost:3000", Whitelist: whitelist, Timeout: 100, CommitType: "three-phase"},
},
}
)
Expand Down

0 comments on commit 73efa2d

Please sign in to comment.