Skip to content

Commit

Permalink
lock files shared between library and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
adammoody committed May 26, 2021
1 parent 03dbb84 commit 6b9b5ea
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/scr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ int SCR_Init()
if (scr_my_rank_world == 0) {
kvtree* nodes_hash = kvtree_new();
kvtree_util_set_int(nodes_hash, SCR_NODES_KEY_NODES, num_nodes);
kvtree_write_path(scr_nodes_file, nodes_hash);
kvtree_write_path_locked(scr_nodes_file, nodes_hash);
kvtree_delete(&nodes_hash);
}

Expand Down
2 changes: 1 addition & 1 deletion src/scr_flush_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int main (int argc, char *argv[])
kvtree* hash = kvtree_new();

/* read in our flush file */
if (kvtree_read_file(file, hash) != KVTREE_SUCCESS) {
if (kvtree_read_with_lock(file, hash) != KVTREE_SUCCESS) {
/* failed to read the flush file */
goto cleanup;
}
Expand Down
22 changes: 11 additions & 11 deletions src/scr_flush_file_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int scr_flush_file_need_flush(int id)
if (scr_my_rank_world == 0) {
/* read the flush file */
kvtree* hash = kvtree_new();
kvtree_read_path(scr_flush_file, hash);
kvtree_read_path_locked(scr_flush_file, hash);

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

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

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

/* write the hash back to the flush file */
kvtree_write_path(scr_flush_file, hash);
kvtree_write_path_locked(scr_flush_file, hash);

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

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

/* write the hash back to the flush file */
kvtree_write_path(scr_flush_file, hash);
kvtree_write_path_locked(scr_flush_file, hash);

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

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

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

/* write the hash back to the flush file */
kvtree_write_path(scr_flush_file, hash);
kvtree_write_path_locked(scr_flush_file, hash);

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

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

/* write the hash back to the flush file */
kvtree_write_path(scr_flush_file, hash);
kvtree_write_path_locked(scr_flush_file, hash);

/* delete the hash */
kvtree_delete(&hash);
Expand Down
2 changes: 1 addition & 1 deletion src/scr_halt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int scr_halt_sync_and_decrement(const spath* file_path, kvtree* hash, int dec_co
}

/* acquire a file lock before read/modify/write */
int ret = scr_file_lock_read(file, fd);
int ret = scr_file_lock_write(file, fd);
if (ret != SCR_SUCCESS) {
scr_close(file,fd);
rc = ret;
Expand Down
6 changes: 3 additions & 3 deletions src/scr_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam
kvtree_set_kv_int(entries, "RANKS", count);

/* write hash to file rank2file part */
if (kvtree_write_path(rank2file_path, entries) != KVTREE_SUCCESS) {
if (kvtree_write_path_locked(rank2file_path, entries) != KVTREE_SUCCESS) {
rc = SCR_FAILURE;
elem = NULL;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam
/* write out rank2file map */
spath* files_path = spath_dup(meta_path);
spath_append_str(files_path, filename);
if (kvtree_write_path(files_path, files_hash) != KVTREE_SUCCESS) {
if (kvtree_write_path_locked(files_path, files_hash) != KVTREE_SUCCESS) {
rc = SCR_FAILURE;
}
spath_delete(&files_path);
Expand Down Expand Up @@ -397,7 +397,7 @@ int scr_summary_write(const spath* prefix, const spath* dir, kvtree* hash)
/* write summary file */
spath* summary_path = spath_dup(meta_path);
spath_append_str(summary_path, SCR_SUMMARY_FILENAME);
if (kvtree_write_path(summary_path, hash) != KVTREE_SUCCESS) {
if (kvtree_write_path_locked(summary_path, hash) != KVTREE_SUCCESS) {
rc = SCR_FAILURE;
}
spath_delete(&summary_path);
Expand Down
2 changes: 1 addition & 1 deletion src/scr_index_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int scr_index_write(const spath* dir, kvtree* index)
}

/* write out the file */
int kvtree_rc = kvtree_write_path(path_index, index);
int kvtree_rc = kvtree_write_path_locked(path_index, index);
int rc = (kvtree_rc == KVTREE_SUCCESS) ? SCR_SUCCESS : SCR_FAILURE;

/* free path */
Expand Down
2 changes: 1 addition & 1 deletion src/scr_nodes_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main (int argc, char *argv[])
kvtree* hash = kvtree_new();

/* read in our nodes file */
if (kvtree_read_file(file_str, hash) != KVTREE_SUCCESS) {
if (kvtree_read_with_lock(file_str, hash) != KVTREE_SUCCESS) {
/* failed to read the nodes file */
goto cleanup;
}
Expand Down
4 changes: 2 additions & 2 deletions src/scr_summary.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static int scr_summary_read_v5(const spath* dir, kvtree* summary_hash)
}

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

/* write the hash to a file */
kvtree_write_path(summary_path, summary_hash);
kvtree_write_path_locked(summary_path, summary_hash);

/* free the hash object */
kvtree_delete(&summary_hash);
Expand Down
16 changes: 16 additions & 0 deletions src/scr_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ int kvtree_write_path(const spath* path, const kvtree* tree)
return rc;
}

int kvtree_read_path_locked(const spath* path, kvtree* tree)
{
char* file = spath_strdup(path);
int rc = kvtree_read_with_lock(file, tree);
scr_free(&file);
return rc;
}

int kvtree_write_path_locked(const spath* path, const kvtree* tree)
{
char* file = spath_strdup(path);
int rc = kvtree_write_with_lock(file, tree);
scr_free(&file);
return rc;
}

/* given a string defining SCR_PREFIX value as given by user
* return spath of fully qualified path, user should free */
spath* scr_get_prefix(const char* str)
Expand Down
6 changes: 6 additions & 0 deletions src/scr_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ int kvtree_read_path(const spath* path, kvtree* tree);
/* convenience to write kvtree to an spath */
int kvtree_write_path(const spath* path, const kvtree* tree);

/* convenience to read kvtree from an spath with a file read lock */
int kvtree_read_path_locked(const spath* path, kvtree* tree);

/* convenience to write kvtree to an spath with a file write lock */
int kvtree_write_path_locked(const spath* path, const kvtree* tree);

/* given a string defining SCR_PREFIX value as given by user
* return spath of fully qualified path, user should free */
spath* scr_get_prefix(const char* prefix);
Expand Down

0 comments on commit 6b9b5ea

Please sign in to comment.