Skip to content

Commit

Permalink
add read super lock api
Browse files Browse the repository at this point in the history
Signed-off-by: lou <alex1988@outlook.com>
  • Loading branch information
27149chen committed Aug 16, 2024
1 parent a993a43 commit 0f492e3
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 36 deletions.
141 changes: 105 additions & 36 deletions weed/storage/backend/udm/api/v1/storage.pb.go

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

7 changes: 7 additions & 0 deletions weed/storage/backend/udm/api/v1/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ service UDMStorage {
rpc CacheFile (FileKey) returns (CacheFileReply) {
}

rpc ReadSuperBlock (FileKey) returns (ReadSuperBlockReply) {
}

rpc DeleteFile (FileKey) returns (google.protobuf.Empty) {
}
}
Expand All @@ -37,3 +40,7 @@ message FileInfo {
message CacheFileReply {
string cache_file = 1;
}

message ReadSuperBlockReply {
bytes data = 1;
}
36 changes: 36 additions & 0 deletions weed/storage/backend/udm/api/v1/storage_grpc.pb.go

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

21 changes: 21 additions & 0 deletions weed/storage/backend/udm/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (cs *ClientSet) DeleteFile(ctx context.Context, key string) error {
}

func (cs *ClientSet) ReadAt(ctx context.Context, key string, offset, length int64) ([]byte, error) {
if isSuperBlock(offset, length) {
return cs.ReadSuperBlock(ctx, key)
}

res, err := cs.storageClient.CacheFile(ctx, &pb.FileKey{
Key: key,
})
Expand All @@ -149,3 +153,20 @@ func (cs *ClientSet) ReadAt(ctx context.Context, key string, offset, length int6

return buffer[:n], nil
}

func (cs *ClientSet) ReadSuperBlock(ctx context.Context, key string) ([]byte, error) {
res, err := cs.storageClient.ReadSuperBlock(ctx, &pb.FileKey{
Key: key,
})
if err != nil {
return nil, err
}

return res.Data, nil
}

const superBlockSize = 8

func isSuperBlock(offset, length int64) bool {
return offset == 0 && length == superBlockSize
}

0 comments on commit 0f492e3

Please sign in to comment.