Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3' into v3_FileInfoImprovementA…
Browse files Browse the repository at this point in the history
…ndRequestHandler
  • Loading branch information
LewerenzM committed Jul 19, 2024
2 parents 74c8337 + af52f9f commit 33135c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/icatproject/ids/IdsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ public Response put(@Context HttpServletRequest request, InputStream body,
@Path("put")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Deprecated
public Response putAsPost(@Context HttpServletRequest request) throws BadRequestException, NotFoundException,
InternalException, InsufficientPrivilegesException, NotImplementedException, DataNotOnlineException {
try {
Expand Down
35 changes: 15 additions & 20 deletions src/main/java/org/icatproject/ids/services/LockManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public class LockInfo {
private class LockEntry {
final Long id;
final LockType type;
final AutoCloseable storageLock;
int count;

LockEntry(Long id, LockType type) {
LockEntry(Long id, LockType type, AutoCloseable storageLock) {
this.id = id;
this.type = type;
this.storageLock = storageLock;
this.count = 0;
lockMap.put(id, this);
}
Expand All @@ -57,6 +59,13 @@ void dec() {
count -= 1;
if (count == 0) {
lockMap.remove(id);
if (storageLock != null) {
try {
storageLock.close();
} catch (Exception e) {
logger.error("Error while closing lock on {} in the storage plugin: {}.", id, e.getMessage());
}
}
}
}
}
Expand All @@ -75,26 +84,17 @@ public void close() {
private class SingleLock extends Lock {
private final Long id;
private boolean isValid;
private AutoCloseable storageLock;

SingleLock(Long id, AutoCloseable storageLock) {
SingleLock(Long id) {
this.id = id;
this.isValid = true;
this.storageLock = storageLock;
}

public void release() {
synchronized (lockMap) {
if (isValid) {
lockMap.get(id).dec();
isValid = false;
if (storageLock != null) {
try {
storageLock.close();
} catch (Exception e) {
logger.error("Error while closing lock on {} in the storage plugin: {}.", id, e.getMessage());
}
}
logger.debug("Released a lock on {}.", id);
}
}
Expand Down Expand Up @@ -137,22 +137,17 @@ public Lock lock(DatasetInfo ds, LockType type) throws AlreadyLockedException, I
synchronized (lockMap) {
LockEntry le = lockMap.get(id);
if (le == null) {
le = new LockEntry(id, type);
AutoCloseable storageLock;
storageLock = mainStorage.lock(ds, type == LockType.SHARED);
le = new LockEntry(id, type, storageLock);
} else {
if (type == LockType.EXCLUSIVE || le.type == LockType.EXCLUSIVE) {
throw new AlreadyLockedException();
}
}
le.inc();
AutoCloseable storageLock;
try {
storageLock = mainStorage.lock(ds, type == LockType.SHARED);
} catch (AlreadyLockedException | IOException e) {
le.dec();
throw e;
}
logger.debug("Acquired a {} lock on {}.", type, id);
return new SingleLock(id, storageLock);
return new SingleLock(id);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/site/xhtml/release-notes.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
<ul>
<li>#147: Drop FileChecker, deprecated in 2.0.0.</li>
<li>#148: Drop getLink API call, deprecated in 2.0.0.</li>
</ul>

<h2>2.1.1</h2>
<p>Bug fix release</p>
<ul>
<li>#164, #166: Fix duplicate calls of mainStorage.lock() in LockManager.</li>
<li>#140, #158: Fix miredot build.</li>
<li>Deprecate the putAsPost call.</li>
</ul>

<h2>2.1.0</h2>
Expand All @@ -30,6 +37,12 @@
</li>
</ul>

<h2>1.12.2</h2>
<p>Bug fix release</p>
<ul>
<li>#164, #165: Fix duplicate calls of mainStorage.lock() in LockManager.</li>
</ul>

<h2>1.12.1</h2>
<ul>
<li>#122: Bump dependency on logback-classic to version 1.2.0.</li>
Expand Down

0 comments on commit 33135c3

Please sign in to comment.