Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate calls of mainStorage.lock() in LockManager for version 1.* #165

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/main/java/org/icatproject/ids/LockManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,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 @@ -55,6 +57,13 @@ void dec() {
count -= 1;
if (count == 0) {
lockMap.remove(id);
if (storageLock != null) {
GonozalIX marked this conversation as resolved.
Show resolved Hide resolved
try {
storageLock.close();
} catch (Exception e) {
logger.error("Error while closing lock on {} in the storage plugin: {}.", id, e.getMessage());
}
}
}
}
}
Expand All @@ -73,25 +82,16 @@ 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 @@ -134,22 +134,21 @@ 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;
try {
storageLock = mainStorage.lock(ds, type == LockType.SHARED);
} catch (AlreadyLockedException | IOException e) {
throw e;
RKrahl marked this conversation as resolved.
Show resolved Hide resolved
}
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
6 changes: 6 additions & 0 deletions src/site/xhtml/release-notes.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

<h1>IDS Server Release Notes</h1>

<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