Skip to content

Remove unused extents from tablet locator - #6498

Open
DomGarguilo wants to merge 3 commits into
apache:2.1from
DomGarguilo:removeExtents
Open

Remove unused extents from tablet locator#6498
DomGarguilo wants to merge 3 commits into
apache:2.1from
DomGarguilo:removeExtents

Conversation

@DomGarguilo

@DomGarguilo DomGarguilo commented Aug 10, 2026

Copy link
Copy Markdown
Member

fixes #6169

Adds a cache to the online tablet locator that expires tablet extents after 10 minutes. Expired locations are reloaded from metadata when needed.

This reduces client memory usage.

@DomGarguilo DomGarguilo added this to the 2.1.7 milestone Aug 10, 2026
@DomGarguilo DomGarguilo self-assigned this Aug 10, 2026
@DomGarguilo DomGarguilo linked an issue Aug 10, 2026 that may be closed by this pull request
lastTabletRow.append(new byte[] {'<'}, 0, 1);
}

private void onExtentRemoval(KeyExtent extent, TabletLocation location, RemovalCause cause) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be invoked asynchronously which could allow the extent to be accessed after an eviction decision has already been made. Looking at the docs, I wonder if we should use evictionListener instead of removalListener on the cache for synchronous notification.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. Switched to evictionListener in 6a59935


if (entry != null) {
KeyExtent ke = entry.getValue().tablet_extent;
TabletLocation location = extentCache.getIfPresent(entry.getValue().tablet_extent);

@dlmarion dlmarion Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code may not need to change if instead we synchronize on an object in this method and in the evictionListener to ensure that an eviction and lookup are not happening concurrently. I have not looked at other places in this class where extentCache lookups are done, but we would want to protect those as well.

Could use Guava's Striped class,Striped<Lock> specifically, for more granular locking on the extent.

@dlmarion dlmarion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want synchronous notification and locking to remove the chance of a race condition between expiration and lookup.

this.lockChecker = tslc;

extentCache = Caffeine.newBuilder().expireAfterAccess(CACHE_EXPIRATION)
.scheduler(Scheduler.systemScheduler()).evictionListener(this::onExtentEviction).build();

@phrocker phrocker Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this introduce deadlock? evictionlistener runs sync on teh thread doing the cache operation, and the locateTabletInCache is called under the rlock from binmutations, binranges, etc. So if getIfPresent can run the listener in line on a thread that holds the read lock the write lock will block forever, no?

Could the listener just enqueue the evicted extent and let processInvalidated drain it under the write lock it already holds?

I'm not sure I'm right about the deadlock though.....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might be right. Looking into a solution now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unused extents from tablet locator

3 participants