mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
filer: carry a create's fsync request in CreateEntryRequest
The per-request fsync is a context mark on the receiving filer, so a create forwarded to another filer lost it. CreateEntry now applies the request's fsync flag to its store write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8d652cc10
commit
f0928124ec
6 files changed
+111
-8
No files matched your search
@@ -262,6 +262,8 @@ message CreateEntryRequest {
|
||||
// Set on a create a filer forwarded to the entry's ring owner, so the owner
|
||||
// applies it locally instead of forwarding again. Clients leave it unset.
|
||||
bool is_moved = 8;
|
||||
// The store write must be durable before the reply, as for ?fsync=true.
|
||||
bool fsync = 9;
|
||||
}
|
||||
|
||||
// WriteCondition is the precondition the filer evaluates against the existing
|
||||
|
||||
@@ -262,6 +262,8 @@ message CreateEntryRequest {
|
||||
// Set on a create a filer forwarded to the entry's ring owner, so the owner
|
||||
// applies it locally instead of forwarding again. Clients leave it unset.
|
||||
bool is_moved = 8;
|
||||
// The store write must be durable before the reply, as for ?fsync=true.
|
||||
bool fsync = 9;
|
||||
}
|
||||
|
||||
// WriteCondition is the precondition the filer evaluates against the existing
|
||||
|
||||
@@ -1398,7 +1398,9 @@ type CreateEntryRequest struct {
|
||||
Condition *WriteCondition `protobuf:"bytes,7,opt,name=condition,proto3" json:"condition,omitempty"`
|
||||
// Set on a create a filer forwarded to the entry's ring owner, so the owner
|
||||
// applies it locally instead of forwarding again. Clients leave it unset.
|
||||
IsMoved bool `protobuf:"varint,8,opt,name=is_moved,json=isMoved,proto3" json:"is_moved,omitempty"`
|
||||
IsMoved bool `protobuf:"varint,8,opt,name=is_moved,json=isMoved,proto3" json:"is_moved,omitempty"`
|
||||
// The store write must be durable before the reply, as for ?fsync=true.
|
||||
Fsync bool `protobuf:"varint,9,opt,name=fsync,proto3" json:"fsync,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -1489,6 +1491,13 @@ func (x *CreateEntryRequest) GetIsMoved() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *CreateEntryRequest) GetFsync() bool {
|
||||
if x != nil {
|
||||
return x.Fsync
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// WriteCondition is the precondition the filer evaluates against the existing
|
||||
// entry before writing, under the per-path lock. A failed condition returns
|
||||
// FilerError PRECONDITION_FAILED. The client maps request semantics (e.g. RFC
|
||||
@@ -7492,7 +7501,7 @@ const file_filer_proto_rawDesc = "" +
|
||||
"\bctime_ns\x18\x14 \x01(\x05R\actimeNs\x12\x1b\n" +
|
||||
"\tcrtime_ns\x18\x15 \x01(\x05R\bcrtimeNs\x12\x14\n" +
|
||||
"\x05atime\x18\x16 \x01(\x03R\x05atime\x12\x19\n" +
|
||||
"\batime_ns\x18\x17 \x01(\x05R\aatimeNs\"\xd5\x02\n" +
|
||||
"\batime_ns\x18\x17 \x01(\x05R\aatimeNs\"\xeb\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" +
|
||||
@@ -7503,7 +7512,8 @@ const file_filer_proto_rawDesc = "" +
|
||||
"signatures\x12=\n" +
|
||||
"\x1bskip_check_parent_directory\x18\x06 \x01(\bR\x18skipCheckParentDirectory\x126\n" +
|
||||
"\tcondition\x18\a \x01(\v2\x18.filer_pb.WriteConditionR\tcondition\x12\x19\n" +
|
||||
"\bis_moved\x18\b \x01(\bR\aisMoved\"\x9e\x05\n" +
|
||||
"\bis_moved\x18\b \x01(\bR\aisMoved\x12\x14\n" +
|
||||
"\x05fsync\x18\t \x01(\bR\x05fsync\"\x9e\x05\n" +
|
||||
"\x0eWriteCondition\x129\n" +
|
||||
"\aclauses\x18\x01 \x03(\v2\x1f.filer_pb.WriteCondition.ClauseR\aclauses\x1a\xc9\x02\n" +
|
||||
"\x06Clause\x121\n" +
|
||||
|
||||
@@ -1019,6 +1019,16 @@ func (m *CreateEntryRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) {
|
||||
i -= len(m.unknownFields)
|
||||
copy(dAtA[i:], m.unknownFields)
|
||||
}
|
||||
if m.Fsync {
|
||||
i--
|
||||
if m.Fsync {
|
||||
dAtA[i] = 1
|
||||
} else {
|
||||
dAtA[i] = 0
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x48
|
||||
}
|
||||
if m.IsMoved {
|
||||
i--
|
||||
if m.IsMoved {
|
||||
@@ -7092,6 +7102,9 @@ func (m *CreateEntryRequest) SizeVT() (n int) {
|
||||
if m.IsMoved {
|
||||
n += 2
|
||||
}
|
||||
if m.Fsync {
|
||||
n += 2
|
||||
}
|
||||
n += len(m.unknownFields)
|
||||
return n
|
||||
}
|
||||
@@ -12350,6 +12363,26 @@ func (m *CreateEntryRequest) UnmarshalVT(dAtA []byte) error {
|
||||
}
|
||||
}
|
||||
m.IsMoved = bool(v != 0)
|
||||
case 9:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Fsync", wireType)
|
||||
}
|
||||
var v int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protohelpers.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Fsync = bool(v != 0)
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := protohelpers.Skip(dAtA[iNdEx:])
|
||||
|
||||
@@ -283,6 +283,9 @@ func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntr
|
||||
existing = current
|
||||
}
|
||||
|
||||
if req.Fsync {
|
||||
ctx = filer.WithSyncWrite(ctx)
|
||||
}
|
||||
ctx, eventSink := filer.WithMetadataEventSink(ctx)
|
||||
createErr := fs.filer.CreateEntry(ctx, newEntry, existing, req.OExcl, req.IsFromOtherCluster, req.Signatures, req.SkipCheckParentDirectory, so.MaxFileNameLength)
|
||||
|
||||
|
||||
@@ -48,18 +48,52 @@ func (s *appendRaceFindHookStore) setHook(hook func(p util.FullPath)) {
|
||||
s.hookMu.Unlock()
|
||||
}
|
||||
|
||||
// appendRaceSyncStore records, per path, whether each entry write was asked
|
||||
// to be durable before returning.
|
||||
type appendRaceSyncStore struct {
|
||||
*renameTestStore
|
||||
mu sync.Mutex
|
||||
synced map[util.FullPath][]bool
|
||||
}
|
||||
|
||||
func (s *appendRaceSyncStore) record(ctx context.Context, p util.FullPath) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.synced[p] = append(s.synced[p], filer.SyncWrite(ctx))
|
||||
}
|
||||
|
||||
func (s *appendRaceSyncStore) writes(p util.FullPath) []bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return append([]bool(nil), s.synced[p]...)
|
||||
}
|
||||
|
||||
func (s *appendRaceSyncStore) InsertEntry(ctx context.Context, entry *filer.Entry) error {
|
||||
s.record(ctx, entry.FullPath)
|
||||
return s.renameTestStore.InsertEntry(ctx, entry)
|
||||
}
|
||||
|
||||
func (s *appendRaceSyncStore) UpdateEntry(ctx context.Context, entry *filer.Entry) error {
|
||||
s.record(ctx, entry.FullPath)
|
||||
return s.renameTestStore.UpdateEntry(ctx, entry)
|
||||
}
|
||||
|
||||
// newAppendRaceFilers starts two gRPC-serving filers on one store with the same
|
||||
// two-member ring. Only the second filer's reads run the hook.
|
||||
func newAppendRaceFilers(t *testing.T) (owner, other *FilerServer, store *appendRaceFindHookStore) {
|
||||
// two-member ring. Only the second filer's reads run the hook; ownerWrites
|
||||
// records the first filer's entry writes.
|
||||
func newAppendRaceFilers(t *testing.T) (owner, other *FilerServer, store *appendRaceFindHookStore, ownerWrites *appendRaceSyncStore) {
|
||||
t.Helper()
|
||||
inner := newRenameTestStore()
|
||||
inner.entries["/"] = newDirectoryEntry("/", 1)
|
||||
store = &appendRaceFindHookStore{renameTestStore: inner}
|
||||
ownerWrites = &appendRaceSyncStore{renameTestStore: inner, synced: map[util.FullPath][]bool{}}
|
||||
|
||||
newServer := func(hooked bool) (*FilerServer, net.Listener) {
|
||||
f := newRenameTestFiler(t, inner)
|
||||
if hooked {
|
||||
f.Store = filer.NewFilerStoreWrapper(store)
|
||||
} else {
|
||||
f.Store = filer.NewFilerStoreWrapper(ownerWrites)
|
||||
}
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
@@ -92,7 +126,7 @@ func newAppendRaceFilers(t *testing.T) (owner, other *FilerServer, store *append
|
||||
t.Cleanup(srv.Stop)
|
||||
pb.InvalidateGrpcConnection(self.ToGrpcAddress())
|
||||
}
|
||||
return owner, other, store
|
||||
return owner, other, store, ownerWrites
|
||||
}
|
||||
|
||||
// ownerPath returns a file path whose writes the ring gives to owner.
|
||||
@@ -133,7 +167,7 @@ func httpAppendWithConcurrentAppend(t *testing.T, atRead int) bool {
|
||||
appendA := []byte("A-")
|
||||
appendB := []byte("B-")
|
||||
|
||||
owner, fs, store := newAppendRaceFilers(t)
|
||||
owner, fs, store, _ := newAppendRaceFilers(t)
|
||||
filePath := ownerPath(t, owner, fs)
|
||||
fileName := util.FullPath(filePath).Name()
|
||||
if err := store.renameTestStore.InsertEntry(ctx, &filer.Entry{
|
||||
@@ -226,7 +260,7 @@ func httpAppendWithConcurrentAppend(t *testing.T, atRead int) bool {
|
||||
// owner and lands in full.
|
||||
func TestHttpAppendOnNonOwnerCommitsThroughOwner(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
owner, fs, store := newAppendRaceFilers(t)
|
||||
owner, fs, store, _ := newAppendRaceFilers(t)
|
||||
filePath := ownerPath(t, owner, fs)
|
||||
fileName := util.FullPath(filePath).Name()
|
||||
if err := store.renameTestStore.InsertEntry(ctx, &filer.Entry{
|
||||
@@ -257,3 +291,22 @@ func TestHttpAppendOnNonOwnerCommitsThroughOwner(t *testing.T) {
|
||||
t.Fatalf("entry is %q, want %q", got, "old-A-")
|
||||
}
|
||||
}
|
||||
|
||||
// A create that asks for fsync reaches the store as a sync write.
|
||||
func TestCreateEntryFsyncReachesStore(t *testing.T) {
|
||||
owner, _, _, ownerWrites := newAppendRaceFilers(t)
|
||||
for _, fsync := range []bool{false, true} {
|
||||
p := util.FullPath(fmt.Sprintf("/fsync-%v.txt", fsync))
|
||||
resp, err := owner.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
|
||||
Directory: "/",
|
||||
Entry: &filer_pb.Entry{Name: p.Name(), Attributes: &filer_pb.FuseAttributes{Mtime: 1, FileMode: 0640}},
|
||||
Fsync: fsync,
|
||||
})
|
||||
if err != nil || resp.Error != "" {
|
||||
t.Fatalf("create %s: %v %s", p, err, resp.GetError())
|
||||
}
|
||||
if got := ownerWrites.writes(p); len(got) != 1 || got[0] != fsync {
|
||||
t.Errorf("fsync=%v: the store writes asked for sync %v, want [%v]", fsync, got, fsync)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user