Skip to content

Commit

Permalink
storage-mgr: no unlock from the waiting thread in synchro file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenChaykovskiy committed May 13, 2024
1 parent d57011c commit eb4345c
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean createFile(String content) {

if (logger.isTraceEnabled())
logger.trace(">>> createFile(<content>)");

logger.debug("... file content (first 20 characters): " + new StringUtils(content).getMaxSubstring(20));
logger.debug("... file size: " + content.length());

Expand All @@ -95,43 +95,42 @@ public boolean createFile(String content) {
}

/**
* Creates the file with the content in a synchro modus
* 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
*
* @param content Content of the file
* @param content Content of the file
* @param waitTime the wait time between each cycle of checking the
* file lock status
* @param fileCheckMaxCycles file check max cycles
* @return true if file was successfully created
*/
public boolean synchroCreateFile(String content, long waitTime, long fileCheckMaxCycles) {

if (logger.isTraceEnabled())
logger.trace(">>> synchroCreateFile(<content>, {}, {})", waitTime, fileCheckMaxCycles);

logger.debug("... file content (first 20 characters): " + new StringUtils(content).getMaxSubstring(20));
logger.debug("... file size: " + content.length());

StorageFileLocker fileLocker = new StorageFileLocker(path, waitTime, fileCheckMaxCycles);
boolean fileCreatedStatus;
boolean fileCreatedStatus = false;

try {

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

} catch (FileLockedAfterMaxCyclesException e) {
logger.debug("... the file is locked after max check cycles: " + path + " " + e.getMessage());
fileCreatedStatus = false;

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 file is locked after max check cycles: " + path + " " + e.getMessage());
fileCreatedStatus = false;

} finally {

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

return fileCreatedStatus;
Expand Down

0 comments on commit eb4345c

Please sign in to comment.