Skip to content

Commit

Permalink
storage-mgr: synchro create file will be unlocked after exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DenChaykovskiy committed May 17, 2024
1 parent eb4345c commit 135542b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ public boolean createFile(String content) {
}

/**
* Creates the file with the content in a synchronized modus. Returns false if the file was not created/rewritten.
* creation of the file was not successfully
* Creates the file with the content in a synchronized modus. Returns false if
* the file was not created/rewritten. creation of the file was not
* successfully. The waiting thread will unlock the file, which was locked in
* the locked thread in case of exception - Timeout or Interrupted exception. It
* is made for unlocking auxiliary files (status and accessed) of the storage
* manager. Please use this synchronized function carefully.
*
* @param content Content of the file
* @param waitTime the wait time between each cycle of checking the
Expand All @@ -119,18 +123,21 @@ public boolean synchroCreateFile(String content, long waitTime, long fileCheckMa

fileLocker.lockOrWaitUntilUnlockedAndLock();
fileCreatedStatus = createFile(content);
fileLocker.unlock();
fileCreatedStatus = true;

} catch (FileLockedAfterMaxCyclesException e) {

logger.debug("... the synchronized file was not created/rewritten: waiting timeout (possible locked from another thread): "
+ path + " " + e.getMessage());
logger.debug(
"... the synchronized file was not created/rewritten: waiting timeout (possible locked from another thread): "
+ path + " " + e.getMessage());

} catch (InterruptedException e) {

logger.debug("... the syncronized file was not created/rewritten: interrupted exception: " + path + " "
+ e.getMessage());
} finally {

fileLocker.unlock();
}

return fileCreatedStatus;
Expand Down

0 comments on commit 135542b

Please sign in to comment.