[sheepdog] [PATCH 5/7 v4 UPDATE] sheep: rename journal_file.c as journal.c

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Apr 5 10:42:01 CEST 2013


> +/* FIXME: Try not sleep inside lock */
> +static void switch_journal_file(void)
> +{
> +	int old = jfile.fd, err;
> +	pthread_t thread;
> +
> +retry:
> +	if (!uatomic_set_true(&jfile.in_commit)) {
> +		sd_eprintf("journal file in committing, "
> +			   "you might need enlarge jfile size");
> +		usleep(100000); /* Wait until committing is finished */
> +		goto retry;
> +	}
>  
> -		ret = xpread(jd.fd, &end_mark, sizeof(end_mark),
> -				sizeof(jd.head) + jd.head.size);
> -		if (ret != sizeof(end_mark)) {
> -			sd_eprintf("can't read journal end mark for object %s",
> -				   jd.head.target_path);
> -			goto end_while_2;
> -		}
> +	if (old == jfile_fds[0])
> +		jfile.fd = jfile_fds[1];
> +	else
> +		jfile.fd = jfile_fds[0];
> +	jfile.commit_fd = old;
> +	jfile.pos = 0;
>  
> -		if (end_mark != JRNL_END_MARK)
> -			goto end_while_2;
> +	err = pthread_create(&thread, NULL, commit_data, NULL);

Creating the thread when switch_journal_file() would produce
unnecessary cost. The thread should be created at initialization
sequence. Then switch_journal_file() can invoke the work of the thread
via pthread_cond_signal(), etc.

Thanks,
Hitoshi



More information about the sheepdog mailing list