Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,21 @@ public void acquire(Collection<? extends Artifact> artifacts, Collection<? exten
}
} catch (InterruptedException e) {
// if we are here, means we were interrupted: fail
close();
try {
namedLock.close();
} finally {
close();
}
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
// if we are here, means all attempts were unsuccessful: fail
close();
try {
namedLock.close();
} finally {
close();
}
String message = "Could not acquire " + lockKind + " lock for "
+ lockSubjects(artifacts, metadatas) + " in " + timeStr
+ "; consider using '" + CONFIG_PROP_TIME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void testRead(FS fs) throws Exception {
void testReadNoFileLeak(FS fs) throws Exception {
TrackingFileManager tfm = createTrackingFileManager(fs);

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
Path propFile = createTmpFile(fs);
assertNotNull(tfm.read(propFile));
assertDoesNotThrow(() -> Files.delete(propFile), "Leaked file" + propFile);
Expand Down Expand Up @@ -157,7 +157,7 @@ void testUpdateNoFileLeak(FS fs) throws Exception {
Map<String, String> updates = new HashMap<>();
updates.put("k", "v");

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
Path propFile = createTmpFile(fs);
assertNotNull(tfm.update(propFile, updates));
assertDoesNotThrow(() -> Files.delete(propFile), "Leaked file" + propFile);
Expand All @@ -169,7 +169,7 @@ void testUpdateNoFileLeak(FS fs) throws Exception {
public void testDeleteFileIsGone(FS fs) throws Exception {
TrackingFileManager tfm = createTrackingFileManager(fs);

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
Path propFile = createTmpFile(fs);
assertTrue(tfm.delete(propFile));
assertFalse(Files.exists(propFile), "File is not gone");
Expand All @@ -196,7 +196,7 @@ void testLockingOnCanonicalPath(FS fs) throws Exception {

threads[i] = new Thread(() -> {
try {
for (int i1 = 0; i1 < 1000; i1++) {
for (int i1 = 0; i1 < 100; i1++) {
assertNotNull(tfm.read(file));
HashMap<String, String> update = new HashMap<>();
update.put("wasHere", Thread.currentThread().getName() + "-" + i1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,34 @@ private boolean lock(long time, TimeUnit timeUnit, boolean shared) throws Interr
final String lockKind = shared ? "shared" : "exclusive";
LOGGER.trace(
"{}: Need {} {} lock(s) of {} in {}", key().name(), locks.size(), lockKind, key().resources(), timeStr);
for (NamedLock namedLock : locks.values()) {
LOGGER.trace("{}: Acquiring {} lock for '{}'", key().name(), lockKind, namedLock.key());

boolean locked;
if (shared) {
locked = namedLock.lockShared(time, timeUnit);
} else {
locked = namedLock.lockExclusively(time, timeUnit);
}

if (!locked) {
LOGGER.trace(
"{}: Failed to acquire {} lock for '{}' in {}",
key().name(),
lockKind,
namedLock.key(),
timeStr);

unlockAll(step);
return false;
} else {
step.push(namedLock);
try {
for (NamedLock namedLock : locks.values()) {
LOGGER.trace("{}: Acquiring {} lock for '{}'", key().name(), lockKind, namedLock.key());

boolean locked;
if (shared) {
locked = namedLock.lockShared(time, timeUnit);
} else {
locked = namedLock.lockExclusively(time, timeUnit);
}

if (!locked) {
LOGGER.trace(
"{}: Failed to acquire {} lock for '{}' in {}",
key().name(),
lockKind,
namedLock.key(),
timeStr);

unlockAll(step);
return false;
} else {
step.push(namedLock);
}
}
} catch (Throwable t) {
unlockAll(step);
throw t;
}
steps.push(step);
return true;
Expand Down
Loading