Skip to content

Commit 0aece73

Browse files
committed
ReleasableLock -> synchronized
1 parent 757dc68 commit 0aece73

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

  • x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/CacheDirectory.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Objects;
2626
import java.util.concurrent.atomic.AtomicBoolean;
2727
import java.util.concurrent.atomic.AtomicReference;
28-
import java.util.concurrent.locks.ReentrantLock;
2928

3029
/**
3130
* {@link CacheDirectory} uses a {@link CacheService} to cache Lucene files provided by another {@link Directory}.
@@ -65,7 +64,6 @@ public class CacheBufferedIndexInput extends BufferedIndexInput implements Cache
6564

6665
private @Nullable AtomicReference<CacheFile> cacheFile;
6766
private @Nullable CacheBufferedIndexInput parent;
68-
private ReleasableLock cacheEvictionLock;
6967
private AtomicBoolean closed;
7068

7169
CacheBufferedIndexInput(String fileName, long fileLength, IOContext ioContext) {
@@ -82,7 +80,6 @@ private CacheBufferedIndexInput(String fileName, long fileLength, IOContext ioCo
8280
this.end = offset + length;
8381
this.cacheFile = new AtomicReference<>();
8482
this.closed = new AtomicBoolean(false);
85-
this.cacheEvictionLock = new ReleasableLock(new ReentrantLock());
8683
}
8784

8885
@Override
@@ -99,7 +96,7 @@ private CacheFile getOrAcquire() throws Exception {
9996
}
10097

10198
final CacheFile newCacheFile = cacheService.get(fileName, fileLength, file);
102-
try (ReleasableLock ignored = cacheEvictionLock.acquire()) {
99+
synchronized (this) {
103100
currentCacheFile = cacheFile.get();
104101
if (currentCacheFile != null) {
105102
return currentCacheFile;
@@ -115,7 +112,7 @@ private CacheFile getOrAcquire() throws Exception {
115112

116113
@Override
117114
public void onEviction(final CacheFile evictedCacheFile) {
118-
try (ReleasableLock ignored = cacheEvictionLock.acquire()) {
115+
synchronized (this) {
119116
if (cacheFile.compareAndSet(evictedCacheFile, null)) {
120117
evictedCacheFile.release(this);
121118
}
@@ -125,7 +122,7 @@ public void onEviction(final CacheFile evictedCacheFile) {
125122
@Override
126123
public void close() {
127124
if (closed.compareAndSet(false, true)) {
128-
try (ReleasableLock ignored = cacheEvictionLock.acquire()) {
125+
synchronized (this) {
129126
final CacheFile currentCacheFile = cacheFile.getAndSet(null);
130127
if (currentCacheFile != null) {
131128
currentCacheFile.release(this);

0 commit comments

Comments
 (0)