Basic file uploader implemetation. Does not wait for replication to finish.
diff --git a/api/api.proto b/api/api.proto
index 6640afd..6372af3 100644
--- a/api/api.proto
+++ b/api/api.proto
@@ -4,10 +4,17 @@
option go_package = "api";
-message Chunk {
- string chunk_id = 1;
- int32 size_bytes = 2;
- bytes data = 3;
+enum ChunkStatus {
+ NEW = 0;
+ CREATED = 1;
+ WRITING = 2;
+ REPLICATING = 3;
+ READY = 4;
+}
+
+enum ReplicaRole {
+ SECONDARY = 0;
+ PRIMARY = 1;
}
// ChunkStorage
@@ -15,13 +22,17 @@
service ChunkStorage {
rpc ListChunks(ListChunksRequest) returns (ListChunksResponse) {}
+ rpc CreateChunk(CreateChunkRequest) returns (CreateChunkResponse) {}
+
+ rpc GetChunkStatus(GetChunkStatusRequest) returns (GetChunkStatusResponse) {}
+
rpc ReadChunk(ReadChunkRequest) returns (ReadChunkResponse) {}
+ rpc WriteChunk(WriteChunkRequest) returns (WriteChunkResponse) {}
+
rpc StoreChunk(StoreChunkRequest) returns (StoreChunkResponse) {}
rpc RemoveChunk(RemoveChunkRequest) returns (RemoveChunkResponse) {}
-
- rpc ReplicateChunk(ReplicateChunkRequest) returns (ReplicateChunkResponse) {}
}
message ListChunksRequest {
@@ -31,6 +42,26 @@
repeated string chunk_id = 1;
}
+message CreateChunkRequest {
+ string chunk_id = 1;
+ int32 size = 2;
+ ReplicaRole role = 3;
+ string primary_address = 4;
+}
+
+message CreateChunkResponse {
+}
+
+message GetChunkStatusRequest {
+ string chunk_id = 1;
+}
+
+message GetChunkStatusResponse {
+ ChunkStatus status = 1;
+ int32 total_bytes = 2;
+ int32 committed_bytes = 3;
+}
+
message ReadChunkRequest {
string chunk_id = 1;
int32 offset = 2;
@@ -41,6 +72,16 @@
bytes data = 1;
}
+message WriteChunkRequest {
+ string chunk_id = 1;
+ int32 offset = 2;
+ bytes data = 3;
+}
+
+message WriteChunkResponse {
+ int32 bytes_written = 1;
+}
+
message StoreChunkRequest {
string chunk_id = 1;
bytes data = 2;
@@ -56,14 +97,6 @@
message RemoveChunkResponse {
}
-message ReplicateChunkRequest {
- string chunk_id = 1;
- string primary_chunk_server = 2;
-}
-
-message ReplicateChunkResponse {
-}
-
// MetadataStorage
message ChunkStorageMetadata {
diff --git a/api/client.go b/api/client.go
new file mode 100644
index 0000000..3e05de6
--- /dev/null
+++ b/api/client.go
@@ -0,0 +1,12 @@
+package api
+
+import (
+ "google.golang.org/grpc"
+)
+
+func DialConn(address string) (*grpc.ClientConn, error) {
+ var opts []grpc.DialOption
+ opts = append(opts, grpc.WithInsecure())
+ opts = append(opts, grpc.WithBlock())
+ return grpc.Dial(address, opts...)
+}