Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append data and becomes bigger than block_size/2 #17

Open
palainp opened this issue Oct 6, 2022 · 1 comment
Open

Append data and becomes bigger than block_size/2 #17

palainp opened this issue Oct 6, 2022 · 1 comment

Comments

@palainp
Copy link
Contributor

palainp commented Oct 6, 2022

Hi, not sure how to translate that into the dune tests but I ran into an issue with the following C code when writing onto a chamelon fs:

#include <stdio.h>
#include <assert.h>
#include <string.h>

#define BLOC_SIZE 512
#define FN "test.bin"

char small[BLOC_SIZE/4-1];
char addi[BLOC_SIZE];

int main()
{
	FILE* fd;

	for (size_t i=0; i<sizeof(small); ++i)
		small[i]='#';

	for (size_t i=0; i<sizeof(addi); ++i)
		addi[i]='@';

	// create a "just a bit under quarter block_size" file
	assert((fd = fopen(FN, "r+")) != NULL);
	assert(fwrite(small, sizeof(char), sizeof(small), fd) == sizeof(small));
	assert(fflush(fd) == 0);
	assert(fclose(fd) == 0);

	// now append data at the end of FN
	assert((fd = fopen(FN, "r+")) != NULL);
	assert(fseek(fd, sizeof(small), SEEK_SET)!=-1);
	assert(fwrite(addi, sizeof(char), sizeof(addi), fd) == sizeof(addi));
	assert(fflush(fd) == 0);
	assert(fclose(fd) == 0);

	return 0;
}

This is my bumb function for set_partial, this is use for both fwrite calls (with offset arguments at 0, and block_size/4 respectively):

  let write root path ~offset newdata_length newdata =
    let pathkey = Mirage_kv.Key.v path in
    get_before root pathkey offset >>= fun before ->
    Log.warn (fun f -> f "got %d bytes before offset %d" (Cstruct.length before) offset) ;
    get_after root pathkey (offset+newdata_length) >>= fun after ->
    Log.warn (fun f -> f "got %d bytes after offset %d" (Cstruct.length after) (offset+newdata_length)) ;

    let newdata = Cstruct.concat [before; newdata; after] in
    Log.warn (fun f -> f "will write %d bytes" (Cstruct.length newdata)) ;
    Chamelon.remove root pathkey >>*= fun () ->
    Log.warn (fun f -> f "old file is now removed" ) ;
    Chamelon.set root pathkey (Cstruct.to_string newdata) >>*= fun () ->
    Log.warn (fun f -> f "new file is now created" ) ;
    Lwt.return_unit

So far the debug logs I got are (melt with mines, I put some comments below to help understanding):

2022-10-06 19:48:19 +02:00: DBG [sshfs_protocol] [SSH_FXP_WRITE 17] '/test.bin' @127 (512) <- this is the 2nd fwrite call (append data)

2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] name "test.bin" is associated with id 4 on blockpair 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] after compaction, there were 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 3 entries with name test.bin
2022-10-06 19:48:19 +02:00: WRN [sshfs_fs] got 127 bytes before offset 127 <- this is the log call after the first get_partial
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] getting size on key /test.bin
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] name "test.bin" is associated with id 4 on blockpair 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] after compaction, there were 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 1 entries with name test.bin
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] name "test.bin" is associated with id 4 on blockpair 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] after compaction, there were 3 entries for id 4 in 0,
1
2022-10-06 19:48:19 +02:00: DBG [chamelon-fs] found 3 entries with name test.bin <- and hangs

Don't hesitate to ask me for any other helpful information :)

@palainp
Copy link
Contributor Author

palainp commented Oct 7, 2022

Update: I just tried to show the value returned by the size call on the line [chamelon-fs] getting size on key /test.bin and it's 512 (the block size), which totally makes sense!
To explain a bit the situation, before the hangs I have test.bin (size=512B, usefull data=127B), I try to append some data at the end (512).

  • I read from 0 to 127 (read_before)
  • I read from 127+512 (=offset+new_data_length) to 512 (=size) : it hangs

I try with various append sized data, and it turns out that when the final size (real size + appending size) is above half a block it hangs :(

@palainp palainp changed the title Append data and becomes bigger than block_size/4 Append data and becomes bigger than block_size/2 Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant