[
https://issues.apache.org/jira/browse/HBASE-30604?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eungsop Yoo updated HBASE-30604:
--------------------------------
Description:
While reviewing the row cache implementation on the HBASE-29585 feature branch,
I found the following issues. The issues in the first list can return stale or
wrong rows from the row cache without any error.
# HRegion#mutateRowsWithLocks does not invalidate the row cache. It calls
batchMutate with a MutationBatchOperation directly and skips the row cache
barrier, so rows mutated through MultiRowMutationEndpoint stay stale in the
cache.
# RowCache#canCacheRow does not check Get#getMaxVersions. A Get reading
multiple versions can populate the cache, and a later single-version Get is
then served all cached versions. The opposite direction is also wrong.
# A Get can cache a stale row when a mutation of the same row completes while
the Get is reading the row. The row level barrier only tells whether a mutation
is in progress, so if a mutation starts and finishes between the read and the
cache population, the old row stays in the cache until the next mutation of the
row.
# The same problem exists at the region level for bulk loads. A Get that starts
after the bulk load increases the row cache sequence number of the region can
read the region before the bulk-loaded files are added, and cache the old row
under the current key after the bulk load finishes.
# Admin#refreshHFiles on a read replica cluster refreshes the store files
without invalidating the row cache, so rows cached before the refresh keep
being served. Such a cluster has no mutations that would evict them.
# The row cache sequence number comes from the open sequence number, which
repeats for a region recreated by truncate_region, and bulk loads can push it
ahead of later open sequence numbers. As row.cache.evictOnClose is false by
default, rows cached in an earlier lifetime of the region can be served.
# A row level barrier is keyed with the row cache sequence number, so a Get
that starts after a bulk load changes the number does not see the barrier of a
mutation in progress.
# Rows that a coprocessor adds to a batch with
MiniBatchOperationInProgress#addOperationsFromCP are not covered by the row
level barriers.
# The barrier counters are incremented outside computeIfAbsent. A concurrent
removal can drop the counter from the map between the lookup and the increment,
which lets a mutation run without a barrier.
For #3, RowCache will register a pending-load token for the row before the
read. A mutation removes the token, and the Get populates the cache only if its
token is still registered. For the bulk load case, the row cache sequence
number is increased again when the bulk load finishes. The row cache sequence
numbers now come from a counter of the region server, and the row level
barriers and the load tokens are keyed by the row only.
The row cache can also use more heap than configured.
# HeapMemoryManager does not count the row cache when it checks the heap limits
of the memstore and the block cache, so the heap memory tuner can grow them
into the heap reserved for the row cache.
# RowCells#heapSize and RowCacheKey#heapSize do not count the list of cells,
the array header of the row key and the map entry of the cache, so the cache
can hold more than row.cache.size.
# A row is cloned before its size is checked, so a row larger than the row
cache is cloned on every miss and evicted right away. The eviction policy
ignores sizes, so a large row can also evict many small rows at once.
Rows larger than 1% of the row cache are not cached. They are counted in the
new rowCacheTooLargeRowCount metric and logged at most once a minute.
Smaller issues:
# TableDescriptor#getRowCacheEnabled is added to a public interface without a
default implementation.
# An explicit ROW_CACHE_ENABLED => false is hidden from the table attributes
shown in the master UI, although it differs from an absent value, which falls
back to row.cache.enabled.
# Mutations create row level barriers even when row.cache.size is 0.
# A cache hit does not check the state of the region, so a closing region or a
region with reads disabled serves cached rows.
# In a multi request, the memstore-only check uses the block bytes scanned by
the whole request.
# Cells that a coprocessor adds to the results in preGetOp without bypassing
the Get are cached and served twice.
# Region#isRowCacheEnabled is added to an interface for coprocessors without a
default implementation.
The barriers were also created in several places: each public mutation method
of HRegion, the bulk load RPC of the region server and the refreshHFiles
procedure. A coprocessor that bulk loads through HRegion#bulkLoadHFiles or
refreshes a store directly skips the invalidation, and a single mutation or a
checkAndMutate creates two or three barriers for the same row. The row level
barriers are now created in HRegion#batchMutate, which every row mutation goes
through, and the region level barriers inside HRegion#bulkLoadHFiles and
HStore#refreshStoreFiles.
This also adds a missing null check of the row cache in
HRegion#getScannerWithResults and simplifies how the row cache is looked up on
region close and in the region server metrics.
was:
While reviewing the row cache implementation on the HBASE-29585 feature branch,
I found the following issues. The issues in the first list can return stale or
wrong rows from the row cache without any error.
# HRegion#mutateRowsWithLocks does not invalidate the row cache. It calls
batchMutate with a MutationBatchOperation directly and skips the row cache
barrier, so rows mutated through MultiRowMutationEndpoint stay stale in the
cache.
# RowCache#canCacheRow does not check Get#getMaxVersions. A Get reading
multiple versions can populate the cache, and a later single-version Get is
then served all cached versions. The opposite direction is also wrong.
# A Get can cache a stale row when a mutation of the same row completes while
the Get is reading the row. The row level barrier only tells whether a mutation
is in progress, so if a mutation starts and finishes between the read and the
cache population, the old row stays in the cache until the next mutation of the
row.
# The same problem exists at the region level for bulk loads. A Get that starts
after the bulk load increases the row cache sequence number of the region can
read the region before the bulk-loaded files are added, and cache the old row
under the current key after the bulk load finishes.
# Admin#refreshHFiles on a read replica cluster refreshes the store files
without invalidating the row cache, so rows cached before the refresh keep
being served. Such a cluster has no mutations that would evict them.
# The row cache sequence number comes from the open sequence number, which
repeats for a region recreated by truncate_region, and bulk loads can push it
ahead of later open sequence numbers. As row.cache.evictOnClose is false by
default, rows cached in an earlier lifetime of the region can be served.
# A row level barrier is keyed with the row cache sequence number, so a Get
that starts after a bulk load changes the number does not see the barrier of a
mutation in progress.
# Rows that a coprocessor adds to a batch with
MiniBatchOperationInProgress#addOperationsFromCP are not covered by the row
level barriers.
# The barrier counters are incremented outside computeIfAbsent. A concurrent
removal can drop the counter from the map between the lookup and the increment,
which lets a mutation run without a barrier.
For #3, RowCache will register a pending-load token for the row before the
read. A mutation removes the token, and the Get populates the cache only if its
token is still registered. For the bulk load case, the row cache sequence
number is increased again when the bulk load finishes. The row cache sequence
numbers now come from a counter of the region server, and the row level
barriers and the load tokens are keyed by the row only.
The row cache can also use more heap than configured.
# HeapMemoryManager does not count the row cache when it checks the heap limits
of the memstore and the block cache, so the heap memory tuner can grow them
into the heap reserved for the row cache.
# RowCells#heapSize and RowCacheKey#heapSize do not count the list of cells,
the array header of the row key and the map entry of the cache, so the cache
can hold more than row.cache.size.
# A row is cloned before its size is checked, so a row larger than the row
cache is cloned on every miss and evicted right away. The eviction policy
ignores sizes, so a large row can also evict many small rows at once.
Rows larger than 1% of the row cache are not cached. They are counted in the
new rowCacheTooLargeRowCount metric and logged at most once a minute.
Smaller issues:
# TableDescriptor#getRowCacheEnabled is added to a public interface without a
default implementation.
# An explicit ROW_CACHE_ENABLED => false is hidden from the table attributes
shown in the master UI, although it differs from an absent value, which falls
back to row.cache.enabled.
# Mutations create row level barriers even when row.cache.size is 0.
# A cache hit does not check the state of the region, so a closing region or a
region with reads disabled serves cached rows.
# In a multi request, the memstore-only check uses the block bytes scanned by
the whole request.
# Cells that a coprocessor adds to the results in preGetOp without bypassing
the Get are cached and served twice.
# Region#isRowCacheEnabled is added to an interface for coprocessors without a
default implementation.
This also adds a missing null check of the row cache in
HRegion#getScannerWithResults and simplifies how the row cache is looked up on
region close and in the region server metrics.
> Fix consistency and memory accounting issues in the row cache
> -------------------------------------------------------------
>
> Key: HBASE-30604
> URL: https://issues.apache.org/jira/browse/HBASE-30604
> Project: HBase
> Issue Type: Sub-task
> Reporter: Eungsop Yoo
> Assignee: Eungsop Yoo
> Priority: Major
>
> While reviewing the row cache implementation on the HBASE-29585 feature
> branch, I found the following issues. The issues in the first list can return
> stale or wrong rows from the row cache without any error.
> # HRegion#mutateRowsWithLocks does not invalidate the row cache. It calls
> batchMutate with a MutationBatchOperation directly and skips the row cache
> barrier, so rows mutated through MultiRowMutationEndpoint stay stale in the
> cache.
> # RowCache#canCacheRow does not check Get#getMaxVersions. A Get reading
> multiple versions can populate the cache, and a later single-version Get is
> then served all cached versions. The opposite direction is also wrong.
> # A Get can cache a stale row when a mutation of the same row completes while
> the Get is reading the row. The row level barrier only tells whether a
> mutation is in progress, so if a mutation starts and finishes between the
> read and the cache population, the old row stays in the cache until the next
> mutation of the row.
> # The same problem exists at the region level for bulk loads. A Get that
> starts after the bulk load increases the row cache sequence number of the
> region can read the region before the bulk-loaded files are added, and cache
> the old row under the current key after the bulk load finishes.
> # Admin#refreshHFiles on a read replica cluster refreshes the store files
> without invalidating the row cache, so rows cached before the refresh keep
> being served. Such a cluster has no mutations that would evict them.
> # The row cache sequence number comes from the open sequence number, which
> repeats for a region recreated by truncate_region, and bulk loads can push it
> ahead of later open sequence numbers. As row.cache.evictOnClose is false by
> default, rows cached in an earlier lifetime of the region can be served.
> # A row level barrier is keyed with the row cache sequence number, so a Get
> that starts after a bulk load changes the number does not see the barrier of
> a mutation in progress.
> # Rows that a coprocessor adds to a batch with
> MiniBatchOperationInProgress#addOperationsFromCP are not covered by the row
> level barriers.
> # The barrier counters are incremented outside computeIfAbsent. A concurrent
> removal can drop the counter from the map between the lookup and the
> increment, which lets a mutation run without a barrier.
> For #3, RowCache will register a pending-load token for the row before the
> read. A mutation removes the token, and the Get populates the cache only if
> its token is still registered. For the bulk load case, the row cache sequence
> number is increased again when the bulk load finishes. The row cache sequence
> numbers now come from a counter of the region server, and the row level
> barriers and the load tokens are keyed by the row only.
> The row cache can also use more heap than configured.
> # HeapMemoryManager does not count the row cache when it checks the heap
> limits of the memstore and the block cache, so the heap memory tuner can grow
> them into the heap reserved for the row cache.
> # RowCells#heapSize and RowCacheKey#heapSize do not count the list of cells,
> the array header of the row key and the map entry of the cache, so the cache
> can hold more than row.cache.size.
> # A row is cloned before its size is checked, so a row larger than the row
> cache is cloned on every miss and evicted right away. The eviction policy
> ignores sizes, so a large row can also evict many small rows at once.
> Rows larger than 1% of the row cache are not cached. They are counted in the
> new rowCacheTooLargeRowCount metric and logged at most once a minute.
> Smaller issues:
> # TableDescriptor#getRowCacheEnabled is added to a public interface without a
> default implementation.
> # An explicit ROW_CACHE_ENABLED => false is hidden from the table attributes
> shown in the master UI, although it differs from an absent value, which falls
> back to row.cache.enabled.
> # Mutations create row level barriers even when row.cache.size is 0.
> # A cache hit does not check the state of the region, so a closing region or
> a region with reads disabled serves cached rows.
> # In a multi request, the memstore-only check uses the block bytes scanned by
> the whole request.
> # Cells that a coprocessor adds to the results in preGetOp without bypassing
> the Get are cached and served twice.
> # Region#isRowCacheEnabled is added to an interface for coprocessors without
> a default implementation.
> The barriers were also created in several places: each public mutation method
> of HRegion, the bulk load RPC of the region server and the refreshHFiles
> procedure. A coprocessor that bulk loads through HRegion#bulkLoadHFiles or
> refreshes a store directly skips the invalidation, and a single mutation or a
> checkAndMutate creates two or three barriers for the same row. The row level
> barriers are now created in HRegion#batchMutate, which every row mutation
> goes through, and the region level barriers inside HRegion#bulkLoadHFiles and
> HStore#refreshStoreFiles.
> This also adds a missing null check of the row cache in
> HRegion#getScannerWithResults and simplifies how the row cache is looked up
> on region close and in the region server metrics.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)