Skip to content

Prevent stale device schema cache after concurrent LAST queries and deletion - #19417

Open
alpass163 wants to merge 3 commits into
apache:masterfrom
alpass163:cyb/fix_last_delete_concurrent_bug
Open

alpass163 wants to merge 3 commits into
apache:masterfrom
alpass163:cyb/fix_last_delete_concurrent_bug

Conversation

@alpass163

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the race between LAST queries, write execution, and schema deletion that could restore device schema
entries after a delete procedure had cleaned the cache. The device schema cache is now written only by the analyze-time
schema fetch; LAST queries and write execution update last values only.

Problem

A LAST query can be analyzed before a deletion but declare or put back its result after the first cache invalidation.
Previously this path also wrote device schema, so the deleted schema could be restored after cleanup. A later INSERT
then hit the stale cache entry, skipped auto-creation, wrote data, and left metadata absent. The same class of issue
existed for write FI execution, fenced DataNodes, and concurrent LAST queries with different put-back orders.

Changes

  • LAST declare/put-back no longer writes device schema.
  • All-null LAST results cache the empty marker or remove a previously cached value; a valid value arriving after an
    all-null marker removes the entry.
  • Delete procedures append a second cache cleanup state after data deletion and before metadata deletion. New states are
    appended to existing enums for ordinal compatibility.
  • DELETE DATABASE invalidates the DN device cache after region deletion.
  • Write FI execution updates last values only.
  • Fenced DataNodes skip device-cache writes.
  • Fragment failure clears the devices declared by the query attempt and suppresses later put-back.
  • The second table-cache cleanup only touches TableDeviceSchemaCache; an optional TInvalidateTableCacheReq field
    distinguishes it from the first cleanup that also updates DataNodeTableCache.
  • Last-cache and attribute memory accounting edge cases are fixed.

Compatibility

  • Existing procedure state IDs are unchanged; new states are appended.
  • The Thrift change is an optional field with backward-compatible default behavior.
  • No data or metadata format changes.

…ies run concurrently with delete time series, or insert data between delete data

@Caideyipi Caideyipi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed commit 31f12aa9f7944fe6247d86952f9f020b6ca4d01c against merge base 45cb9959f16bb5350c136b0e5ca6847cde853d2b. Found one behavioral issue: procedures persisted by the previous version at their old post-delete successor state can bypass the new second cache invalidation. I also left a naming-convention comment on the new log constants. git diff --check passed; no tests were run locally. Required CI checks were pending at review time.

public static final String FAILED_TO_INVALIDATE_SCHEMAENGINE_CACHE_OF_DEVICES_IN_TABLE =
"Failed to invalidate schemaEngine cache of devices in table {}.{}";
public static final String
FAILED_TO_INVALIDATE_SCHEMAENGINE_CACHE_OF_DEVICES_IN_TABLE_FIRST_TIME =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] Follow the required i18n log-key naming convention. These newly added constants are used as logger templates, but repository guidance requires logger keys to use LOG_<NORMALIZED>_<HASH> with matching en/zh names. Please rename the added log constants accordingly; the current names are unprefixed semantic names.

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.

2 participants