Skip to content

Commit 99bd5a1

Browse files
authored
Vine: Specific error cases for vine_fetch_file (#4192)
* Add specific errno values for various failure cases of vine_fetch_file. * format
1 parent a23f75c commit 99bd5a1

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

taskvine/src/manager/taskvine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ whose contents are not returned to the manager by default.
907907
@param m A manager object
908908
@param f A file object.
909909
@return A pointer to the contents of the file. This will be freed with the file object.
910+
On error, returns NULL with errno set to: ENOENT if the file was not yet created,
911+
EAGAIN is the fetch failed but can be tried again, EIO if some unexpected I/O error occured.
910912
*/
911913

912914
const char *vine_fetch_file(struct vine_manager *m, struct vine_file *f);

taskvine/src/manager/vine_manager.c

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6613,38 +6613,67 @@ struct vine_file *vine_declare_chirp(
66136613
return vine_manager_declare_file(m, t);
66146614
}
66156615

6616+
/*
6617+
Return the contents of a vine_file as a memory buffer.
6618+
If the content is not available, set errno in one of three ways:
6619+
ENOENT - file has not been created yet
6620+
EAGAIN - file has been created, but not currently available, try again.
6621+
EIO - something more serious went wrong.
6622+
*/
6623+
66166624
const char *vine_fetch_file(struct vine_manager *m, struct vine_file *f)
66176625
{
6626+
/* If the file should not exist yet, bail out quickly. */
6627+
if (f->state == VINE_FILE_STATE_PENDING) {
6628+
errno = ENOENT;
6629+
return 0;
6630+
}
6631+
66186632
/* If the data has already been loaded, just return it. */
6619-
if (f->data)
6633+
if (f->data) {
66206634
return f->data;
6635+
}
6636+
6637+
/* Now consider the various ways to get the file content. */
66216638

66226639
switch (f->type) {
66236640
case VINE_FILE:
6624-
/* If it is on the local filesystem, load it. */
6641+
/* It should already be on the local filesystem */
66256642
{
66266643
size_t length;
66276644
if (copy_file_to_buffer(f->source, &f->data, &length)) {
66286645
return f->data;
66296646
} else {
6647+
/* something went wrong in loading the file. */
6648+
errno = EIO;
66306649
return 0;
66316650
}
66326651
}
66336652
break;
66346653
case VINE_BUFFER:
6635-
/* Buffer files will already have their contents in memory, if available. */
6636-
return f->data;
6637-
break;
6654+
/* We shouldn't get here: f->data should be filled when file created. */
6655+
errno = EIO;
6656+
return 0;
66386657
case VINE_TEMP:
66396658
case VINE_URL:
66406659
case VINE_MINI_TASK:
66416660
/* If the file has been materialized remotely, go get it from a worker. */
66426661
{
66436662
struct vine_worker_info *w = vine_file_replica_table_find_worker(m, f->cached_name);
6644-
if (w)
6663+
if (w) {
66456664
vine_manager_get_single_file(m, w, f);
6646-
/* If that succeeded, then f->data is now set, null otherwise. */
6647-
return f->data;
6665+
if (f->data) {
6666+
return f->data;
6667+
} else {
6668+
/* Something went wrong in fetching a good replica. */
6669+
errno = EIO;
6670+
return 0;
6671+
}
6672+
} else {
6673+
/* No replicas were currently available, but you can try again later. */
6674+
errno = EAGAIN;
6675+
return 0;
6676+
}
66486677
}
66496678
break;
66506679
}

0 commit comments

Comments
 (0)