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

initial v3 demo #3248

Merged
merged 7 commits into from
Aug 10, 2015
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions Documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ Follow the instructions when using these flags.
+ Force to create a new one-member cluster. It commits configuration changes in force to remove all existing members in the cluster and add itself. It needs to be set to [restore a backup][restore].
+ default: false

### Experimental Flags

##### -experimental-v3demo
+ Enable experimental v3 demo API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a link to docs

+ default: false

### Miscellaneous Flags

##### -version
Expand Down
5 changes: 5 additions & 0 deletions etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ type config struct {

printVersion bool

v3demo bool

ignored []string
}

Expand Down Expand Up @@ -208,6 +210,9 @@ func NewConfig() *config {
// version
fs.BoolVar(&cfg.printVersion, "version", false, "Print the version and exit")

// demo flag
fs.BoolVar(&cfg.v3demo, "experimental-v3demo", false, "Enable experimental v3 demo API")

// backwards-compatibility with v0.4.6
fs.Var(&flags.IPAddressPort{}, "addr", "DEPRECATED: Use -advertise-client-urls instead.")
fs.Var(&flags.IPAddressPort{}, "bind-addr", "DEPRECATED: Use -listen-client-urls instead.")
Expand Down
21 changes: 21 additions & 0 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ import (
systemdutil "github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-systemd/util"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
"github.com/coreos/etcd/discovery"
"github.com/coreos/etcd/etcdserver"
"github.com/coreos/etcd/etcdserver/api/v3rpc"
"github.com/coreos/etcd/etcdserver/etcdhttp"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/pkg/cors"
"github.com/coreos/etcd/pkg/fileutil"
"github.com/coreos/etcd/pkg/osutil"
Expand Down Expand Up @@ -233,6 +236,15 @@ func startEtcd(cfg *config) (<-chan struct{}, error) {
clns = append(clns, l)
}

var v3l net.Listener
if cfg.v3demo {
v3l, err = net.Listen("tcp", "127.0.0.1:12379")
if err != nil {
plog.Fatal(err)
}
plog.Infof("listening for client rpc on 127.0.0.1:12379")
}

srvcfg := &etcdserver.ServerConfig{
Name: cfg.name,
ClientURLs: cfg.acurls,
Expand All @@ -250,6 +262,7 @@ func startEtcd(cfg *config) (<-chan struct{}, error) {
Transport: pt,
TickMs: cfg.TickMs,
ElectionTicks: cfg.electionTicks(),
V3demo: cfg.v3demo,
}
var s *etcdserver.EtcdServer
s, err = etcdserver.NewServer(srvcfg)
Expand Down Expand Up @@ -281,6 +294,14 @@ func startEtcd(cfg *config) (<-chan struct{}, error) {
plog.Fatal(serveHTTP(l, ch, 0))
}(l)
}

if cfg.v3demo {
// set up v3 demo rpc
grpcServer := grpc.NewServer()
etcdserverpb.RegisterEtcdServer(grpcServer, v3rpc.New(s))
go plog.Fatal(grpcServer.Serve(v3l))
}

return s.StopNotify(), nil
}

Expand Down
6 changes: 6 additions & 0 deletions etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,11 @@ given by the consensus protocol.

--force-new-cluster 'false'
force to create a new one-member cluster.


experimental flags:

--experimental-v3demo 'false'
enable experimental v3 demo API
`
)
54 changes: 54 additions & 0 deletions etcdserver/api/v3rpc/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v3rpc

import (
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/etcdserver"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
)

type handler struct {
server etcdserver.V3DemoServer
}

func New(s etcdserver.V3DemoServer) pb.EtcdServer {
return &handler{s}
}

func (h *handler) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) {
resp := h.server.V3DemoDo(ctx, pb.InternalRaftRequest{Range: r})
return resp.(*pb.RangeResponse), nil
}

func (h *handler) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) {
resp := h.server.V3DemoDo(ctx, pb.InternalRaftRequest{Put: r})
return resp.(*pb.PutResponse), nil
}

func (h *handler) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) {
resp := h.server.V3DemoDo(ctx, pb.InternalRaftRequest{DeleteRange: r})
return resp.(*pb.DeleteRangeResponse), nil
}

func (h *handler) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) {
panic("not implemented")
return nil, nil
}

func (h *handler) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) {
panic("not implemented")
return nil, nil
}
2 changes: 2 additions & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type ServerConfig struct {

TickMs uint
ElectionTicks int

V3demo bool
}

// VerifyBootstrapConfig sanity-checks the initial config for bootstrap case
Expand Down
143 changes: 1 addition & 142 deletions etcdserver/etcdserverpb/etcdserver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions etcdserver/etcdserverpb/etcdserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,3 @@ message Metadata {
optional uint64 NodeID = 1 [(gogoproto.nullable) = false];
optional uint64 ClusterID = 2 [(gogoproto.nullable) = false];
}

// An InternalRaftRequest is the union of all requests which can be
// sent via raft.
message InternalRaftRequest {
option (gogoproto.onlyone) = true;
oneof value {
Request v2 = 1;
}
}
Loading