Skip to content

Commit 6b9b5ea

Browse files
committed
lock files shared between library and scripts
1 parent 03dbb84 commit 6b9b5ea

File tree

10 files changed

+43
-21
lines changed

10 files changed

+43
-21
lines changed

src/scr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ int SCR_Init()
21202120
if (scr_my_rank_world == 0) {
21212121
kvtree* nodes_hash = kvtree_new();
21222122
kvtree_util_set_int(nodes_hash, SCR_NODES_KEY_NODES, num_nodes);
2123-
kvtree_write_path(scr_nodes_file, nodes_hash);
2123+
kvtree_write_path_locked(scr_nodes_file, nodes_hash);
21242124
kvtree_delete(&nodes_hash);
21252125
}
21262126

src/scr_flush_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ int main (int argc, char *argv[])
220220
kvtree* hash = kvtree_new();
221221

222222
/* read in our flush file */
223-
if (kvtree_read_file(file, hash) != KVTREE_SUCCESS) {
223+
if (kvtree_read_with_lock(file, hash) != KVTREE_SUCCESS) {
224224
/* failed to read the flush file */
225225
goto cleanup;
226226
}

src/scr_flush_file_mpi.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int scr_flush_file_need_flush(int id)
2929
if (scr_my_rank_world == 0) {
3030
/* read the flush file */
3131
kvtree* hash = kvtree_new();
32-
kvtree_read_path(scr_flush_file, hash);
32+
kvtree_read_path_locked(scr_flush_file, hash);
3333

3434
/* if we have the dataset in cache, but not on the parallel file system,
3535
* then it needs to be flushed */
@@ -60,7 +60,7 @@ int scr_flush_file_is_flushing(int id)
6060
if (scr_my_rank_world == 0) {
6161
/* read flush file into hash */
6262
kvtree* hash = kvtree_new();
63-
kvtree_read_path(scr_flush_file, hash);
63+
kvtree_read_path_locked(scr_flush_file, hash);
6464

6565
/* attempt to look up the FLUSHING state for this checkpoint */
6666
kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
@@ -86,13 +86,13 @@ int scr_flush_file_dataset_remove(int id)
8686
if (scr_my_rank_world == 0) {
8787
/* read the flush file into hash */
8888
kvtree* hash = kvtree_new();
89-
kvtree_read_path(scr_flush_file, hash);
89+
kvtree_read_path_locked(scr_flush_file, hash);
9090

9191
/* delete this dataset id from the flush file */
9292
kvtree_unset_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
9393

9494
/* write the hash back to the flush file */
95-
kvtree_write_path(scr_flush_file, hash);
95+
kvtree_write_path_locked(scr_flush_file, hash);
9696

9797
/* delete the hash */
9898
kvtree_delete(&hash);
@@ -107,14 +107,14 @@ int scr_flush_file_location_set(int id, const char* location)
107107
if (scr_my_rank_world == 0) {
108108
/* read the flush file into hash */
109109
kvtree* hash = kvtree_new();
110-
kvtree_read_path(scr_flush_file, hash);
110+
kvtree_read_path_locked(scr_flush_file, hash);
111111

112112
/* set the location for this dataset */
113113
kvtree* dset_hash = kvtree_set_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
114114
kvtree_set_kv(dset_hash, SCR_FLUSH_KEY_LOCATION, location);
115115

116116
/* write the hash back to the flush file */
117-
kvtree_write_path(scr_flush_file, hash);
117+
kvtree_write_path_locked(scr_flush_file, hash);
118118

119119
/* delete the hash */
120120
kvtree_delete(&hash);
@@ -130,7 +130,7 @@ int scr_flush_file_location_test(int id, const char* location)
130130
if (scr_my_rank_world == 0) {
131131
/* read the flush file into hash */
132132
kvtree* hash = kvtree_new();
133-
kvtree_read_path(scr_flush_file, hash);
133+
kvtree_read_path_locked(scr_flush_file, hash);
134134

135135
/* check the location for this dataset */
136136
kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
@@ -157,14 +157,14 @@ int scr_flush_file_location_unset(int id, const char* location)
157157
if (scr_my_rank_world == 0) {
158158
/* read the flush file into hash */
159159
kvtree* hash = kvtree_new();
160-
kvtree_read_path(scr_flush_file, hash);
160+
kvtree_read_path_locked(scr_flush_file, hash);
161161

162162
/* unset the location for this dataset */
163163
kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
164164
kvtree_unset_kv(dset_hash, SCR_FLUSH_KEY_LOCATION, location);
165165

166166
/* write the hash back to the flush file */
167-
kvtree_write_path(scr_flush_file, hash);
167+
kvtree_write_path_locked(scr_flush_file, hash);
168168

169169
/* delete the hash */
170170
kvtree_delete(&hash);
@@ -180,7 +180,7 @@ int scr_flush_file_new_entry(int id, const char* name, const scr_dataset* datase
180180
if (scr_my_rank_world == 0) {
181181
/* read the flush file into hash */
182182
kvtree* hash = kvtree_new();
183-
kvtree_read_path(scr_flush_file, hash);
183+
kvtree_read_path_locked(scr_flush_file, hash);
184184

185185
/* set the name, location, and flags for this dataset */
186186
kvtree* dset_hash = kvtree_set_kv_int(hash, SCR_FLUSH_KEY_DATASET, id);
@@ -200,7 +200,7 @@ int scr_flush_file_new_entry(int id, const char* name, const scr_dataset* datase
200200
kvtree_set(dset_hash, SCR_FLUSH_KEY_DSETDESC, dataset_copy);
201201

202202
/* write the hash back to the flush file */
203-
kvtree_write_path(scr_flush_file, hash);
203+
kvtree_write_path_locked(scr_flush_file, hash);
204204

205205
/* delete the hash */
206206
kvtree_delete(&hash);

src/scr_halt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int scr_halt_sync_and_decrement(const spath* file_path, kvtree* hash, int dec_co
107107
}
108108

109109
/* acquire a file lock before read/modify/write */
110-
int ret = scr_file_lock_read(file, fd);
110+
int ret = scr_file_lock_write(file, fd);
111111
if (ret != SCR_SUCCESS) {
112112
scr_close(file,fd);
113113
rc = ret;

src/scr_index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam
338338
kvtree_set_kv_int(entries, "RANKS", count);
339339

340340
/* write hash to file rank2file part */
341-
if (kvtree_write_path(rank2file_path, entries) != KVTREE_SUCCESS) {
341+
if (kvtree_write_path_locked(rank2file_path, entries) != KVTREE_SUCCESS) {
342342
rc = SCR_FAILURE;
343343
elem = NULL;
344344
}
@@ -367,7 +367,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam
367367
/* write out rank2file map */
368368
spath* files_path = spath_dup(meta_path);
369369
spath_append_str(files_path, filename);
370-
if (kvtree_write_path(files_path, files_hash) != KVTREE_SUCCESS) {
370+
if (kvtree_write_path_locked(files_path, files_hash) != KVTREE_SUCCESS) {
371371
rc = SCR_FAILURE;
372372
}
373373
spath_delete(&files_path);
@@ -397,7 +397,7 @@ int scr_summary_write(const spath* prefix, const spath* dir, kvtree* hash)
397397
/* write summary file */
398398
spath* summary_path = spath_dup(meta_path);
399399
spath_append_str(summary_path, SCR_SUMMARY_FILENAME);
400-
if (kvtree_write_path(summary_path, hash) != KVTREE_SUCCESS) {
400+
if (kvtree_write_path_locked(summary_path, hash) != KVTREE_SUCCESS) {
401401
rc = SCR_FAILURE;
402402
}
403403
spath_delete(&summary_path);

src/scr_index_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int scr_index_write(const spath* dir, kvtree* index)
197197
}
198198

199199
/* write out the file */
200-
int kvtree_rc = kvtree_write_path(path_index, index);
200+
int kvtree_rc = kvtree_write_path_locked(path_index, index);
201201
int rc = (kvtree_rc == KVTREE_SUCCESS) ? SCR_SUCCESS : SCR_FAILURE;
202202

203203
/* free path */

src/scr_nodes_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int main (int argc, char *argv[])
114114
kvtree* hash = kvtree_new();
115115

116116
/* read in our nodes file */
117-
if (kvtree_read_file(file_str, hash) != KVTREE_SUCCESS) {
117+
if (kvtree_read_with_lock(file_str, hash) != KVTREE_SUCCESS) {
118118
/* failed to read the nodes file */
119119
goto cleanup;
120120
}

src/scr_summary.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static int scr_summary_read_v5(const spath* dir, kvtree* summary_hash)
314314
}
315315

316316
/* read in the summary hash file */
317-
if (kvtree_read_path(summary_path, summary_hash) != KVTREE_SUCCESS) {
317+
if (kvtree_read_path_locked(summary_path, summary_hash) != KVTREE_SUCCESS) {
318318
scr_err("Reading summary file %s @ %s:%d",
319319
summary_file, __FILE__, __LINE__
320320
);
@@ -484,7 +484,7 @@ int scr_summary_write(const spath* dir, const scr_dataset* dataset, int all_comp
484484
kvtree_util_set_int(rank2file_hash, SCR_SUMMARY_6_KEY_RANKS, scr_ranks_world);
485485

486486
/* write the hash to a file */
487-
kvtree_write_path(summary_path, summary_hash);
487+
kvtree_write_path_locked(summary_path, summary_hash);
488488

489489
/* free the hash object */
490490
kvtree_delete(&summary_hash);

src/scr_util.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,22 @@ int kvtree_write_path(const spath* path, const kvtree* tree)
361361
return rc;
362362
}
363363

364+
int kvtree_read_path_locked(const spath* path, kvtree* tree)
365+
{
366+
char* file = spath_strdup(path);
367+
int rc = kvtree_read_with_lock(file, tree);
368+
scr_free(&file);
369+
return rc;
370+
}
371+
372+
int kvtree_write_path_locked(const spath* path, const kvtree* tree)
373+
{
374+
char* file = spath_strdup(path);
375+
int rc = kvtree_write_with_lock(file, tree);
376+
scr_free(&file);
377+
return rc;
378+
}
379+
364380
/* given a string defining SCR_PREFIX value as given by user
365381
* return spath of fully qualified path, user should free */
366382
spath* scr_get_prefix(const char* str)

src/scr_util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ int kvtree_read_path(const spath* path, kvtree* tree);
7878
/* convenience to write kvtree to an spath */
7979
int kvtree_write_path(const spath* path, const kvtree* tree);
8080

81+
/* convenience to read kvtree from an spath with a file read lock */
82+
int kvtree_read_path_locked(const spath* path, kvtree* tree);
83+
84+
/* convenience to write kvtree to an spath with a file write lock */
85+
int kvtree_write_path_locked(const spath* path, const kvtree* tree);
86+
8187
/* given a string defining SCR_PREFIX value as given by user
8288
* return spath of fully qualified path, user should free */
8389
spath* scr_get_prefix(const char* prefix);

0 commit comments

Comments
 (0)