Skip to content

Commit

Permalink
More godoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KalyanAkella committed Feb 6, 2020
1 parent dc2a806 commit de2e487
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
8 changes: 4 additions & 4 deletions cmd/dkvsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func newKVStore() storage.KVStore {
}

func newDKVReplicator(kvs storage.KVStore) nexus_api.RaftReplicator {
repl_store := sync.NewDKVReplStore(kvs)
if nexus_repl, err := nexus_api.NewRaftReplicator(repl_store, nexus.OptionsFromFlags()...); err != nil {
replStore := sync.NewDKVReplStore(kvs)
if nexusRepl, err := nexus_api.NewRaftReplicator(replStore, nexus.OptionsFromFlags()...); err != nil {
panic(err)
} else {
nexus_repl.Start()
return nexus_repl
nexusRepl.Start()
return nexusRepl
}
}
11 changes: 11 additions & 0 deletions internal/ctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"google.golang.org/grpc"
)

// A DKVClient instance used to communicate with DKV service
// over GRPC.
type DKVClient struct {
cliConn *grpc.ClientConn
dkvCli serverpb.DKVClient
Expand All @@ -21,6 +23,8 @@ const (
Timeout = 1 * time.Second
)

// NewInSecureDKVClient creates an insecure GRPC client against the
// given DKV service address.
func NewInSecureDKVClient(svcAddr string) (*DKVClient, error) {
if conn, err := grpc.Dial(svcAddr, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithReadBufferSize(ReadBufSize), grpc.WithWriteBufferSize(WriteBufSize)); err != nil {
return nil, err
Expand All @@ -30,6 +34,8 @@ func NewInSecureDKVClient(svcAddr string) (*DKVClient, error) {
}
}

// Put takes the key and value as byte arrays and invokes the
// GRPC Put method. This is a convenience wrapper.
func (dkvClnt *DKVClient) Put(key []byte, value []byte) error {
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()
Expand All @@ -44,13 +50,17 @@ func (dkvClnt *DKVClient) Put(key []byte, value []byte) error {
return nil
}

// Get takes the key as byte array and invokes the
// GRPC Get method. This is a convenience wrapper.
func (dkvClnt *DKVClient) Get(key []byte) (*serverpb.GetResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()
getReq := &serverpb.GetRequest{Key: key}
return dkvClnt.dkvCli.Get(ctx, getReq)
}

// MultiGet takes the keys as byte arrays and invokes the
// GRPC MultiGet method. This is a convenience wrapper.
func (dkvClnt *DKVClient) MultiGet(keys ...[]byte) ([]*serverpb.GetResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()
Expand All @@ -63,6 +73,7 @@ func (dkvClnt *DKVClient) MultiGet(keys ...[]byte) ([]*serverpb.GetResponse, err
return res.GetResponses, err
}

// Close closes the underlying GRPC client connection to DKV service
func (dkvClnt *DKVClient) Close() error {
return dkvClnt.cliConn.Close()
}
8 changes: 4 additions & 4 deletions internal/server/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type standaloneService struct {
store storage.KVStore
}

// Creates a standalone variant of the DKVService that works only with
// the local storage.
// NewStandaloneService creates a standalone variant of the DKVService
// that works only with the local storage.
func NewStandaloneService(store storage.KVStore) *standaloneService {
return &standaloneService{store}
}
Expand Down Expand Up @@ -71,8 +71,8 @@ type distributedService struct {
raftRepl nexus_api.RaftReplicator
}

// Creates a distributed variant of the DKV service that attempts to
// replicate data across multiple replicas over Nexus.
// NewDistributedService creates a distributed variant of the DKV service
// that attempts to replicate data across multiple replicas over Nexus.
func NewDistributedService(kvs storage.KVStore, raftRepl nexus_api.RaftReplicator) *distributedService {
return &distributedService{NewStandaloneService(kvs), raftRepl}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/server/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package storage

import "io"

// Generic result that holds the error if available
// from the storage implementation.
// A Result instance holds the error if available from the
// storage implementation.
type Result struct {
Error error
}

// Result of a read from the storage implementation.
// A ReadResult instance of a read from the storage implementation.
type ReadResult struct {
*Result
Value []byte
}

// Creates a ReadResult with the given value.
// NewReadResultWithValue creates a ReadResult with the given value.
func NewReadResultWithValue(val []byte) *ReadResult {
return &ReadResult{&Result{Error: nil}, val}
}

// Creates a ReadResult with the given error.
// NewReadResultWithError creates a ReadResult with the given error.
func NewReadResultWithError(err error) *ReadResult {
return &ReadResult{&Result{Error: err}, nil}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/sync/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type dkvReplStore struct {
kvs storage.KVStore
}

// Creates a wrapper around the given KVStore instance
// NewDKVReplStore creates a wrapper out of the given KVStore
// that performs synchronous replication of all operations
// over Nexus onto multiple replicas.
func NewDKVReplStore(kvs storage.KVStore) *dkvReplStore {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package version

var (
// Holds the latest version of the DKV binary
// Version holds the latest version of the DKV binary
Version = "latest"
)

0 comments on commit de2e487

Please sign in to comment.