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

feat: multi-raft #2

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 25 additions & 6 deletions cmd/store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@
package main

import (
// standard libraries.
"context"
"fmt"
"net"
"os"
"time"

// third-party libraries.
"google.golang.org/grpc"

// first-party libraries.
raftpb "github.com/linkall-labs/vsproto/pkg/raft"
segpb "github.com/linkall-labs/vsproto/pkg/segment"

// this project.
"github.com/linkall-labs/vanus/internal/primitive"
"github.com/linkall-labs/vanus/internal/raft/transport"
"github.com/linkall-labs/vanus/internal/store/segment"
"github.com/linkall-labs/vanus/internal/util"
"github.com/linkall-labs/vanus/observability/log"
segpb "github.com/linkall-labs/vsproto/pkg/segment"
"google.golang.org/grpc"
"net"
"os"
"time"
)

var (
Expand All @@ -51,6 +60,13 @@ func main() {
grpcServer.GracefulStop()
exitChan <- struct{}{}
}

// setup raft
reslover := transport.NewSimpleResolver()
host := transport.NewHost(reslover)
raftSrv := transport.NewRaftServer(context.TODO(), host)
raftpb.RegisterRaftServerServer(grpcServer, raftSrv)

srv := segment.NewSegmentServer("127.0.0.1:11811", defaultControllerAddr,
"volume-1", stopCallback)
if err != nil {
Expand All @@ -60,6 +76,8 @@ func main() {
})
os.Exit(-1)
}
segpb.RegisterSegmentServerServer(grpcServer, srv)

ctx := context.Background()
init, _ := srv.(primitive.Initializer)
// TODO panic
Expand All @@ -70,17 +88,18 @@ func main() {
})
os.Exit(-2)
}

go func() {
log.Info(ctx, "the SegmentServer ready to work", map[string]interface{}{
"listen_ip": defaultIP,
"listen_port": defaultPort,
"time": util.FormatTime(time.Now()),
})
segpb.RegisterSegmentServerServer(grpcServer, srv)
if err = grpcServer.Serve(listen); err != nil {
log.Error(ctx, "grpc server occurred an error", map[string]interface{}{
log.KeyError: err,
})
return
}
}()

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/huandu/skiplist v1.2.0
github.com/linkall-labs/embed-etcd v0.0.0
github.com/linkall-labs/eventbus-go v0.0.0
github.com/linkall-labs/raft v0.0.0
github.com/linkall-labs/vsproto v0.0.0
github.com/pkg/errors v0.9.1
github.com/prashantv/gostub v1.1.0
Expand All @@ -31,6 +32,7 @@ replace (
cloudevents.io/genproto v1.0.2 => ../vsproto/include/cloudevents/pkg
github.com/linkall-labs/embed-etcd v0.0.0 => ../embed-etcd
github.com/linkall-labs/eventbus-go v0.0.0 => ../eventbus-go
github.com/linkall-labs/raft v0.0.0 => ../raft
github.com/linkall-labs/vsproto v0.0.0 => ../vsproto
)

Expand Down Expand Up @@ -67,7 +69,7 @@ require (
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/api/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0 // indirect
go.etcd.io/etcd/client/v2 v2.305.2 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.2 // indirect
go.etcd.io/etcd/raft/v3 v3.5.2 // indirect
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
go.etcd.io/etcd/api/v3 v3.5.2 h1:tXok5yLlKyuQ/SXSjtqHc4uzNaMqZi2XsoSPr/LlJXI=
go.etcd.io/etcd/api/v3 v3.5.2/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
go.etcd.io/etcd/client/pkg/v3 v3.5.2 h1:4hzqQ6hIb3blLyQ8usCU4h3NghkqcsohEQ3o3VetYxE=
go.etcd.io/etcd/client/pkg/v3 v3.5.2/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0 h1:2UyRzFWbZZzgu/xzxoRukgixvafiJtGyxO+3IKUyJ6c=
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0/go.mod h1:Vl/FkH40bHqmBFwhr8WVKtV47neyts36zl1voccRq8s=
go.etcd.io/etcd/client/v2 v2.305.2 h1:ymrVwTkefuqA/rPkSW7/B4ApijbPVefRumkY+stNfS0=
go.etcd.io/etcd/client/v2 v2.305.2/go.mod h1:2D7ZejHVMIfog1221iLSYlQRzrtECw3kz4I4VAQm3qI=
go.etcd.io/etcd/client/v3 v3.5.2 h1:WdnejrUtQC4nCxK0/dLTMqKOB+U5TP/2Ya0BJL+1otA=
Expand Down Expand Up @@ -680,6 +681,7 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
Loading