@@ -895,16 +895,28 @@ int unifyfs_find_extent_chunks(unifyfs_fops_ctx_t* ctx,
895895 if (ret == UNIFYFS_SUCCESS ) {
896896 int file_laminated = (attrs .is_shared && attrs .is_laminated );
897897 if (!(is_owner || use_server_local_extents || file_laminated )) {
898- /* send request for updated extents to owner */
899- struct timespec cache_ts ;
900- ret = unifyfs_inode_get_cache_times (gfid , & cache_ts , NULL );
901- if (UNIFYFS_SUCCESS != ret ) {
898+ int send_request = 1 ;
899+ struct timespec cache_ts , valid_ts ;
900+ ret = unifyfs_inode_get_cache_times (gfid , & cache_ts , & valid_ts );
901+ if (UNIFYFS_SUCCESS == ret ) {
902+ struct timespec now ;
903+ struct timespec cache_expire = valid_ts ;
904+ cache_expire .tv_sec += UNIFYFS_METADATA_CACHE_SECONDS ;
905+ clock_gettime (CLOCK_REALTIME , & now );
906+ if (compare_timespec (& now , & cache_expire ) <= 0 ) {
907+ /* cached extent metadata is still valid */
908+ send_request = 0 ;
909+ }
910+ } else {
902911 cache_ts = (struct timespec ) {0 };
903912 }
904- ret = unifyfs_invoke_get_extents_rpc (gfid , & cache_ts );
905- if (ret != UNIFYFS_SUCCESS ) {
906- LOGERR ("request to get extents for gfid=%d failed (ret=%d)" ,
907- gfid , ret );
913+ if (send_request ) {
914+ /* send request for updated extents to owner */
915+ ret = unifyfs_invoke_get_extents_rpc (gfid , & cache_ts );
916+ if (ret != UNIFYFS_SUCCESS ) {
917+ LOGERR ("request to get extents for gfid=%d failed (ret=%d)" ,
918+ gfid , ret );
919+ }
908920 }
909921 }
910922 }
@@ -952,15 +964,15 @@ int unifyfs_invoke_get_extents_rpc(int gfid,
952964 LOGERR ("failed to add pending remote get_extents" );
953965 return UNIFYFS_FAILURE ;
954966 } else if (rc == UNIFYFS_PENDING ) {
955- /* wait up to 5 seconds for completion of pending */
956- struct timespec timeout ;
957- clock_gettime (CLOCK_REALTIME , & timeout );
958- timeout .tv_sec += 5 ;
967+ /* wait for completion of pending get_extents request */
968+ struct timespec pendwait ;
969+ clock_gettime (CLOCK_REALTIME , & pendwait );
970+ pendwait .tv_sec += UNIFYFS_METADATA_CACHE_SECONDS ;
959971 ABT_mutex_lock (preq -> pending_sync );
960972 preq -> pending_waiters ++ ;
961973 LOGDBG ("waiting on pending get_extents condition for preq(%p)" , preq );
962974 rc = ABT_cond_timedwait (preq -> pending_cond , preq -> pending_sync ,
963- & timeout );
975+ & pendwait );
964976 if (ABT_ERR_COND_TIMEDOUT == rc ) {
965977 LOGERR ("wait for pending get_extents timed-out" );
966978 ret = UNIFYFS_ERROR_TIMEOUT ;
@@ -983,7 +995,6 @@ int unifyfs_invoke_get_extents_rpc(int gfid,
983995 get_extents_out_t * out = preq -> req_state -> outputs ;
984996
985997 /* fill rpc input struct and forward request to owner */
986-
987998 in -> src_rank = (int32_t ) glb_pmi_rank ;
988999 in -> gfid = (int32_t ) gfid ;
9891000 in -> src_timestamp = * timestamp ;
@@ -1004,24 +1015,23 @@ int unifyfs_invoke_get_extents_rpc(int gfid,
10041015 ret = out -> ret ;
10051016 if (ret == UNIFYFS_SUCCESS ) {
10061017 /* get number of extents */
1007- unsigned int n_ext = (unsigned int ) out -> num_extents ;
1018+ extent_metadata * em_arr = NULL ;
1019+ size_t n_ext = (size_t ) out -> num_extents ;
1020+ struct timespec owner_stamp = (struct timespec ) out -> owner_timestamp ;
10081021 if ((n_ext > 0 ) && (out -> extents != HG_BULK_NULL )) {
10091022 /* get bulk buffer with extent locations */
1010- size_t buf_sz = ( size_t ) n_ext * sizeof (extent_metadata );
1023+ size_t buf_sz = n_ext * sizeof (extent_metadata );
10111024 void * buf = pull_margo_bulk (preq -> req_state -> handle ,
10121025 out -> extents , buf_sz , NULL );
10131026 if (NULL == buf ) {
10141027 LOGERR ("failed to pull extent metadata array" );
10151028 ret = UNIFYFS_ERROR_MARGO ;
10161029 } else {
10171030 /* replace local cache with received extents */
1018- extent_metadata * em_arr = (extent_metadata * ) buf ;
1019- struct timespec owner_stamp =
1020- (struct timespec ) out -> owner_timestamp ;
1021- ret = unifyfs_inode_cache_extents (gfid , (int ) n_ext , em_arr ,
1022- & owner_stamp );
1031+ em_arr = (extent_metadata * ) buf ;
10231032 }
10241033 }
1034+ ret = sm_cache_extents (gfid , n_ext , em_arr , & owner_stamp );
10251035 }
10261036
10271037clear_pending_extents_get :
@@ -1067,7 +1077,7 @@ static void process_get_extents_rpc(server_rpc_req_t* sreq)
10671077 int send_extents = 0 ;
10681078 int owner_rank = hash_gfid_to_server (gfid );
10691079 if (owner_rank == glb_pmi_rank ) {
1070- ret = unifyfs_inode_get_extents (gfid , 0 , & num_extents , & extents ,
1080+ ret = unifyfs_inode_get_extents (gfid , & num_extents , & extents ,
10711081 & owner_stamp );
10721082 if (ret == UNIFYFS_SUCCESS ) {
10731083 /* Compare source timestamp to owner's and do:
@@ -1080,7 +1090,7 @@ static void process_get_extents_rpc(server_rpc_req_t* sreq)
10801090 LOGDBG ("owner has newer extents metadata" );
10811091 send_extents = 1 ;
10821092 if (src_stamp .tv_sec == 0 ) {
1083- /* zero source timestamp, time to broadcast */
1093+ /* source timestamp is zero , time to broadcast */
10841094 LOGDBG ("broadcasting extents metadata to cache" );
10851095 ret = unifyfs_invoke_broadcast_extents_cache (gfid );
10861096 }
@@ -1090,6 +1100,8 @@ static void process_get_extents_rpc(server_rpc_req_t* sreq)
10901100 send_extents = 1 ;
10911101 LOGWARN ("source cache timestamp is newer than owner?!?" );
10921102 }
1103+ // else, the timestamps are the same, so don't send
1104+
10931105 if (send_extents && (num_extents > 0 )) {
10941106 /* define a bulk handle to transfer extent_metadata array */
10951107 margo_instance_id mid =
0 commit comments