-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/proto creation #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
1fdd213
71f45ec
6572893
c64ffd8
bc8fec5
b35b2aa
a18f159
55da8e1
d61c836
50c8f8f
027caf6
d662385
84cbf98
7bec086
7640b24
aa4a4c7
0d32ff4
94a05ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| /vendor | ||
| /vendor | ||
| __pycache__/ | ||
| /dion-env | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package clientwithoutinternode; | ||
|
|
||
| message GetRequest { | ||
| string key = 1; | ||
| } | ||
|
|
||
| message GetResponse { | ||
| string value = 1; | ||
| } | ||
|
|
||
| message PutRequest { | ||
| string key = 1; | ||
| string value = 2; | ||
| } | ||
|
|
||
| message PutResponse { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should return key and value back to user as well |
||
| bool success = 1; | ||
| } | ||
|
|
||
| service KeyValueService { | ||
| rpc Get(GetRequest) returns (GetResponse); | ||
| rpc Put(PutRequest) returns (PutResponse); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sixletters/simple-db/pkg/storage" | ||
| "sixletters/simple-db/pkg/tree" | ||
| "sixletters/simple-db/pkg/stubs" | ||
| ) | ||
|
|
||
| type grpcServer struct{ | ||
| storageEngine storage.StorageEngine | ||
| } | ||
|
|
||
| func NewGrpcServer() *grpcServer { | ||
| newStorageConfig := storage.NewConfigWithOpts( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see how its done in the http server, you dont build a new storage engine everytime, its a singleton that is shared between all servers, not an instance that is instantiated everytime |
||
| storage.WithTreeType(tree.BTree), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see how its done in http server, all these are abstracted from the grpc server |
||
| storage.WithFilePath("testFile.txt"), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is taken in as a flag |
||
| ) | ||
| storageEngine, err := storage.NewSingletonEngine(newStorageConfig) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return &grpcServer{ | ||
| storageEngine: storageEngine, | ||
| } | ||
| } | ||
|
|
||
| func (s *grpcServer) Get(ctx context.Context, req *stubs.GetRequest) (*stubs.GetResponse, error) { | ||
| res, err := s.storageEngine.Get(context.Background(), req.Key) | ||
| if err != nil { | ||
| fmt.Print(err.Error()) | ||
| return nil, err | ||
| } | ||
| return &stubs.GetResponse{Value: res}, nil | ||
| } | ||
|
|
||
| func (s *grpcServer) Put(ctx context.Context, req *stubs.PutRequest) (*stubs.PutResponse, error) { | ||
| err := s.storageEngine.Put(context.Background(), req.Key, req.Value) | ||
| if err != nil { | ||
| fmt.Print(err.Error()) | ||
| return &stubs.PutResponse{Success: false}, err | ||
| } | ||
| return &stubs.PutResponse{Success: true}, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package storage | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this file added again |
||
| import "context" | ||
|
|
||
| type StorageEngine interface { | ||
| Put(ctx context.Context, key string, value string) error | ||
| Get(ctx context.Context, key string) (string, error) | ||
| } | ||
|
|
||
| type storageEngine struct { | ||
| } | ||
|
|
||
| func NewStorageEngine() StorageEngine { | ||
| return &storageEngine{} | ||
| } | ||
|
|
||
| func (s *storageEngine) Put(ctx context.Context, key string, value string) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (s *storageEngine) Get(ctx context.Context, key string) (string, error) { | ||
| return "", nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return the key back to user as well