Browse Source

MINOR: Rename lock variable of the entry class (#14569)

The RemoteIndexCache has a variable lock and the child class also have a variable lock in the same class file. Renaming lock of the entry(child class) to avoid confusion.

Reviewers: Luke Chen <showuon@gmail.com>, hudeqi <1217150961@qq.com>
pull/14034/merge
Arpit Goyal 11 months ago committed by GitHub
parent
commit
dc6a53e196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteIndexCache.java

26
storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteIndexCache.java

@ -479,7 +479,7 @@ public class RemoteIndexCache implements Closeable { @@ -479,7 +479,7 @@ public class RemoteIndexCache implements Closeable {
// underlying files of the index) isn't performed while a read is in-progress for the entry. This is required in
// addition to using the thread safe cache because, while the thread safety of the cache ensures that we can read
// entries concurrently, it does not ensure that we won't mutate underlying files belonging to an entry.
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private final ReentrantReadWriteLock entryLock = new ReentrantReadWriteLock();
private boolean cleanStarted = false;
@ -524,41 +524,41 @@ public class RemoteIndexCache implements Closeable { @@ -524,41 +524,41 @@ public class RemoteIndexCache implements Closeable {
}
private long estimatedEntrySize() {
lock.readLock().lock();
entryLock.readLock().lock();
try {
return offsetIndex.sizeInBytes() + timeIndex.sizeInBytes() + Files.size(txnIndex.file().toPath());
} catch (IOException e) {
log.warn("Error occurred when estimating remote index cache entry bytes size, just set 0 firstly.", e);
return 0L;
} finally {
lock.readLock().unlock();
entryLock.readLock().unlock();
}
}
public OffsetPosition lookupOffset(long targetOffset) {
lock.readLock().lock();
entryLock.readLock().lock();
try {
if (markedForCleanup) throw new IllegalStateException("This entry is marked for cleanup");
else return offsetIndex.lookup(targetOffset);
} finally {
lock.readLock().unlock();
entryLock.readLock().unlock();
}
}
public OffsetPosition lookupTimestamp(long timestamp, long startingOffset) throws IOException {
lock.readLock().lock();
entryLock.readLock().lock();
try {
if (markedForCleanup) throw new IllegalStateException("This entry is marked for cleanup");
TimestampOffset timestampOffset = timeIndex.lookup(timestamp);
return offsetIndex.lookup(Math.max(startingOffset, timestampOffset.offset));
} finally {
lock.readLock().unlock();
entryLock.readLock().unlock();
}
}
public void markForCleanup() throws IOException {
lock.writeLock().lock();
entryLock.writeLock().lock();
try {
if (!markedForCleanup) {
markedForCleanup = true;
@ -567,12 +567,12 @@ public class RemoteIndexCache implements Closeable { @@ -567,12 +567,12 @@ public class RemoteIndexCache implements Closeable {
txnIndex.renameTo(new File(Utils.replaceSuffix(txnIndex.file().getPath(), "", LogFileUtils.DELETED_FILE_SUFFIX)));
}
} finally {
lock.writeLock().unlock();
entryLock.writeLock().unlock();
}
}
public void cleanup() throws IOException {
lock.writeLock().lock();
entryLock.writeLock().lock();
try {
markForCleanup();
// no-op if clean is done already
@ -593,19 +593,19 @@ public class RemoteIndexCache implements Closeable { @@ -593,19 +593,19 @@ public class RemoteIndexCache implements Closeable {
tryAll(actions);
}
} finally {
lock.writeLock().unlock();
entryLock.writeLock().unlock();
}
}
@Override
public void close() {
lock.writeLock().lock();
entryLock.writeLock().lock();
try {
Utils.closeQuietly(offsetIndex, "OffsetIndex");
Utils.closeQuietly(timeIndex, "TimeIndex");
Utils.closeQuietly(txnIndex, "TransactionIndex");
} finally {
lock.writeLock().unlock();
entryLock.writeLock().unlock();
}
}

Loading…
Cancel
Save