@@ -13,14 +13,15 @@ typedef struct DFSRandomAccessFile {
13
13
DAOS_FILE daos_file;
14
14
std::vector<ReadBuffer> buffers;
15
15
daos_size_t file_size;
16
- DFSRandomAccessFile (std::string dfs_path, dfs_t * file_system,
17
- daos_handle_t eqh , dfs_obj_t * obj)
16
+ daos_handle_t mEventQueueHandle {};
17
+ DFSRandomAccessFile (std::string dfs_path, dfs_t * file_system , dfs_obj_t * obj)
18
18
: dfs_path(std::move(dfs_path)) {
19
19
daos_fs = file_system;
20
20
daos_file.file = obj;
21
21
dfs_get_size (daos_fs, obj, &file_size);
22
22
size_t num_of_buffers;
23
23
size_t buff_size;
24
+ int rc = daos_eq_create (&mEventQueueHandle );
24
25
25
26
if (char * env_num_of_buffers = std::getenv (" TF_IO_DAOS_NUM_OF_BUFFERS" )) {
26
27
num_of_buffers = atoi (env_num_of_buffers);
@@ -34,16 +35,18 @@ typedef struct DFSRandomAccessFile {
34
35
buff_size = BUFF_SIZE;
35
36
}
36
37
for (size_t i = 0 ; i < num_of_buffers; i++) {
37
- buffers.push_back (ReadBuffer (i, eqh , buff_size));
38
+ buffers.push_back (ReadBuffer (i, mEventQueueHandle , buff_size));
38
39
}
39
40
}
40
41
} DFSRandomAccessFile;
41
42
42
43
void Cleanup (TF_RandomAccessFile* file) {
43
44
auto dfs_file = static_cast <DFSRandomAccessFile*>(file->plugin_file );
44
- for (auto & read_buf : dfs_file->buffers ) {
45
- read_buf. AbortEvent ();
45
+ for (auto & buffer : dfs_file->buffers ) {
46
+ buffer. FinalizeEvent ();
46
47
}
48
+
49
+ daos_eq_destroy (dfs_file->mEventQueueHandle , 0 );
47
50
dfs_release (dfs_file->daos_file .file );
48
51
dfs_file->daos_fs = nullptr ;
49
52
delete dfs_file;
@@ -52,7 +55,11 @@ void Cleanup(TF_RandomAccessFile* file) {
52
55
int64_t Read (const TF_RandomAccessFile* file, uint64_t offset, size_t n,
53
56
char * ret, TF_Status* status) {
54
57
auto dfs_file = static_cast <DFSRandomAccessFile*>(file->plugin_file );
55
- if (offset > dfs_file->file_size ) return -1 ;
58
+ if (offset > dfs_file->file_size ) {
59
+ TF_SetStatus (status, TF_OUT_OF_RANGE, " " );
60
+ return -1 ;
61
+ }
62
+
56
63
size_t ret_offset = 0 ;
57
64
size_t curr_offset = offset;
58
65
int64_t total_bytes = 0 ;
@@ -61,7 +68,7 @@ int64_t Read(const TF_RandomAccessFile* file, uint64_t offset, size_t n,
61
68
size_t read_bytes = 0 ;
62
69
for (auto & read_buf : dfs_file->buffers ) {
63
70
if (read_buf.CacheHit (curr_offset)) {
64
- read_bytes = read_buf.CopyFromCache (ret, ret_offset, offset , n,
71
+ read_bytes = read_buf.CopyFromCache (ret, ret_offset, curr_offset , n,
65
72
dfs_file->file_size , status);
66
73
}
67
74
}
@@ -92,6 +99,12 @@ int64_t Read(const TF_RandomAccessFile* file, uint64_t offset, size_t n,
92
99
ret_offset += read_bytes;
93
100
total_bytes += read_bytes;
94
101
n -= read_bytes;
102
+
103
+ if (curr_offset >= dfs_file->file_size ) {
104
+ for (size_t i = 0 ; i < dfs_file->buffers .size (); i++) {
105
+ dfs_file->buffers [i].WaitEvent ();
106
+ }
107
+ }
95
108
}
96
109
97
110
return total_bytes;
@@ -227,8 +240,8 @@ void NewRandomAccessFile(const TF_Filesystem* filesystem, const char* path,
227
240
TF_SetStatus (status, TF_INTERNAL, " Error initializng DAOS API" );
228
241
return ;
229
242
}
230
- auto random_access_file = new tf_random_access_file::DFSRandomAccessFile (
231
- path, daos->daos_fs , daos-> mEventQueueHandle , obj);
243
+ auto random_access_file =
244
+ new tf_random_access_file::DFSRandomAccessFile ( path, daos->daos_fs , obj);
232
245
random_access_file->buffers [0 ].ReadAsync (
233
246
daos->daos_fs , random_access_file->daos_file .file , 0 );
234
247
file->plugin_file = random_access_file;
0 commit comments