diff --git a/seaweed-block/core/frontend/chunkstore/fake_test.go b/seaweed-block/core/frontend/chunkstore/fake_test.go new file mode 100644 index 0000000000..dbcca286fa --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/fake_test.go @@ -0,0 +1,144 @@ +package chunkstore + +import ( + "bytes" + "context" + "errors" + "fmt" + "path" + "sync" + + "google.golang.org/protobuf/proto" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" +) + +// fakeFiler is an in-memory filer with the same precondition semantics as +// seaweed-mono's UpdateEntry (validateUpdateEntryPreconditions) and +// CreateEntry(o_excl). It records every entry ever written so tests can +// check that no HEAD or snapshot entry carries chunks. +type fakeFiler struct { + mu sync.Mutex + entries map[string]*filerpb.Entry + written []*filerpb.Entry + + // failUpdate, if set, is called before an UpdateEntry is applied; a + // non-nil return fails the call and the update is NOT applied. + failUpdate func(p string) error + // failUpdateAfterApply, if set, is called after an UpdateEntry was + // applied; a non-nil return is reported to the caller (ambiguous error). + failUpdateAfterApply func(p string) error + updates int +} + +func newFakeFiler() *fakeFiler { return &fakeFiler{entries: map[string]*filerpb.Entry{}} } + +func (f *fakeFiler) LookupEntry(_ context.Context, dir, name string) (*filerpb.Entry, error) { + f.mu.Lock() + defer f.mu.Unlock() + e, ok := f.entries[path.Join(dir, name)] + if !ok { + return nil, ErrNotFound + } + return proto.Clone(e).(*filerpb.Entry), nil +} + +func (f *fakeFiler) CreateEntry(_ context.Context, dir string, e *filerpb.Entry, oExcl bool) error { + f.mu.Lock() + defer f.mu.Unlock() + p := path.Join(dir, e.Name) + if _, ok := f.entries[p]; ok && oExcl { + return fmt.Errorf("%w: %s", ErrExists, p) + } + c := proto.Clone(e).(*filerpb.Entry) + f.entries[p] = c + f.written = append(f.written, proto.Clone(e).(*filerpb.Entry)) + return nil +} + +func (f *fakeFiler) UpdateEntry(_ context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error { + f.mu.Lock() + defer f.mu.Unlock() + p := path.Join(dir, e.Name) + if f.failUpdate != nil { + if err := f.failUpdate(p); err != nil { + return err + } + } + cur, ok := f.entries[p] + if !ok { + return fmt.Errorf("%w: %s", ErrNotFound, p) + } + for k, want := range expected { + got, has := cur.Extended[k] + if has && !bytes.Equal(got, want) || !has && len(want) > 0 { + return fmt.Errorf("%w: extended %q changed", ErrPrecondition, k) + } + } + f.entries[p] = proto.Clone(e).(*filerpb.Entry) + f.written = append(f.written, proto.Clone(e).(*filerpb.Entry)) + f.updates++ + if f.failUpdateAfterApply != nil { + if err := f.failUpdateAfterApply(p); err != nil { + return err + } + } + return nil +} + +// bumpExtended mutates a stored entry's extended key, as another writer would. +func (f *fakeFiler) bumpExtended(p, key, val string) { + f.mu.Lock() + defer f.mu.Unlock() + f.entries[p].Extended[key] = []byte(val) +} + +func (f *fakeFiler) allWritten() []*filerpb.Entry { + f.mu.Lock() + defer f.mu.Unlock() + return append([]*filerpb.Entry(nil), f.written...) +} + +// fakeBlobs is an in-memory needle store. +type fakeBlobs struct { + mu sync.Mutex + data map[string][]byte + next int + puts int + gets int + failPut func(n int) error +} + +func newFakeBlobs() *fakeBlobs { return &fakeBlobs{data: map[string][]byte{}} } + +func (b *fakeBlobs) Put(_ context.Context, d []byte) (string, error) { + b.mu.Lock() + defer b.mu.Unlock() + b.puts++ + if b.failPut != nil { + if err := b.failPut(b.puts); err != nil { + return "", err + } + } + b.next++ + fid := fmt.Sprintf("3,%08x", b.next) + b.data[fid] = append([]byte(nil), d...) + return fid, nil +} + +func (b *fakeBlobs) Get(_ context.Context, fid string) ([]byte, error) { + b.mu.Lock() + defer b.mu.Unlock() + b.gets++ + d, ok := b.data[fid] + if !ok { + return nil, errors.New("fake: no such fid " + fid) + } + return append([]byte(nil), d...), nil +} + +func (b *fakeBlobs) counts() (puts, gets, stored int) { + b.mu.Lock() + defer b.mu.Unlock() + return b.puts, b.gets, len(b.data) +} diff --git a/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.pb.go b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.pb.go new file mode 100644 index 0000000000..50ab1f6a27 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.pb.go @@ -0,0 +1,1456 @@ +// Minimal subset of SeaweedFS filer.proto (seaweed-mono 8b582399d, +// enterprise/weed/pb/filer.proto) used by the chunkstore PoC client. +// +// Package, service, message names and field numbers are copied verbatim so +// the wire format and the gRPC method paths (/filer_pb.SeaweedFiler/...) +// match a real filer. Fields chunkstore never reads or writes are omitted; +// protobuf keeps them as unknown fields on decode. +// +// Regenerate (from this directory): +// protoc --go_out=. --go_opt=paths=source_relative \ +// --go-grpc_out=. --go-grpc_opt=paths=source_relative filer_subset.proto + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.6 +// protoc v7.34.1 +// source: filer_subset.proto + +package filerpb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type FilerError int32 + +const ( + FilerError_OK FilerError = 0 + FilerError_ENTRY_NAME_TOO_LONG FilerError = 1 + FilerError_PARENT_IS_FILE FilerError = 2 + FilerError_EXISTING_IS_DIRECTORY FilerError = 3 + FilerError_EXISTING_IS_FILE FilerError = 4 + FilerError_ENTRY_ALREADY_EXISTS FilerError = 5 + FilerError_PRECONDITION_FAILED FilerError = 6 + FilerError_READ_ONLY FilerError = 7 +) + +// Enum value maps for FilerError. +var ( + FilerError_name = map[int32]string{ + 0: "OK", + 1: "ENTRY_NAME_TOO_LONG", + 2: "PARENT_IS_FILE", + 3: "EXISTING_IS_DIRECTORY", + 4: "EXISTING_IS_FILE", + 5: "ENTRY_ALREADY_EXISTS", + 6: "PRECONDITION_FAILED", + 7: "READ_ONLY", + } + FilerError_value = map[string]int32{ + "OK": 0, + "ENTRY_NAME_TOO_LONG": 1, + "PARENT_IS_FILE": 2, + "EXISTING_IS_DIRECTORY": 3, + "EXISTING_IS_FILE": 4, + "ENTRY_ALREADY_EXISTS": 5, + "PRECONDITION_FAILED": 6, + "READ_ONLY": 7, + } +) + +func (x FilerError) Enum() *FilerError { + p := new(FilerError) + *p = x + return p +} + +func (x FilerError) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FilerError) Descriptor() protoreflect.EnumDescriptor { + return file_filer_subset_proto_enumTypes[0].Descriptor() +} + +func (FilerError) Type() protoreflect.EnumType { + return &file_filer_subset_proto_enumTypes[0] +} + +func (x FilerError) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FilerError.Descriptor instead. +func (FilerError) EnumDescriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{0} +} + +type LookupDirectoryEntryRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Directory string `protobuf:"bytes,1,opt,name=directory,proto3" json:"directory,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LookupDirectoryEntryRequest) Reset() { + *x = LookupDirectoryEntryRequest{} + mi := &file_filer_subset_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LookupDirectoryEntryRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupDirectoryEntryRequest) ProtoMessage() {} + +func (x *LookupDirectoryEntryRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupDirectoryEntryRequest.ProtoReflect.Descriptor instead. +func (*LookupDirectoryEntryRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{0} +} + +func (x *LookupDirectoryEntryRequest) GetDirectory() string { + if x != nil { + return x.Directory + } + return "" +} + +func (x *LookupDirectoryEntryRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type LookupDirectoryEntryResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Entry *Entry `protobuf:"bytes,1,opt,name=entry,proto3" json:"entry,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LookupDirectoryEntryResponse) Reset() { + *x = LookupDirectoryEntryResponse{} + mi := &file_filer_subset_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LookupDirectoryEntryResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupDirectoryEntryResponse) ProtoMessage() {} + +func (x *LookupDirectoryEntryResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupDirectoryEntryResponse.ProtoReflect.Descriptor instead. +func (*LookupDirectoryEntryResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{1} +} + +func (x *LookupDirectoryEntryResponse) GetEntry() *Entry { + if x != nil { + return x.Entry + } + return nil +} + +type Entry struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + IsDirectory bool `protobuf:"varint,2,opt,name=is_directory,json=isDirectory,proto3" json:"is_directory,omitempty"` + Chunks []*FileChunk `protobuf:"bytes,3,rep,name=chunks,proto3" json:"chunks,omitempty"` + Attributes *FuseAttributes `protobuf:"bytes,4,opt,name=attributes,proto3" json:"attributes,omitempty"` + Extended map[string][]byte `protobuf:"bytes,5,rep,name=extended,proto3" json:"extended,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Content []byte `protobuf:"bytes,9,opt,name=content,proto3" json:"content,omitempty"` // if not empty, the file content + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Entry) Reset() { + *x = Entry{} + mi := &file_filer_subset_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Entry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Entry) ProtoMessage() {} + +func (x *Entry) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Entry.ProtoReflect.Descriptor instead. +func (*Entry) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{2} +} + +func (x *Entry) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Entry) GetIsDirectory() bool { + if x != nil { + return x.IsDirectory + } + return false +} + +func (x *Entry) GetChunks() []*FileChunk { + if x != nil { + return x.Chunks + } + return nil +} + +func (x *Entry) GetAttributes() *FuseAttributes { + if x != nil { + return x.Attributes + } + return nil +} + +func (x *Entry) GetExtended() map[string][]byte { + if x != nil { + return x.Extended + } + return nil +} + +func (x *Entry) GetContent() []byte { + if x != nil { + return x.Content + } + return nil +} + +// Only file_id is modelled: chunkstore never writes chunks, and reads them +// only to refuse a HEAD entry that carries any. +type FileChunk struct { + state protoimpl.MessageState `protogen:"open.v1"` + FileId string `protobuf:"bytes,1,opt,name=file_id,json=fileId,proto3" json:"file_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileChunk) Reset() { + *x = FileChunk{} + mi := &file_filer_subset_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileChunk) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileChunk) ProtoMessage() {} + +func (x *FileChunk) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileChunk.ProtoReflect.Descriptor instead. +func (*FileChunk) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{3} +} + +func (x *FileChunk) GetFileId() string { + if x != nil { + return x.FileId + } + return "" +} + +type FuseAttributes struct { + state protoimpl.MessageState `protogen:"open.v1"` + FileSize uint64 `protobuf:"varint,1,opt,name=file_size,json=fileSize,proto3" json:"file_size,omitempty"` + Mtime int64 `protobuf:"varint,2,opt,name=mtime,proto3" json:"mtime,omitempty"` // unix time in seconds + FileMode uint32 `protobuf:"varint,3,opt,name=file_mode,json=fileMode,proto3" json:"file_mode,omitempty"` + Uid uint32 `protobuf:"varint,4,opt,name=uid,proto3" json:"uid,omitempty"` + Gid uint32 `protobuf:"varint,5,opt,name=gid,proto3" json:"gid,omitempty"` + Crtime int64 `protobuf:"varint,6,opt,name=crtime,proto3" json:"crtime,omitempty"` // unix time in seconds + Mime string `protobuf:"bytes,7,opt,name=mime,proto3" json:"mime,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FuseAttributes) Reset() { + *x = FuseAttributes{} + mi := &file_filer_subset_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FuseAttributes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FuseAttributes) ProtoMessage() {} + +func (x *FuseAttributes) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FuseAttributes.ProtoReflect.Descriptor instead. +func (*FuseAttributes) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{4} +} + +func (x *FuseAttributes) GetFileSize() uint64 { + if x != nil { + return x.FileSize + } + return 0 +} + +func (x *FuseAttributes) GetMtime() int64 { + if x != nil { + return x.Mtime + } + return 0 +} + +func (x *FuseAttributes) GetFileMode() uint32 { + if x != nil { + return x.FileMode + } + return 0 +} + +func (x *FuseAttributes) GetUid() uint32 { + if x != nil { + return x.Uid + } + return 0 +} + +func (x *FuseAttributes) GetGid() uint32 { + if x != nil { + return x.Gid + } + return 0 +} + +func (x *FuseAttributes) GetCrtime() int64 { + if x != nil { + return x.Crtime + } + return 0 +} + +func (x *FuseAttributes) GetMime() string { + if x != nil { + return x.Mime + } + return "" +} + +type CreateEntryRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Directory string `protobuf:"bytes,1,opt,name=directory,proto3" json:"directory,omitempty"` + Entry *Entry `protobuf:"bytes,2,opt,name=entry,proto3" json:"entry,omitempty"` + OExcl bool `protobuf:"varint,3,opt,name=o_excl,json=oExcl,proto3" json:"o_excl,omitempty"` + IsFromOtherCluster bool `protobuf:"varint,4,opt,name=is_from_other_cluster,json=isFromOtherCluster,proto3" json:"is_from_other_cluster,omitempty"` + Signatures []int32 `protobuf:"varint,5,rep,packed,name=signatures,proto3" json:"signatures,omitempty"` + SkipCheckParentDirectory bool `protobuf:"varint,6,opt,name=skip_check_parent_directory,json=skipCheckParentDirectory,proto3" json:"skip_check_parent_directory,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateEntryRequest) Reset() { + *x = CreateEntryRequest{} + mi := &file_filer_subset_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateEntryRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateEntryRequest) ProtoMessage() {} + +func (x *CreateEntryRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateEntryRequest.ProtoReflect.Descriptor instead. +func (*CreateEntryRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{5} +} + +func (x *CreateEntryRequest) GetDirectory() string { + if x != nil { + return x.Directory + } + return "" +} + +func (x *CreateEntryRequest) GetEntry() *Entry { + if x != nil { + return x.Entry + } + return nil +} + +func (x *CreateEntryRequest) GetOExcl() bool { + if x != nil { + return x.OExcl + } + return false +} + +func (x *CreateEntryRequest) GetIsFromOtherCluster() bool { + if x != nil { + return x.IsFromOtherCluster + } + return false +} + +func (x *CreateEntryRequest) GetSignatures() []int32 { + if x != nil { + return x.Signatures + } + return nil +} + +func (x *CreateEntryRequest) GetSkipCheckParentDirectory() bool { + if x != nil { + return x.SkipCheckParentDirectory + } + return false +} + +type CreateEntryResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + ErrorCode FilerError `protobuf:"varint,3,opt,name=error_code,json=errorCode,proto3,enum=filer_pb.FilerError" json:"error_code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateEntryResponse) Reset() { + *x = CreateEntryResponse{} + mi := &file_filer_subset_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateEntryResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateEntryResponse) ProtoMessage() {} + +func (x *CreateEntryResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateEntryResponse.ProtoReflect.Descriptor instead. +func (*CreateEntryResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{6} +} + +func (x *CreateEntryResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +func (x *CreateEntryResponse) GetErrorCode() FilerError { + if x != nil { + return x.ErrorCode + } + return FilerError_OK +} + +type UpdateEntryRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Directory string `protobuf:"bytes,1,opt,name=directory,proto3" json:"directory,omitempty"` + Entry *Entry `protobuf:"bytes,2,opt,name=entry,proto3" json:"entry,omitempty"` + IsFromOtherCluster bool `protobuf:"varint,3,opt,name=is_from_other_cluster,json=isFromOtherCluster,proto3" json:"is_from_other_cluster,omitempty"` + Signatures []int32 `protobuf:"varint,4,rep,packed,name=signatures,proto3" json:"signatures,omitempty"` + ExpectedExtended map[string][]byte `protobuf:"bytes,5,rep,name=expected_extended,json=expectedExtended,proto3" json:"expected_extended,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateEntryRequest) Reset() { + *x = UpdateEntryRequest{} + mi := &file_filer_subset_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateEntryRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateEntryRequest) ProtoMessage() {} + +func (x *UpdateEntryRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateEntryRequest.ProtoReflect.Descriptor instead. +func (*UpdateEntryRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateEntryRequest) GetDirectory() string { + if x != nil { + return x.Directory + } + return "" +} + +func (x *UpdateEntryRequest) GetEntry() *Entry { + if x != nil { + return x.Entry + } + return nil +} + +func (x *UpdateEntryRequest) GetIsFromOtherCluster() bool { + if x != nil { + return x.IsFromOtherCluster + } + return false +} + +func (x *UpdateEntryRequest) GetSignatures() []int32 { + if x != nil { + return x.Signatures + } + return nil +} + +func (x *UpdateEntryRequest) GetExpectedExtended() map[string][]byte { + if x != nil { + return x.ExpectedExtended + } + return nil +} + +type UpdateEntryResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateEntryResponse) Reset() { + *x = UpdateEntryResponse{} + mi := &file_filer_subset_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateEntryResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateEntryResponse) ProtoMessage() {} + +func (x *UpdateEntryResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateEntryResponse.ProtoReflect.Descriptor instead. +func (*UpdateEntryResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{8} +} + +type DeleteEntryRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Directory string `protobuf:"bytes,1,opt,name=directory,proto3" json:"directory,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + IsDeleteData bool `protobuf:"varint,4,opt,name=is_delete_data,json=isDeleteData,proto3" json:"is_delete_data,omitempty"` + IsRecursive bool `protobuf:"varint,5,opt,name=is_recursive,json=isRecursive,proto3" json:"is_recursive,omitempty"` + ExpectedExtended map[string][]byte `protobuf:"bytes,12,rep,name=expected_extended,json=expectedExtended,proto3" json:"expected_extended,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeleteEntryRequest) Reset() { + *x = DeleteEntryRequest{} + mi := &file_filer_subset_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeleteEntryRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteEntryRequest) ProtoMessage() {} + +func (x *DeleteEntryRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteEntryRequest.ProtoReflect.Descriptor instead. +func (*DeleteEntryRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{9} +} + +func (x *DeleteEntryRequest) GetDirectory() string { + if x != nil { + return x.Directory + } + return "" +} + +func (x *DeleteEntryRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *DeleteEntryRequest) GetIsDeleteData() bool { + if x != nil { + return x.IsDeleteData + } + return false +} + +func (x *DeleteEntryRequest) GetIsRecursive() bool { + if x != nil { + return x.IsRecursive + } + return false +} + +func (x *DeleteEntryRequest) GetExpectedExtended() map[string][]byte { + if x != nil { + return x.ExpectedExtended + } + return nil +} + +type DeleteEntryResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeleteEntryResponse) Reset() { + *x = DeleteEntryResponse{} + mi := &file_filer_subset_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeleteEntryResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteEntryResponse) ProtoMessage() {} + +func (x *DeleteEntryResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteEntryResponse.ProtoReflect.Descriptor instead. +func (*DeleteEntryResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{10} +} + +func (x *DeleteEntryResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +type AssignVolumeRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` + Collection string `protobuf:"bytes,2,opt,name=collection,proto3" json:"collection,omitempty"` + Replication string `protobuf:"bytes,3,opt,name=replication,proto3" json:"replication,omitempty"` + TtlSec int32 `protobuf:"varint,4,opt,name=ttl_sec,json=ttlSec,proto3" json:"ttl_sec,omitempty"` + DataCenter string `protobuf:"bytes,5,opt,name=data_center,json=dataCenter,proto3" json:"data_center,omitempty"` + Path string `protobuf:"bytes,6,opt,name=path,proto3" json:"path,omitempty"` + Rack string `protobuf:"bytes,7,opt,name=rack,proto3" json:"rack,omitempty"` + DiskType string `protobuf:"bytes,8,opt,name=disk_type,json=diskType,proto3" json:"disk_type,omitempty"` + DataNode string `protobuf:"bytes,9,opt,name=data_node,json=dataNode,proto3" json:"data_node,omitempty"` + ExpectedDataSize uint64 `protobuf:"varint,10,opt,name=expected_data_size,json=expectedDataSize,proto3" json:"expected_data_size,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AssignVolumeRequest) Reset() { + *x = AssignVolumeRequest{} + mi := &file_filer_subset_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AssignVolumeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AssignVolumeRequest) ProtoMessage() {} + +func (x *AssignVolumeRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AssignVolumeRequest.ProtoReflect.Descriptor instead. +func (*AssignVolumeRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{11} +} + +func (x *AssignVolumeRequest) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 +} + +func (x *AssignVolumeRequest) GetCollection() string { + if x != nil { + return x.Collection + } + return "" +} + +func (x *AssignVolumeRequest) GetReplication() string { + if x != nil { + return x.Replication + } + return "" +} + +func (x *AssignVolumeRequest) GetTtlSec() int32 { + if x != nil { + return x.TtlSec + } + return 0 +} + +func (x *AssignVolumeRequest) GetDataCenter() string { + if x != nil { + return x.DataCenter + } + return "" +} + +func (x *AssignVolumeRequest) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +func (x *AssignVolumeRequest) GetRack() string { + if x != nil { + return x.Rack + } + return "" +} + +func (x *AssignVolumeRequest) GetDiskType() string { + if x != nil { + return x.DiskType + } + return "" +} + +func (x *AssignVolumeRequest) GetDataNode() string { + if x != nil { + return x.DataNode + } + return "" +} + +func (x *AssignVolumeRequest) GetExpectedDataSize() uint64 { + if x != nil { + return x.ExpectedDataSize + } + return 0 +} + +type AssignVolumeResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + FileId string `protobuf:"bytes,1,opt,name=file_id,json=fileId,proto3" json:"file_id,omitempty"` + Count int32 `protobuf:"varint,4,opt,name=count,proto3" json:"count,omitempty"` + Auth string `protobuf:"bytes,5,opt,name=auth,proto3" json:"auth,omitempty"` + Collection string `protobuf:"bytes,6,opt,name=collection,proto3" json:"collection,omitempty"` + Replication string `protobuf:"bytes,7,opt,name=replication,proto3" json:"replication,omitempty"` + Error string `protobuf:"bytes,8,opt,name=error,proto3" json:"error,omitempty"` + Location *Location `protobuf:"bytes,9,opt,name=location,proto3" json:"location,omitempty"` + Replicas []*Location `protobuf:"bytes,10,rep,name=replicas,proto3" json:"replicas,omitempty"` + Fsync bool `protobuf:"varint,11,opt,name=fsync,proto3" json:"fsync,omitempty"` + ErrorCode FilerError `protobuf:"varint,12,opt,name=error_code,json=errorCode,proto3,enum=filer_pb.FilerError" json:"error_code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AssignVolumeResponse) Reset() { + *x = AssignVolumeResponse{} + mi := &file_filer_subset_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AssignVolumeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AssignVolumeResponse) ProtoMessage() {} + +func (x *AssignVolumeResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AssignVolumeResponse.ProtoReflect.Descriptor instead. +func (*AssignVolumeResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{12} +} + +func (x *AssignVolumeResponse) GetFileId() string { + if x != nil { + return x.FileId + } + return "" +} + +func (x *AssignVolumeResponse) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 +} + +func (x *AssignVolumeResponse) GetAuth() string { + if x != nil { + return x.Auth + } + return "" +} + +func (x *AssignVolumeResponse) GetCollection() string { + if x != nil { + return x.Collection + } + return "" +} + +func (x *AssignVolumeResponse) GetReplication() string { + if x != nil { + return x.Replication + } + return "" +} + +func (x *AssignVolumeResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +func (x *AssignVolumeResponse) GetLocation() *Location { + if x != nil { + return x.Location + } + return nil +} + +func (x *AssignVolumeResponse) GetReplicas() []*Location { + if x != nil { + return x.Replicas + } + return nil +} + +func (x *AssignVolumeResponse) GetFsync() bool { + if x != nil { + return x.Fsync + } + return false +} + +func (x *AssignVolumeResponse) GetErrorCode() FilerError { + if x != nil { + return x.ErrorCode + } + return FilerError_OK +} + +type LookupVolumeRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + VolumeIds []string `protobuf:"bytes,1,rep,name=volume_ids,json=volumeIds,proto3" json:"volume_ids,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LookupVolumeRequest) Reset() { + *x = LookupVolumeRequest{} + mi := &file_filer_subset_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LookupVolumeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupVolumeRequest) ProtoMessage() {} + +func (x *LookupVolumeRequest) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupVolumeRequest.ProtoReflect.Descriptor instead. +func (*LookupVolumeRequest) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{13} +} + +func (x *LookupVolumeRequest) GetVolumeIds() []string { + if x != nil { + return x.VolumeIds + } + return nil +} + +type Locations struct { + state protoimpl.MessageState `protogen:"open.v1"` + Locations []*Location `protobuf:"bytes,1,rep,name=locations,proto3" json:"locations,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Locations) Reset() { + *x = Locations{} + mi := &file_filer_subset_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Locations) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Locations) ProtoMessage() {} + +func (x *Locations) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Locations.ProtoReflect.Descriptor instead. +func (*Locations) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{14} +} + +func (x *Locations) GetLocations() []*Location { + if x != nil { + return x.Locations + } + return nil +} + +type Location struct { + state protoimpl.MessageState `protogen:"open.v1"` + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` + PublicUrl string `protobuf:"bytes,2,opt,name=public_url,json=publicUrl,proto3" json:"public_url,omitempty"` + GrpcPort uint32 `protobuf:"varint,3,opt,name=grpc_port,json=grpcPort,proto3" json:"grpc_port,omitempty"` + DataCenter string `protobuf:"bytes,4,opt,name=data_center,json=dataCenter,proto3" json:"data_center,omitempty"` + DataInRemote bool `protobuf:"varint,5,opt,name=data_in_remote,json=dataInRemote,proto3" json:"data_in_remote,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Location) Reset() { + *x = Location{} + mi := &file_filer_subset_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Location) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Location) ProtoMessage() {} + +func (x *Location) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[15] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Location.ProtoReflect.Descriptor instead. +func (*Location) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{15} +} + +func (x *Location) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +func (x *Location) GetPublicUrl() string { + if x != nil { + return x.PublicUrl + } + return "" +} + +func (x *Location) GetGrpcPort() uint32 { + if x != nil { + return x.GrpcPort + } + return 0 +} + +func (x *Location) GetDataCenter() string { + if x != nil { + return x.DataCenter + } + return "" +} + +func (x *Location) GetDataInRemote() bool { + if x != nil { + return x.DataInRemote + } + return false +} + +type LookupVolumeResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + LocationsMap map[string]*Locations `protobuf:"bytes,1,rep,name=locations_map,json=locationsMap,proto3" json:"locations_map,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LookupVolumeResponse) Reset() { + *x = LookupVolumeResponse{} + mi := &file_filer_subset_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LookupVolumeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupVolumeResponse) ProtoMessage() {} + +func (x *LookupVolumeResponse) ProtoReflect() protoreflect.Message { + mi := &file_filer_subset_proto_msgTypes[16] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupVolumeResponse.ProtoReflect.Descriptor instead. +func (*LookupVolumeResponse) Descriptor() ([]byte, []int) { + return file_filer_subset_proto_rawDescGZIP(), []int{16} +} + +func (x *LookupVolumeResponse) GetLocationsMap() map[string]*Locations { + if x != nil { + return x.LocationsMap + } + return nil +} + +var File_filer_subset_proto protoreflect.FileDescriptor + +const file_filer_subset_proto_rawDesc = "" + + "\n" + + "\x12filer_subset.proto\x12\bfiler_pb\"O\n" + + "\x1bLookupDirectoryEntryRequest\x12\x1c\n" + + "\tdirectory\x18\x01 \x01(\tR\tdirectory\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\"E\n" + + "\x1cLookupDirectoryEntryResponse\x12%\n" + + "\x05entry\x18\x01 \x01(\v2\x0f.filer_pb.EntryR\x05entry\"\xb7\x02\n" + + "\x05Entry\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12!\n" + + "\fis_directory\x18\x02 \x01(\bR\visDirectory\x12+\n" + + "\x06chunks\x18\x03 \x03(\v2\x13.filer_pb.FileChunkR\x06chunks\x128\n" + + "\n" + + "attributes\x18\x04 \x01(\v2\x18.filer_pb.FuseAttributesR\n" + + "attributes\x129\n" + + "\bextended\x18\x05 \x03(\v2\x1d.filer_pb.Entry.ExtendedEntryR\bextended\x12\x18\n" + + "\acontent\x18\t \x01(\fR\acontent\x1a;\n" + + "\rExtendedEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\fR\x05value:\x028\x01\"$\n" + + "\tFileChunk\x12\x17\n" + + "\afile_id\x18\x01 \x01(\tR\x06fileId\"\xb0\x01\n" + + "\x0eFuseAttributes\x12\x1b\n" + + "\tfile_size\x18\x01 \x01(\x04R\bfileSize\x12\x14\n" + + "\x05mtime\x18\x02 \x01(\x03R\x05mtime\x12\x1b\n" + + "\tfile_mode\x18\x03 \x01(\rR\bfileMode\x12\x10\n" + + "\x03uid\x18\x04 \x01(\rR\x03uid\x12\x10\n" + + "\x03gid\x18\x05 \x01(\rR\x03gid\x12\x16\n" + + "\x06crtime\x18\x06 \x01(\x03R\x06crtime\x12\x12\n" + + "\x04mime\x18\a \x01(\tR\x04mime\"\x82\x02\n" + + "\x12CreateEntryRequest\x12\x1c\n" + + "\tdirectory\x18\x01 \x01(\tR\tdirectory\x12%\n" + + "\x05entry\x18\x02 \x01(\v2\x0f.filer_pb.EntryR\x05entry\x12\x15\n" + + "\x06o_excl\x18\x03 \x01(\bR\x05oExcl\x121\n" + + "\x15is_from_other_cluster\x18\x04 \x01(\bR\x12isFromOtherCluster\x12\x1e\n" + + "\n" + + "signatures\x18\x05 \x03(\x05R\n" + + "signatures\x12=\n" + + "\x1bskip_check_parent_directory\x18\x06 \x01(\bR\x18skipCheckParentDirectory\"`\n" + + "\x13CreateEntryResponse\x12\x14\n" + + "\x05error\x18\x01 \x01(\tR\x05error\x123\n" + + "\n" + + "error_code\x18\x03 \x01(\x0e2\x14.filer_pb.FilerErrorR\terrorCode\"\xd2\x02\n" + + "\x12UpdateEntryRequest\x12\x1c\n" + + "\tdirectory\x18\x01 \x01(\tR\tdirectory\x12%\n" + + "\x05entry\x18\x02 \x01(\v2\x0f.filer_pb.EntryR\x05entry\x121\n" + + "\x15is_from_other_cluster\x18\x03 \x01(\bR\x12isFromOtherCluster\x12\x1e\n" + + "\n" + + "signatures\x18\x04 \x03(\x05R\n" + + "signatures\x12_\n" + + "\x11expected_extended\x18\x05 \x03(\v22.filer_pb.UpdateEntryRequest.ExpectedExtendedEntryR\x10expectedExtended\x1aC\n" + + "\x15ExpectedExtendedEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\fR\x05value:\x028\x01\"\x15\n" + + "\x13UpdateEntryResponse\"\xb5\x02\n" + + "\x12DeleteEntryRequest\x12\x1c\n" + + "\tdirectory\x18\x01 \x01(\tR\tdirectory\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\x12$\n" + + "\x0eis_delete_data\x18\x04 \x01(\bR\fisDeleteData\x12!\n" + + "\fis_recursive\x18\x05 \x01(\bR\visRecursive\x12_\n" + + "\x11expected_extended\x18\f \x03(\v22.filer_pb.DeleteEntryRequest.ExpectedExtendedEntryR\x10expectedExtended\x1aC\n" + + "\x15ExpectedExtendedEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\fR\x05value:\x028\x01\"+\n" + + "\x13DeleteEntryResponse\x12\x14\n" + + "\x05error\x18\x01 \x01(\tR\x05error\"\xb7\x02\n" + + "\x13AssignVolumeRequest\x12\x14\n" + + "\x05count\x18\x01 \x01(\x05R\x05count\x12\x1e\n" + + "\n" + + "collection\x18\x02 \x01(\tR\n" + + "collection\x12 \n" + + "\vreplication\x18\x03 \x01(\tR\vreplication\x12\x17\n" + + "\attl_sec\x18\x04 \x01(\x05R\x06ttlSec\x12\x1f\n" + + "\vdata_center\x18\x05 \x01(\tR\n" + + "dataCenter\x12\x12\n" + + "\x04path\x18\x06 \x01(\tR\x04path\x12\x12\n" + + "\x04rack\x18\a \x01(\tR\x04rack\x12\x1b\n" + + "\tdisk_type\x18\b \x01(\tR\bdiskType\x12\x1b\n" + + "\tdata_node\x18\t \x01(\tR\bdataNode\x12,\n" + + "\x12expected_data_size\x18\n" + + " \x01(\x04R\x10expectedDataSize\"\xdc\x02\n" + + "\x14AssignVolumeResponse\x12\x17\n" + + "\afile_id\x18\x01 \x01(\tR\x06fileId\x12\x14\n" + + "\x05count\x18\x04 \x01(\x05R\x05count\x12\x12\n" + + "\x04auth\x18\x05 \x01(\tR\x04auth\x12\x1e\n" + + "\n" + + "collection\x18\x06 \x01(\tR\n" + + "collection\x12 \n" + + "\vreplication\x18\a \x01(\tR\vreplication\x12\x14\n" + + "\x05error\x18\b \x01(\tR\x05error\x12.\n" + + "\blocation\x18\t \x01(\v2\x12.filer_pb.LocationR\blocation\x12.\n" + + "\breplicas\x18\n" + + " \x03(\v2\x12.filer_pb.LocationR\breplicas\x12\x14\n" + + "\x05fsync\x18\v \x01(\bR\x05fsync\x123\n" + + "\n" + + "error_code\x18\f \x01(\x0e2\x14.filer_pb.FilerErrorR\terrorCode\"4\n" + + "\x13LookupVolumeRequest\x12\x1d\n" + + "\n" + + "volume_ids\x18\x01 \x03(\tR\tvolumeIds\"=\n" + + "\tLocations\x120\n" + + "\tlocations\x18\x01 \x03(\v2\x12.filer_pb.LocationR\tlocations\"\x9f\x01\n" + + "\bLocation\x12\x10\n" + + "\x03url\x18\x01 \x01(\tR\x03url\x12\x1d\n" + + "\n" + + "public_url\x18\x02 \x01(\tR\tpublicUrl\x12\x1b\n" + + "\tgrpc_port\x18\x03 \x01(\rR\bgrpcPort\x12\x1f\n" + + "\vdata_center\x18\x04 \x01(\tR\n" + + "dataCenter\x12$\n" + + "\x0edata_in_remote\x18\x05 \x01(\bR\fdataInRemote\"\xc3\x01\n" + + "\x14LookupVolumeResponse\x12U\n" + + "\rlocations_map\x18\x01 \x03(\v20.filer_pb.LookupVolumeResponse.LocationsMapEntryR\flocationsMap\x1aT\n" + + "\x11LocationsMapEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12)\n" + + "\x05value\x18\x02 \x01(\v2\x13.filer_pb.LocationsR\x05value:\x028\x01*\xb4\x01\n" + + "\n" + + "FilerError\x12\x06\n" + + "\x02OK\x10\x00\x12\x17\n" + + "\x13ENTRY_NAME_TOO_LONG\x10\x01\x12\x12\n" + + "\x0ePARENT_IS_FILE\x10\x02\x12\x19\n" + + "\x15EXISTING_IS_DIRECTORY\x10\x03\x12\x14\n" + + "\x10EXISTING_IS_FILE\x10\x04\x12\x18\n" + + "\x14ENTRY_ALREADY_EXISTS\x10\x05\x12\x17\n" + + "\x13PRECONDITION_FAILED\x10\x06\x12\r\n" + + "\tREAD_ONLY\x10\a2\x83\x04\n" + + "\fSeaweedFiler\x12g\n" + + "\x14LookupDirectoryEntry\x12%.filer_pb.LookupDirectoryEntryRequest\x1a&.filer_pb.LookupDirectoryEntryResponse\"\x00\x12L\n" + + "\vCreateEntry\x12\x1c.filer_pb.CreateEntryRequest\x1a\x1d.filer_pb.CreateEntryResponse\"\x00\x12L\n" + + "\vUpdateEntry\x12\x1c.filer_pb.UpdateEntryRequest\x1a\x1d.filer_pb.UpdateEntryResponse\"\x00\x12L\n" + + "\vDeleteEntry\x12\x1c.filer_pb.DeleteEntryRequest\x1a\x1d.filer_pb.DeleteEntryResponse\"\x00\x12O\n" + + "\fAssignVolume\x12\x1d.filer_pb.AssignVolumeRequest\x1a\x1e.filer_pb.AssignVolumeResponse\"\x00\x12O\n" + + "\fLookupVolume\x12\x1d.filer_pb.LookupVolumeRequest\x1a\x1e.filer_pb.LookupVolumeResponse\"\x00BEZCgithub.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpbb\x06proto3" + +var ( + file_filer_subset_proto_rawDescOnce sync.Once + file_filer_subset_proto_rawDescData []byte +) + +func file_filer_subset_proto_rawDescGZIP() []byte { + file_filer_subset_proto_rawDescOnce.Do(func() { + file_filer_subset_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_filer_subset_proto_rawDesc), len(file_filer_subset_proto_rawDesc))) + }) + return file_filer_subset_proto_rawDescData +} + +var file_filer_subset_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_filer_subset_proto_msgTypes = make([]protoimpl.MessageInfo, 21) +var file_filer_subset_proto_goTypes = []any{ + (FilerError)(0), // 0: filer_pb.FilerError + (*LookupDirectoryEntryRequest)(nil), // 1: filer_pb.LookupDirectoryEntryRequest + (*LookupDirectoryEntryResponse)(nil), // 2: filer_pb.LookupDirectoryEntryResponse + (*Entry)(nil), // 3: filer_pb.Entry + (*FileChunk)(nil), // 4: filer_pb.FileChunk + (*FuseAttributes)(nil), // 5: filer_pb.FuseAttributes + (*CreateEntryRequest)(nil), // 6: filer_pb.CreateEntryRequest + (*CreateEntryResponse)(nil), // 7: filer_pb.CreateEntryResponse + (*UpdateEntryRequest)(nil), // 8: filer_pb.UpdateEntryRequest + (*UpdateEntryResponse)(nil), // 9: filer_pb.UpdateEntryResponse + (*DeleteEntryRequest)(nil), // 10: filer_pb.DeleteEntryRequest + (*DeleteEntryResponse)(nil), // 11: filer_pb.DeleteEntryResponse + (*AssignVolumeRequest)(nil), // 12: filer_pb.AssignVolumeRequest + (*AssignVolumeResponse)(nil), // 13: filer_pb.AssignVolumeResponse + (*LookupVolumeRequest)(nil), // 14: filer_pb.LookupVolumeRequest + (*Locations)(nil), // 15: filer_pb.Locations + (*Location)(nil), // 16: filer_pb.Location + (*LookupVolumeResponse)(nil), // 17: filer_pb.LookupVolumeResponse + nil, // 18: filer_pb.Entry.ExtendedEntry + nil, // 19: filer_pb.UpdateEntryRequest.ExpectedExtendedEntry + nil, // 20: filer_pb.DeleteEntryRequest.ExpectedExtendedEntry + nil, // 21: filer_pb.LookupVolumeResponse.LocationsMapEntry +} +var file_filer_subset_proto_depIdxs = []int32{ + 3, // 0: filer_pb.LookupDirectoryEntryResponse.entry:type_name -> filer_pb.Entry + 4, // 1: filer_pb.Entry.chunks:type_name -> filer_pb.FileChunk + 5, // 2: filer_pb.Entry.attributes:type_name -> filer_pb.FuseAttributes + 18, // 3: filer_pb.Entry.extended:type_name -> filer_pb.Entry.ExtendedEntry + 3, // 4: filer_pb.CreateEntryRequest.entry:type_name -> filer_pb.Entry + 0, // 5: filer_pb.CreateEntryResponse.error_code:type_name -> filer_pb.FilerError + 3, // 6: filer_pb.UpdateEntryRequest.entry:type_name -> filer_pb.Entry + 19, // 7: filer_pb.UpdateEntryRequest.expected_extended:type_name -> filer_pb.UpdateEntryRequest.ExpectedExtendedEntry + 20, // 8: filer_pb.DeleteEntryRequest.expected_extended:type_name -> filer_pb.DeleteEntryRequest.ExpectedExtendedEntry + 16, // 9: filer_pb.AssignVolumeResponse.location:type_name -> filer_pb.Location + 16, // 10: filer_pb.AssignVolumeResponse.replicas:type_name -> filer_pb.Location + 0, // 11: filer_pb.AssignVolumeResponse.error_code:type_name -> filer_pb.FilerError + 16, // 12: filer_pb.Locations.locations:type_name -> filer_pb.Location + 21, // 13: filer_pb.LookupVolumeResponse.locations_map:type_name -> filer_pb.LookupVolumeResponse.LocationsMapEntry + 15, // 14: filer_pb.LookupVolumeResponse.LocationsMapEntry.value:type_name -> filer_pb.Locations + 1, // 15: filer_pb.SeaweedFiler.LookupDirectoryEntry:input_type -> filer_pb.LookupDirectoryEntryRequest + 6, // 16: filer_pb.SeaweedFiler.CreateEntry:input_type -> filer_pb.CreateEntryRequest + 8, // 17: filer_pb.SeaweedFiler.UpdateEntry:input_type -> filer_pb.UpdateEntryRequest + 10, // 18: filer_pb.SeaweedFiler.DeleteEntry:input_type -> filer_pb.DeleteEntryRequest + 12, // 19: filer_pb.SeaweedFiler.AssignVolume:input_type -> filer_pb.AssignVolumeRequest + 14, // 20: filer_pb.SeaweedFiler.LookupVolume:input_type -> filer_pb.LookupVolumeRequest + 2, // 21: filer_pb.SeaweedFiler.LookupDirectoryEntry:output_type -> filer_pb.LookupDirectoryEntryResponse + 7, // 22: filer_pb.SeaweedFiler.CreateEntry:output_type -> filer_pb.CreateEntryResponse + 9, // 23: filer_pb.SeaweedFiler.UpdateEntry:output_type -> filer_pb.UpdateEntryResponse + 11, // 24: filer_pb.SeaweedFiler.DeleteEntry:output_type -> filer_pb.DeleteEntryResponse + 13, // 25: filer_pb.SeaweedFiler.AssignVolume:output_type -> filer_pb.AssignVolumeResponse + 17, // 26: filer_pb.SeaweedFiler.LookupVolume:output_type -> filer_pb.LookupVolumeResponse + 21, // [21:27] is the sub-list for method output_type + 15, // [15:21] is the sub-list for method input_type + 15, // [15:15] is the sub-list for extension type_name + 15, // [15:15] is the sub-list for extension extendee + 0, // [0:15] is the sub-list for field type_name +} + +func init() { file_filer_subset_proto_init() } +func file_filer_subset_proto_init() { + if File_filer_subset_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_filer_subset_proto_rawDesc), len(file_filer_subset_proto_rawDesc)), + NumEnums: 1, + NumMessages: 21, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_filer_subset_proto_goTypes, + DependencyIndexes: file_filer_subset_proto_depIdxs, + EnumInfos: file_filer_subset_proto_enumTypes, + MessageInfos: file_filer_subset_proto_msgTypes, + }.Build() + File_filer_subset_proto = out.File + file_filer_subset_proto_goTypes = nil + file_filer_subset_proto_depIdxs = nil +} diff --git a/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.proto b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.proto new file mode 100644 index 0000000000..dcb62a2495 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset.proto @@ -0,0 +1,153 @@ +// Minimal subset of SeaweedFS filer.proto (seaweed-mono 8b582399d, +// enterprise/weed/pb/filer.proto) used by the chunkstore PoC client. +// +// Package, service, message names and field numbers are copied verbatim so +// the wire format and the gRPC method paths (/filer_pb.SeaweedFiler/...) +// match a real filer. Fields chunkstore never reads or writes are omitted; +// protobuf keeps them as unknown fields on decode. +// +// Regenerate (from this directory): +// protoc --go_out=. --go_opt=paths=source_relative \ +// --go-grpc_out=. --go-grpc_opt=paths=source_relative filer_subset.proto +syntax = "proto3"; + +package filer_pb; + +option go_package = "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"; + +service SeaweedFiler { + rpc LookupDirectoryEntry (LookupDirectoryEntryRequest) returns (LookupDirectoryEntryResponse) {} + rpc CreateEntry (CreateEntryRequest) returns (CreateEntryResponse) {} + rpc UpdateEntry (UpdateEntryRequest) returns (UpdateEntryResponse) {} + rpc DeleteEntry (DeleteEntryRequest) returns (DeleteEntryResponse) {} + rpc AssignVolume (AssignVolumeRequest) returns (AssignVolumeResponse) {} + rpc LookupVolume (LookupVolumeRequest) returns (LookupVolumeResponse) {} +} + +message LookupDirectoryEntryRequest { + string directory = 1; + string name = 2; +} + +message LookupDirectoryEntryResponse { + Entry entry = 1; +} + +message Entry { + string name = 1; + bool is_directory = 2; + repeated FileChunk chunks = 3; + FuseAttributes attributes = 4; + map extended = 5; + bytes content = 9; // if not empty, the file content +} + +// Only file_id is modelled: chunkstore never writes chunks, and reads them +// only to refuse a HEAD entry that carries any. +message FileChunk { + string file_id = 1; +} + +message FuseAttributes { + uint64 file_size = 1; + int64 mtime = 2; // unix time in seconds + uint32 file_mode = 3; + uint32 uid = 4; + uint32 gid = 5; + int64 crtime = 6; // unix time in seconds + string mime = 7; +} + +message CreateEntryRequest { + string directory = 1; + Entry entry = 2; + bool o_excl = 3; + bool is_from_other_cluster = 4; + repeated int32 signatures = 5; + bool skip_check_parent_directory = 6; +} + +enum FilerError { + OK = 0; + ENTRY_NAME_TOO_LONG = 1; + PARENT_IS_FILE = 2; + EXISTING_IS_DIRECTORY = 3; + EXISTING_IS_FILE = 4; + ENTRY_ALREADY_EXISTS = 5; + PRECONDITION_FAILED = 6; + READ_ONLY = 7; +} + +message CreateEntryResponse { + string error = 1; + FilerError error_code = 3; +} + +message UpdateEntryRequest { + string directory = 1; + Entry entry = 2; + bool is_from_other_cluster = 3; + repeated int32 signatures = 4; + map expected_extended = 5; +} + +message UpdateEntryResponse { +} + +message DeleteEntryRequest { + string directory = 1; + string name = 2; + bool is_delete_data = 4; + bool is_recursive = 5; + map expected_extended = 12; +} + +message DeleteEntryResponse { + string error = 1; +} + +message AssignVolumeRequest { + int32 count = 1; + string collection = 2; + string replication = 3; + int32 ttl_sec = 4; + string data_center = 5; + string path = 6; + string rack = 7; + string disk_type = 8; + string data_node = 9; + uint64 expected_data_size = 10; +} + +message AssignVolumeResponse { + string file_id = 1; + int32 count = 4; + string auth = 5; + string collection = 6; + string replication = 7; + string error = 8; + Location location = 9; + repeated Location replicas = 10; + bool fsync = 11; + FilerError error_code = 12; +} + +message LookupVolumeRequest { + repeated string volume_ids = 1; +} + +message Locations { + repeated Location locations = 1; +} + +message Location { + string url = 1; + string public_url = 2; + uint32 grpc_port = 3; + string data_center = 4; + bool data_in_remote = 5; +} + +message LookupVolumeResponse { + map locations_map = 1; +} diff --git a/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset_grpc.pb.go b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset_grpc.pb.go new file mode 100644 index 0000000000..b8a9cbb606 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/filerpb/filer_subset_grpc.pb.go @@ -0,0 +1,323 @@ +// Minimal subset of SeaweedFS filer.proto (seaweed-mono 8b582399d, +// enterprise/weed/pb/filer.proto) used by the chunkstore PoC client. +// +// Package, service, message names and field numbers are copied verbatim so +// the wire format and the gRPC method paths (/filer_pb.SeaweedFiler/...) +// match a real filer. Fields chunkstore never reads or writes are omitted; +// protobuf keeps them as unknown fields on decode. +// +// Regenerate (from this directory): +// protoc --go_out=. --go_opt=paths=source_relative \ +// --go-grpc_out=. --go-grpc_opt=paths=source_relative filer_subset.proto + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.2 +// - protoc v7.34.1 +// source: filer_subset.proto + +package filerpb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + SeaweedFiler_LookupDirectoryEntry_FullMethodName = "/filer_pb.SeaweedFiler/LookupDirectoryEntry" + SeaweedFiler_CreateEntry_FullMethodName = "/filer_pb.SeaweedFiler/CreateEntry" + SeaweedFiler_UpdateEntry_FullMethodName = "/filer_pb.SeaweedFiler/UpdateEntry" + SeaweedFiler_DeleteEntry_FullMethodName = "/filer_pb.SeaweedFiler/DeleteEntry" + SeaweedFiler_AssignVolume_FullMethodName = "/filer_pb.SeaweedFiler/AssignVolume" + SeaweedFiler_LookupVolume_FullMethodName = "/filer_pb.SeaweedFiler/LookupVolume" +) + +// SeaweedFilerClient is the client API for SeaweedFiler service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type SeaweedFilerClient interface { + LookupDirectoryEntry(ctx context.Context, in *LookupDirectoryEntryRequest, opts ...grpc.CallOption) (*LookupDirectoryEntryResponse, error) + CreateEntry(ctx context.Context, in *CreateEntryRequest, opts ...grpc.CallOption) (*CreateEntryResponse, error) + UpdateEntry(ctx context.Context, in *UpdateEntryRequest, opts ...grpc.CallOption) (*UpdateEntryResponse, error) + DeleteEntry(ctx context.Context, in *DeleteEntryRequest, opts ...grpc.CallOption) (*DeleteEntryResponse, error) + AssignVolume(ctx context.Context, in *AssignVolumeRequest, opts ...grpc.CallOption) (*AssignVolumeResponse, error) + LookupVolume(ctx context.Context, in *LookupVolumeRequest, opts ...grpc.CallOption) (*LookupVolumeResponse, error) +} + +type seaweedFilerClient struct { + cc grpc.ClientConnInterface +} + +func NewSeaweedFilerClient(cc grpc.ClientConnInterface) SeaweedFilerClient { + return &seaweedFilerClient{cc} +} + +func (c *seaweedFilerClient) LookupDirectoryEntry(ctx context.Context, in *LookupDirectoryEntryRequest, opts ...grpc.CallOption) (*LookupDirectoryEntryResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LookupDirectoryEntryResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_LookupDirectoryEntry_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *seaweedFilerClient) CreateEntry(ctx context.Context, in *CreateEntryRequest, opts ...grpc.CallOption) (*CreateEntryResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CreateEntryResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_CreateEntry_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *seaweedFilerClient) UpdateEntry(ctx context.Context, in *UpdateEntryRequest, opts ...grpc.CallOption) (*UpdateEntryResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdateEntryResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_UpdateEntry_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *seaweedFilerClient) DeleteEntry(ctx context.Context, in *DeleteEntryRequest, opts ...grpc.CallOption) (*DeleteEntryResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DeleteEntryResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_DeleteEntry_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *seaweedFilerClient) AssignVolume(ctx context.Context, in *AssignVolumeRequest, opts ...grpc.CallOption) (*AssignVolumeResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AssignVolumeResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_AssignVolume_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *seaweedFilerClient) LookupVolume(ctx context.Context, in *LookupVolumeRequest, opts ...grpc.CallOption) (*LookupVolumeResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LookupVolumeResponse) + err := c.cc.Invoke(ctx, SeaweedFiler_LookupVolume_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SeaweedFilerServer is the server API for SeaweedFiler service. +// All implementations must embed UnimplementedSeaweedFilerServer +// for forward compatibility. +type SeaweedFilerServer interface { + LookupDirectoryEntry(context.Context, *LookupDirectoryEntryRequest) (*LookupDirectoryEntryResponse, error) + CreateEntry(context.Context, *CreateEntryRequest) (*CreateEntryResponse, error) + UpdateEntry(context.Context, *UpdateEntryRequest) (*UpdateEntryResponse, error) + DeleteEntry(context.Context, *DeleteEntryRequest) (*DeleteEntryResponse, error) + AssignVolume(context.Context, *AssignVolumeRequest) (*AssignVolumeResponse, error) + LookupVolume(context.Context, *LookupVolumeRequest) (*LookupVolumeResponse, error) + mustEmbedUnimplementedSeaweedFilerServer() +} + +// UnimplementedSeaweedFilerServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedSeaweedFilerServer struct{} + +func (UnimplementedSeaweedFilerServer) LookupDirectoryEntry(context.Context, *LookupDirectoryEntryRequest) (*LookupDirectoryEntryResponse, error) { + return nil, status.Error(codes.Unimplemented, "method LookupDirectoryEntry not implemented") +} +func (UnimplementedSeaweedFilerServer) CreateEntry(context.Context, *CreateEntryRequest) (*CreateEntryResponse, error) { + return nil, status.Error(codes.Unimplemented, "method CreateEntry not implemented") +} +func (UnimplementedSeaweedFilerServer) UpdateEntry(context.Context, *UpdateEntryRequest) (*UpdateEntryResponse, error) { + return nil, status.Error(codes.Unimplemented, "method UpdateEntry not implemented") +} +func (UnimplementedSeaweedFilerServer) DeleteEntry(context.Context, *DeleteEntryRequest) (*DeleteEntryResponse, error) { + return nil, status.Error(codes.Unimplemented, "method DeleteEntry not implemented") +} +func (UnimplementedSeaweedFilerServer) AssignVolume(context.Context, *AssignVolumeRequest) (*AssignVolumeResponse, error) { + return nil, status.Error(codes.Unimplemented, "method AssignVolume not implemented") +} +func (UnimplementedSeaweedFilerServer) LookupVolume(context.Context, *LookupVolumeRequest) (*LookupVolumeResponse, error) { + return nil, status.Error(codes.Unimplemented, "method LookupVolume not implemented") +} +func (UnimplementedSeaweedFilerServer) mustEmbedUnimplementedSeaweedFilerServer() {} +func (UnimplementedSeaweedFilerServer) testEmbeddedByValue() {} + +// UnsafeSeaweedFilerServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to SeaweedFilerServer will +// result in compilation errors. +type UnsafeSeaweedFilerServer interface { + mustEmbedUnimplementedSeaweedFilerServer() +} + +func RegisterSeaweedFilerServer(s grpc.ServiceRegistrar, srv SeaweedFilerServer) { + // If the following call panics, it indicates UnimplementedSeaweedFilerServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&SeaweedFiler_ServiceDesc, srv) +} + +func _SeaweedFiler_LookupDirectoryEntry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LookupDirectoryEntryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).LookupDirectoryEntry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_LookupDirectoryEntry_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).LookupDirectoryEntry(ctx, req.(*LookupDirectoryEntryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SeaweedFiler_CreateEntry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateEntryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).CreateEntry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_CreateEntry_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).CreateEntry(ctx, req.(*CreateEntryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SeaweedFiler_UpdateEntry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateEntryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).UpdateEntry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_UpdateEntry_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).UpdateEntry(ctx, req.(*UpdateEntryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SeaweedFiler_DeleteEntry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteEntryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).DeleteEntry(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_DeleteEntry_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).DeleteEntry(ctx, req.(*DeleteEntryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SeaweedFiler_AssignVolume_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AssignVolumeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).AssignVolume(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_AssignVolume_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).AssignVolume(ctx, req.(*AssignVolumeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SeaweedFiler_LookupVolume_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LookupVolumeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedFilerServer).LookupVolume(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SeaweedFiler_LookupVolume_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedFilerServer).LookupVolume(ctx, req.(*LookupVolumeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// SeaweedFiler_ServiceDesc is the grpc.ServiceDesc for SeaweedFiler service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var SeaweedFiler_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "filer_pb.SeaweedFiler", + HandlerType: (*SeaweedFilerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "LookupDirectoryEntry", + Handler: _SeaweedFiler_LookupDirectoryEntry_Handler, + }, + { + MethodName: "CreateEntry", + Handler: _SeaweedFiler_CreateEntry_Handler, + }, + { + MethodName: "UpdateEntry", + Handler: _SeaweedFiler_UpdateEntry_Handler, + }, + { + MethodName: "DeleteEntry", + Handler: _SeaweedFiler_DeleteEntry_Handler, + }, + { + MethodName: "AssignVolume", + Handler: _SeaweedFiler_AssignVolume_Handler, + }, + { + MethodName: "LookupVolume", + Handler: _SeaweedFiler_LookupVolume_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "filer_subset.proto", +} diff --git a/seaweed-block/core/frontend/chunkstore/remote.go b/seaweed-block/core/frontend/chunkstore/remote.go new file mode 100644 index 0000000000..12f8717dd7 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/remote.go @@ -0,0 +1,45 @@ +package chunkstore + +import ( + "context" + "errors" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" +) + +// Filer is the metadata side chunkstore needs from a SeaweedFS filer: one +// entry per volume HEAD (and per snapshot), written with a precondition. +// +// The two SeaweedFS failure styles are normalised here: +// - CreateEntry reports a failed o_excl / condition in the response's +// ErrorCode with a nil gRPC error; +// - UpdateEntry reports a failed expected_extended as gRPC FailedPrecondition. +// +// Both become ErrExists / ErrPrecondition so callers branch on one thing. +type Filer interface { + // LookupEntry returns ErrNotFound when dir/name does not exist. + LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry, error) + // CreateEntry with oExcl returns ErrExists when dir/name already exists. + CreateEntry(ctx context.Context, dir string, e *filerpb.Entry, oExcl bool) error + // UpdateEntry applies e only if every expected extended key still holds + // the given value; otherwise ErrPrecondition. ErrNotFound if absent. + UpdateEntry(ctx context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error +} + +// Blobs stores immutable chunk payloads as SeaweedFS needles. +type Blobs interface { + // Put stores data as a new needle and returns its fid. A fid is never + // reused, so a Put can never overwrite data another manifest references. + Put(ctx context.Context, data []byte) (fid string, err error) + // Get returns the whole needle payload. + Get(ctx context.Context, fid string) ([]byte, error) +} + +var ( + // ErrNotFound: the filer entry does not exist. + ErrNotFound = errors.New("chunkstore: entry not found") + // ErrExists: an exclusive create found the entry already there. + ErrExists = errors.New("chunkstore: entry already exists") + // ErrPrecondition: a conditional write lost (HEAD changed under us). + ErrPrecondition = errors.New("chunkstore: precondition failed") +) diff --git a/seaweed-block/core/frontend/chunkstore/swfs.go b/seaweed-block/core/frontend/chunkstore/swfs.go new file mode 100644 index 0000000000..eb7707a860 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/swfs.go @@ -0,0 +1,265 @@ +package chunkstore + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "strings" + "sync" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" +) + +// SWFSConfig configures the minimal SeaweedFS client. +type SWFSConfig struct { + FilerGRPC string // filer gRPC address, host:port (default: filer HTTP port + 10000) + Collection string // collection for chunk needles (empty = filer default / storage rule) + Replication string // replication for chunk needles (empty = filer default / storage rule) + AssignPath string // path passed to AssignVolume so filer storage rules (fsync, collection) apply + HTTPTimeout time.Duration +} + +// SWFS is a minimal SeaweedFS client built for the chunkstore PoC: +// - filer gRPC (vendored proto subset, package filerpb) for HEAD/snapshot +// entries, AssignVolume and LookupVolume; +// - plain HTTP to volume servers for needle upload (POST) and read (GET). +// +// It deliberately does not import the SeaweedFS module. +type SWFS struct { + cfg SWFSConfig + conn *grpc.ClientConn + fc filerpb.SeaweedFilerClient + http *http.Client + + mu sync.Mutex + vidCache map[string][]string // volume id -> volume server urls +} + +// filerNotFoundText is the text of seaweed-mono's filer_pb.ErrNotFound +// (pb/filer_pb/filer_pb_helper.go:261). LookupDirectoryEntry returns that raw +// sentinel, which crosses gRPC as codes.Unknown carrying only this text. +const filerNotFoundText = "no entry is found in filer store" + +// DialSWFS connects to the filer's gRPC port. The connection is lazy. +func DialSWFS(cfg SWFSConfig) (*SWFS, error) { + if cfg.FilerGRPC == "" { + return nil, errors.New("chunkstore: filer gRPC address required") + } + if cfg.HTTPTimeout == 0 { + cfg.HTTPTimeout = 60 * time.Second + } + conn, err := grpc.NewClient(cfg.FilerGRPC, + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(64<<20), grpc.MaxCallSendMsgSize(64<<20))) + if err != nil { + return nil, fmt.Errorf("chunkstore: dial filer %s: %w", cfg.FilerGRPC, err) + } + return &SWFS{ + cfg: cfg, + conn: conn, + fc: filerpb.NewSeaweedFilerClient(conn), + http: &http.Client{Timeout: cfg.HTTPTimeout}, + vidCache: map[string][]string{}, + }, nil +} + +// Close releases the gRPC connection. +func (c *SWFS) Close() error { + if c.conn == nil { + return nil + } + return c.conn.Close() +} + +// LookupEntry implements Filer. +func (c *SWFS) LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry, error) { + resp, err := c.fc.LookupDirectoryEntry(ctx, &filerpb.LookupDirectoryEntryRequest{Directory: dir, Name: name}) + if err != nil { + if st, ok := status.FromError(err); ok { + if st.Code() == codes.NotFound || + (st.Code() == codes.Unknown && strings.Contains(st.Message(), filerNotFoundText)) { + return nil, ErrNotFound + } + } + return nil, fmt.Errorf("chunkstore: lookup %s/%s: %w", dir, name, err) + } + if resp.GetEntry() == nil { + return nil, ErrNotFound + } + return resp.Entry, nil +} + +// CreateEntry implements Filer. A failed o_excl or condition is reported by +// the filer in CreateEntryResponse.ErrorCode with a nil gRPC error. +func (c *SWFS) CreateEntry(ctx context.Context, dir string, e *filerpb.Entry, oExcl bool) error { + resp, err := c.fc.CreateEntry(ctx, &filerpb.CreateEntryRequest{Directory: dir, Entry: e, OExcl: oExcl}) + if err != nil { + if status.Code(err) == codes.FailedPrecondition { + return fmt.Errorf("%w: create %s/%s: %v", ErrPrecondition, dir, e.GetName(), err) + } + return fmt.Errorf("chunkstore: create %s/%s: %w", dir, e.GetName(), err) + } + switch resp.GetErrorCode() { + case filerpb.FilerError_OK: + if resp.GetError() != "" { + return fmt.Errorf("chunkstore: create %s/%s: %s", dir, e.GetName(), resp.GetError()) + } + return nil + case filerpb.FilerError_ENTRY_ALREADY_EXISTS: + return fmt.Errorf("%w: %s/%s", ErrExists, dir, e.GetName()) + case filerpb.FilerError_PRECONDITION_FAILED: + return fmt.Errorf("%w: create %s/%s", ErrPrecondition, dir, e.GetName()) + default: + return fmt.Errorf("chunkstore: create %s/%s: %s (%s)", dir, e.GetName(), resp.GetError(), resp.GetErrorCode()) + } +} + +// UpdateEntry implements Filer. A failed expected_extended comes back as gRPC +// FailedPrecondition. Any other error is ambiguous (the write may or may not +// have applied) and is returned unwrapped from the sentinels. +func (c *SWFS) UpdateEntry(ctx context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error { + _, err := c.fc.UpdateEntry(ctx, &filerpb.UpdateEntryRequest{Directory: dir, Entry: e, ExpectedExtended: expected}) + if err == nil { + return nil + } + switch status.Code(err) { + case codes.FailedPrecondition: + return fmt.Errorf("%w: update %s/%s: %v", ErrPrecondition, dir, e.GetName(), err) + case codes.NotFound: + return fmt.Errorf("%w: update %s/%s", ErrNotFound, dir, e.GetName()) + } + return fmt.Errorf("chunkstore: update %s/%s: %w", dir, e.GetName(), err) +} + +// Put implements Blobs: filer AssignVolume, then a raw HTTP POST of data to +// the assigned volume server. The body is sent as application/octet-stream +// with no Content-Encoding, so the volume server stores it uncompressed (its +// auto-compress only fires for types it is sure about; octet-stream is +// cleared to "" first, storage/needle/needle_parse_upload.go:116-119). +func (c *SWFS) Put(ctx context.Context, data []byte) (string, error) { + ar, err := c.fc.AssignVolume(ctx, &filerpb.AssignVolumeRequest{ + Count: 1, + Collection: c.cfg.Collection, + Replication: c.cfg.Replication, + Path: c.cfg.AssignPath, + ExpectedDataSize: uint64(len(data)), + }) + if err != nil { + return "", fmt.Errorf("chunkstore: assign: %w", err) + } + if ar.GetError() != "" { + return "", fmt.Errorf("chunkstore: assign: %s", ar.GetError()) + } + if ar.GetFileId() == "" || ar.GetLocation().GetUrl() == "" { + return "", fmt.Errorf("chunkstore: assign returned no fid/location") + } + u := "http://" + ar.Location.Url + "/" + ar.FileId + if ar.GetFsync() { + u += "?fsync=true" + } + req, err := http.NewRequestWithContext(ctx, http.MethodPost, u, bytes.NewReader(data)) + if err != nil { + return "", err + } + req.Header.Set("Content-Type", "application/octet-stream") + if ar.GetAuth() != "" { + req.Header.Set("Authorization", "BEARER "+ar.Auth) + } + resp, err := c.http.Do(req) + if err != nil { + return "", fmt.Errorf("chunkstore: upload %s: %w", ar.FileId, err) + } + defer resp.Body.Close() + body, _ := io.ReadAll(io.LimitReader(resp.Body, 64<<10)) + if resp.StatusCode/100 != 2 { + return "", fmt.Errorf("chunkstore: upload %s: http %d: %s", ar.FileId, resp.StatusCode, strings.TrimSpace(string(body))) + } + var ur struct { + Error string `json:"error"` + } + if json.Unmarshal(body, &ur) == nil && ur.Error != "" { + return "", fmt.Errorf("chunkstore: upload %s: %s", ar.FileId, ur.Error) + } + return ar.FileId, nil +} + +// Get implements Blobs: resolve the fid's volume through the filer, then GET +// the needle from each location until one answers. +func (c *SWFS) Get(ctx context.Context, fid string) ([]byte, error) { + vid, _, ok := strings.Cut(fid, ",") + if !ok { + return nil, fmt.Errorf("chunkstore: bad fid %q", fid) + } + urls, err := c.lookupVolume(ctx, vid) + if err != nil { + return nil, err + } + var lastErr error + for _, host := range urls { + b, err := c.getFrom(ctx, host, fid) + if err == nil { + return b, nil + } + lastErr = err + } + c.mu.Lock() + delete(c.vidCache, vid) + c.mu.Unlock() + return nil, fmt.Errorf("chunkstore: read %s: %w", fid, lastErr) +} + +func (c *SWFS) getFrom(ctx context.Context, host, fid string) ([]byte, error) { + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+host+"/"+fid, nil) + if err != nil { + return nil, err + } + resp, err := c.http.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("http %d from %s", resp.StatusCode, host) + } + return io.ReadAll(resp.Body) +} + +func (c *SWFS) lookupVolume(ctx context.Context, vid string) ([]string, error) { + c.mu.Lock() + urls, ok := c.vidCache[vid] + c.mu.Unlock() + if ok && len(urls) > 0 { + return urls, nil + } + resp, err := c.fc.LookupVolume(ctx, &filerpb.LookupVolumeRequest{VolumeIds: []string{vid}}) + if err != nil { + return nil, fmt.Errorf("chunkstore: lookup volume %s: %w", vid, err) + } + for _, l := range resp.GetLocationsMap()[vid].GetLocations() { + if l.GetUrl() != "" { + urls = append(urls, l.Url) + } + } + if len(urls) == 0 { + return nil, fmt.Errorf("chunkstore: volume %s has no locations", vid) + } + c.mu.Lock() + c.vidCache[vid] = urls + c.mu.Unlock() + return urls, nil +} + +var ( + _ Filer = (*SWFS)(nil) + _ Blobs = (*SWFS)(nil) +) diff --git a/seaweed-block/core/frontend/chunkstore/swfs_test.go b/seaweed-block/core/frontend/chunkstore/swfs_test.go new file mode 100644 index 0000000000..748681e3a8 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/swfs_test.go @@ -0,0 +1,270 @@ +package chunkstore + +import ( + "bytes" + "context" + "errors" + "io" + "net" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" +) + +// fakeFilerGRPC answers the real gRPC method paths with canned replies so the +// client's error mapping is tested against both SeaweedFS failure styles. +type fakeFilerGRPC struct { + filerpb.UnimplementedSeaweedFilerServer + + mu sync.Mutex + createResp *filerpb.CreateEntryResponse + createErr error + updateErr error + lookupResp *filerpb.LookupDirectoryEntryResponse + lookupErr error + assignResp *filerpb.AssignVolumeResponse + lookupVol *filerpb.LookupVolumeResponse + + lastCreate *filerpb.CreateEntryRequest + lastUpdate *filerpb.UpdateEntryRequest + lastAssign *filerpb.AssignVolumeRequest +} + +func (f *fakeFilerGRPC) CreateEntry(_ context.Context, r *filerpb.CreateEntryRequest) (*filerpb.CreateEntryResponse, error) { + f.mu.Lock() + defer f.mu.Unlock() + f.lastCreate = r + if f.createErr != nil { + return nil, f.createErr + } + if f.createResp != nil { + return f.createResp, nil + } + return &filerpb.CreateEntryResponse{}, nil +} + +func (f *fakeFilerGRPC) UpdateEntry(_ context.Context, r *filerpb.UpdateEntryRequest) (*filerpb.UpdateEntryResponse, error) { + f.mu.Lock() + defer f.mu.Unlock() + f.lastUpdate = r + if f.updateErr != nil { + return nil, f.updateErr + } + return &filerpb.UpdateEntryResponse{}, nil +} + +func (f *fakeFilerGRPC) LookupDirectoryEntry(_ context.Context, r *filerpb.LookupDirectoryEntryRequest) (*filerpb.LookupDirectoryEntryResponse, error) { + f.mu.Lock() + defer f.mu.Unlock() + if f.lookupErr != nil { + return nil, f.lookupErr + } + return f.lookupResp, nil +} + +func (f *fakeFilerGRPC) AssignVolume(_ context.Context, r *filerpb.AssignVolumeRequest) (*filerpb.AssignVolumeResponse, error) { + f.mu.Lock() + defer f.mu.Unlock() + f.lastAssign = r + return f.assignResp, nil +} + +func (f *fakeFilerGRPC) LookupVolume(_ context.Context, r *filerpb.LookupVolumeRequest) (*filerpb.LookupVolumeResponse, error) { + f.mu.Lock() + defer f.mu.Unlock() + return f.lookupVol, nil +} + +func startFakeFiler(t *testing.T, f *fakeFilerGRPC) *SWFS { + t.Helper() + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + srv := grpc.NewServer() + filerpb.RegisterSeaweedFilerServer(srv, f) + go func() { _ = srv.Serve(lis) }() + t.Cleanup(srv.Stop) + c, err := DialSWFS(SWFSConfig{FilerGRPC: lis.Addr().String(), Collection: "swblock", Replication: "000", AssignPath: "/swblock/vols/v1"}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = c.Close() }) + return c +} + +func TestSWFS_CreateEntry_ErrorCodeStyle(t *testing.T) { + f := &fakeFilerGRPC{} + c := startFakeFiler(t, f) + ctx := context.Background() + + // CreateEntry reports o_excl loss in ErrorCode with a nil gRPC error + // (seaweed-mono server/filer_grpc_server.go CreateEntry). + f.createResp = &filerpb.CreateEntryResponse{Error: "exists", ErrorCode: filerpb.FilerError_ENTRY_ALREADY_EXISTS} + err := c.CreateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, true) + if !errors.Is(err, ErrExists) { + t.Fatalf("ENTRY_ALREADY_EXISTS: got %v want ErrExists", err) + } + if !f.lastCreate.OExcl { + t.Fatalf("o_excl not sent") + } + + f.createResp = &filerpb.CreateEntryResponse{Error: "precondition failed", ErrorCode: filerpb.FilerError_PRECONDITION_FAILED} + if err := c.CreateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, true); !errors.Is(err, ErrPrecondition) { + t.Fatalf("PRECONDITION_FAILED: got %v want ErrPrecondition", err) + } + + // Any other non-empty Error is still a failure, never silent success. + f.createResp = &filerpb.CreateEntryResponse{Error: "parent is a file", ErrorCode: filerpb.FilerError_PARENT_IS_FILE} + if err := c.CreateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, true); err == nil { + t.Fatalf("PARENT_IS_FILE: got nil error") + } + + f.createResp = &filerpb.CreateEntryResponse{} + if err := c.CreateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, true); err != nil { + t.Fatalf("ok create: %v", err) + } +} + +func TestSWFS_UpdateEntry_FailedPreconditionStyle(t *testing.T) { + f := &fakeFilerGRPC{} + c := startFakeFiler(t, f) + ctx := context.Background() + exp := map[string][]byte{"swb.gen": []byte("3"), "swb.epoch": []byte("1")} + + f.updateErr = status.Error(codes.FailedPrecondition, `extended attribute "swb.gen" changed`) + if err := c.UpdateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, exp); !errors.Is(err, ErrPrecondition) { + t.Fatalf("FailedPrecondition: got %v want ErrPrecondition", err) + } + if string(f.lastUpdate.ExpectedExtended["swb.gen"]) != "3" || string(f.lastUpdate.ExpectedExtended["swb.epoch"]) != "1" { + t.Fatalf("expected_extended not sent: %v", f.lastUpdate.ExpectedExtended) + } + + f.updateErr = status.Error(codes.NotFound, "not found /d/x") + if err := c.UpdateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, exp); !errors.Is(err, ErrNotFound) { + t.Fatalf("NotFound: got %v want ErrNotFound", err) + } + + f.updateErr = status.Error(codes.Unavailable, "down") + err := c.UpdateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, exp) + if err == nil || errors.Is(err, ErrPrecondition) || errors.Is(err, ErrNotFound) { + t.Fatalf("Unavailable: got %v, want a plain (ambiguous) error", err) + } + + f.updateErr = nil + if err := c.UpdateEntry(ctx, "/d", &filerpb.Entry{Name: "x"}, exp); err != nil { + t.Fatalf("ok update: %v", err) + } +} + +func TestSWFS_LookupEntry_NotFoundStyles(t *testing.T) { + f := &fakeFilerGRPC{} + c := startFakeFiler(t, f) + ctx := context.Background() + + // The filer returns its raw sentinel, which crosses gRPC as Unknown. + f.lookupErr = errors.New("filer: no entry is found in filer store") + if _, err := c.LookupEntry(ctx, "/d", "x"); !errors.Is(err, ErrNotFound) { + t.Fatalf("Unknown+sentinel: got %v want ErrNotFound", err) + } + f.lookupErr = status.Error(codes.NotFound, "nope") + if _, err := c.LookupEntry(ctx, "/d", "x"); !errors.Is(err, ErrNotFound) { + t.Fatalf("NotFound: got %v want ErrNotFound", err) + } + f.lookupErr = nil + f.lookupResp = &filerpb.LookupDirectoryEntryResponse{Entry: &filerpb.Entry{Name: "x", Content: []byte("m")}} + e, err := c.LookupEntry(ctx, "/d", "x") + if err != nil || string(e.Content) != "m" { + t.Fatalf("found: %v %v", e, err) + } +} + +func TestSWFS_PutGet_RawUncompressedUpload(t *testing.T) { + var ( + mu sync.Mutex + stored = map[string][]byte{} + gotReq *http.Request + ) + vol := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fid := strings.TrimPrefix(r.URL.Path, "/") + mu.Lock() + defer mu.Unlock() + switch r.Method { + case http.MethodPost: + gotReq = r.Clone(context.Background()) + b, _ := io.ReadAll(r.Body) + stored[fid] = b + w.WriteHeader(http.StatusCreated) + _, _ = w.Write([]byte(`{"size":` + "1" + `}`)) + case http.MethodGet: + b, ok := stored[fid] + if !ok { + w.WriteHeader(http.StatusNotFound) + return + } + _, _ = w.Write(b) + } + })) + defer vol.Close() + host := strings.TrimPrefix(vol.URL, "http://") + + f := &fakeFilerGRPC{ + assignResp: &filerpb.AssignVolumeResponse{FileId: "7,01abcdef", Auth: "tok", Fsync: true, Location: &filerpb.Location{Url: host}}, + lookupVol: &filerpb.LookupVolumeResponse{LocationsMap: map[string]*filerpb.Locations{"7": {Locations: []*filerpb.Location{{Url: host}}}}}, + } + c := startFakeFiler(t, f) + ctx := context.Background() + // Text-looking data: must still go up raw (no gzip, no type sniffing). + data := bytes.Repeat([]byte("hello world\n"), 1000) + fid, err := c.Put(ctx, data) + if err != nil { + t.Fatal(err) + } + if fid != "7,01abcdef" { + t.Fatalf("fid %q", fid) + } + if f.lastAssign.Collection != "swblock" || f.lastAssign.Path != "/swblock/vols/v1" || f.lastAssign.Count != 1 { + t.Fatalf("assign request %+v", f.lastAssign) + } + mu.Lock() + r := gotReq + mu.Unlock() + if r.URL.Query().Get("fsync") != "true" { + t.Fatalf("fsync not carried onto upload: %s", r.URL.RawQuery) + } + if ct := r.Header.Get("Content-Type"); ct != "application/octet-stream" { + t.Fatalf("content-type %q", ct) + } + if ce := r.Header.Get("Content-Encoding"); ce != "" { + t.Fatalf("content-encoding %q, want none", ce) + } + if a := r.Header.Get("Authorization"); a != "BEARER tok" { + t.Fatalf("authorization %q", a) + } + got, err := c.Get(ctx, fid) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(got, data) { + t.Fatalf("get mismatch") + } + if _, err := c.Get(ctx, "7,0000dead"); err == nil { + t.Fatalf("get of missing fid returned nil error") + } +} + +func TestSWFS_Put_AssignErrorIsFailure(t *testing.T) { + f := &fakeFilerGRPC{assignResp: &filerpb.AssignVolumeResponse{Error: "no free volumes"}} + c := startFakeFiler(t, f) + if _, err := c.Put(context.Background(), []byte("x")); err == nil { + t.Fatalf("assign error swallowed") + } +}