Skip to content

Commit

Permalink
Merge branch 'master' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
RKrahl committed Jul 15, 2024
2 parents 95e77b7 + 94a7dbc commit af52f9f
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 @@ -511,6 +511,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/LockManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,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 @@ -56,6 +58,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 @@ -74,26 +83,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 @@ -136,22 +136,17 @@ public Lock lock(DsInfo ds, LockType type) throws AlreadyLockedException, IOExce
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 af52f9f

Please sign in to comment.