fstree: Handle incomplete writes #1600

Merged
dstepanov-yadro merged 1 commit from fyrchik/frostfs-node:fix-fstree-write into master 2025-01-15 07:01:14 +00:00
Owner

The test is below, but it requires mounting, so I desided to not add it to code.

func TestENOSPC(t *testing.T) {
	dir, err := os.MkdirTemp(t.TempDir(), "ramdisk")
	require.NoError(t, err)

	f, err := os.CreateTemp(t.TempDir(), "ramdisk_*")
	require.NoError(t, err)

	defer func() {
		require.NoError(t, unix.Unmount(dir, 0))
	}()
	require.NoError(t, unix.Mount(f.Name(), dir, "tmpfs", 0, "size=1M"))

	fst := New(WithPath(dir), WithDepth(1))
	require.NoError(t, fst.Open(mode.ComponentReadWrite))
	require.NoError(t, fst.Init())

	_, err = fst.Put(context.Background(), common.PutPrm{
		RawData: make([]byte, 10<<20),
	})
	spew.Dump(err)
	require.ErrorIs(t, err, common.ErrNoSpace)
}
The test is below, but it requires mounting, so I desided to not add it to code. ```go func TestENOSPC(t *testing.T) { dir, err := os.MkdirTemp(t.TempDir(), "ramdisk") require.NoError(t, err) f, err := os.CreateTemp(t.TempDir(), "ramdisk_*") require.NoError(t, err) defer func() { require.NoError(t, unix.Unmount(dir, 0)) }() require.NoError(t, unix.Mount(f.Name(), dir, "tmpfs", 0, "size=1M")) fst := New(WithPath(dir), WithDepth(1)) require.NoError(t, fst.Open(mode.ComponentReadWrite)) require.NoError(t, fst.Init()) _, err = fst.Put(context.Background(), common.PutPrm{ RawData: make([]byte, 10<<20), }) spew.Dump(err) require.ErrorIs(t, err, common.ErrNoSpace) } ```
requested reviews from storage-core-committers, storage-core-developers 2025-01-14 10:50:01 +00:00
fyrchik force-pushed fix-fstree-write from 019cda8fba to 4843882853 2025-01-14 10:56:05 +00:00 Compare
fyrchik force-pushed fix-fstree-write from 4843882853 to 01acf72835 2025-01-14 10:57:27 +00:00 Compare
fyrchik force-pushed fix-fstree-write from 01acf72835 to 2bc86b5982 2025-01-14 11:11:39 +00:00 Compare
acid-ant approved these changes 2025-01-14 11:12:29 +00:00
Dismissed
fyrchik force-pushed fix-fstree-write from 2bc86b5982 to 85f369c076 2025-01-14 11:13:06 +00:00 Compare
fyrchik dismissed acid-ant's review 2025-01-14 11:13:11 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

dstepanov-yadro reviewed 2025-01-14 11:24:47 +00:00
@ -73,3 +74,2 @@
n, err := unix.Write(fd, data)
if err == nil {
if n == len(data) {
for err == nil {

Does frostfs-node write to socket or pipe? Looks like for loop is redundant.

Does frostfs-node write to `socket or pipe`? Looks like `for` loop is redundant.
Author
Owner

I find it more robust -- I am not sure it is completely impossible to get multiple incomplete writes (like with some network-mounted filesystem)

I find it more robust -- I am not sure it is completely impossible to get multiple incomplete writes (like with some network-mounted filesystem)

Then there is an error:
len(data)=10
loop 1:
n == 3, err == nil
written = 3
n, err = unix.Write(fd, data[3:])
n == 4, err == nil
loop 2:
n = 4
written = 7
n, err = unix.Write(fd, data[4:]) <--- oops!

Then there is an error: len(data)=10 loop 1: n == 3, err == nil written = 3 `n, err = unix.Write(fd, data[3:])` n == 4, err == nil loop 2: n = 4 written = 7 `n, err = unix.Write(fd, data[4:])` <--- oops!
Author
Owner

missed during refactoring, fixed!

missed during refactoring, fixed!
Author
Owner

good catch!

good catch!
acid-ant approved these changes 2025-01-14 11:36:27 +00:00
Dismissed
fyrchik force-pushed fix-fstree-write from 85f369c076 to 05fd999162 2025-01-14 11:52:41 +00:00 Compare
fyrchik dismissed acid-ant's review 2025-01-14 11:52:41 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

dstepanov-yadro approved these changes 2025-01-14 12:21:10 +00:00
a-savchuk approved these changes 2025-01-14 12:21:22 +00:00
aarifullin approved these changes 2025-01-14 12:27:38 +00:00
dstepanov-yadro merged commit 05fd999162 into master 2025-01-15 07:01:14 +00:00
fyrchik deleted branch fix-fstree-write 2025-01-15 10:06:31 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#1600
No description provided.