Best practices for materialized views

Adhere to the following guidelines to avoid inconsistency between base tables and materialized views.

Because there is currently no automatic mechanism to detect and fix inconsistencies between the base and view (other than dropping and recreating the view), adhere to the following best practices to ensure consistency between the base and table views.
  • Write to base tables with materialized views using consistency levels greater than ONE (such as LOCAL_QUORUM) to avoid base-view inconsistency. Alternatively, use the -Dmv_enable_coordinator_batchlog=true option to provide better protection against a coordinator failing in the middle of a request.
    Note: Using the -Dmv_enable_coordinator_batchlog=true option will slow the view write operation considerably.
  • Run repair on both the base table and the view whenever a node is removed, replaced, down for longer than the value specified by max_hint_window_in_ms, or a new datacenter is added. This recommendation is valid to prevent data loss for any tables, not just tables with materialized views.
  • Run repair periodically on views (at least one time every period specified by gc_grace_seconds) to ensure that tombstones for views are successfully propagated to all replicas, and to prevent data resurrection. This recommendation is valid for any tables where delete operations occurred, such as manually denormalized tables.