Cloudera CDP-3002 study materials
Cloudera CDP-3002 study resources

Hive ACID Compaction Debt from Five-Minute Streaming

Cloudera CDP-3002 · Put your knowledge to work in context.

All case studies

Hive ACID Compaction Debt from Five-Minute Streaming

A CDP Private Cloud Base 7.1.9 deployment supports a Hive 3 ACID table web_events with 14,000 daily partitions. NiFi ingests every five minutes, producing one delta directory per batch; each partition accumulates about 288 delta directories and 1,800 small ORC files per day. The table is 850 TB; HDFS is 61% full. Analysts query the last seven days, but queries now scan 2,000+ files per partition and p95 latency has tripled. SHOW COMPACTIONS lists 9,400 queued or working compactions, and the compaction initiator logs 'Not enough workers'. The HMS has 2.8 million partitions across all tables; NameNode RPC latency is elevated. The team proposes increasing hive.compactor.worker.threads from 2 to 32 on the HiveServer2 host and running MSCK REPAIR TABLE nightly. You need a plan that improves read latency without saturating HDFS or breaking streaming ingestion.

1. Diagnose the root cause and decide whether raising compactor workers to 32 is safe by itself. What evidence should be gathered first?

Read the worked answer

The symptom is metadata and small-file amplification, not a capacity shortage. Each five-minute batch creates a delta directory, so a partition can contain 288 deltas and 1,800 ORC files in one day. A query over seven days must open thousands of files, which increases ORC reader overhead, NameNode RPCs, and HMS partition/file lookups. The 9,400-entry compaction backlog confirms that compaction is not keeping up, while 61% HDFS usage shows space is not the immediate constraint.

Raising workers from 2 to 32 on the HiveServer2 host is risky. Compaction consumes MapReduce or Tez containers, HDFS read/write bandwidth, NameNode RPC, and HMS capacity. Thirty-two workers can starve interactive HiveServer2 sessions, increase write amplification, and compete with Spark/Impala. It also does not fix the root cause: five-minute micro-batches will keep producing deltas faster than a poorly placed compactor can rewrite them, especially if major compaction runs on hot partitions during peak hours.

MSCK REPAIR TABLE is the wrong tool here. The partitions already exist; MSCK only reconciles directory layout with the metastore, and it can be expensive at this scale. It does not merge delta directories or small ORC files.

Gather evidence first: SHOW COMPACTIONS for queued, initiated, and failed entries; file and delta counts per partition from HDFS; EXPLAIN on a representative query; HMS and NameNode RPC metrics; compactor logs and worker timeouts; MR/Tez queue utilization; and whether major or minor compactions dominate. Also check whether the table is full ACID or insert-only, because insert-only tables have different compaction needs.

2. Design the ingestion and compaction changes. Include thresholds, worker sizing, partition scope, and scheduling so read latency improves without breaking exactly-once streaming.

Read the worked answer

Start by reducing delta creation. Move NiFi from five-minute to 15-minute batches where the SLA allows, cutting 288 deltas per day to 96; a 30-minute batch cuts it to 48. Preserve exactly-once behavior with NiFi provenance, deterministic transaction IDs, and retry idempotency. If the source demands five-minute latency, land raw events in a staging area and write to the ACID table in larger batches rather than shrinking compaction intervals further.

Enable and size compaction deliberately. On the HMS set hive.compactor.initiator.on=true. Place compactor workers on dedicated HiveServer2 or compaction hosts, not the busiest interactive HS2, and set hive.compactor.worker.threads to something the MR/Tez queue can absorb, for example 6 to 8, then measure. Raise thresholds so minor compaction does not run after every few deltas: hive.compactor.delta.num.threshold=50, hive.compactor.delta.pct.threshold=0.2, and consider hive.compactor.abortedtxn.threshold=10. Tune hive.compactor.check.interval to 600 seconds or more so the initiator does not scan the entire 2.8-million-partition metastore too aggressively.

Scope major compaction. Run major compaction against partitions older than seven days during an off-peak window, one partition range at a time. Keep recent hot partitions on minor compaction only; a major compaction on the current day's partition rewrites large base files while streaming is still writing and can cause conflicts and extra I/O. Use a separate YARN queue or Tez queue for compaction with a capacity cap so it cannot consume all interactive resources. Also collect Hive statistics after compaction, because stale stats can keep the optimizer choosing bad plans even after files are merged.

3. If the business refuses to change the five-minute ingestion cadence, what alternative would you evaluate? Compare it with Hive ACID compaction and state the migration risks.

Read the worked answer

If five-minute writes are fixed, evaluate an insert-only ACID table or an Iceberg table. An insert-only Hive ACID table avoids delete-delta accumulation and the full major-compaction burden, but it still creates small files, so you still need periodic file consolidation or a table format that manages files better. It is appropriate only if the workload truly has no updates or deletes.

Iceberg is the stronger alternative for this pattern. It supports hidden partitioning, snapshot-based reads, and explicit file maintenance through rewrite_data_files, rewrite_manifests, and expire_snapshots. A Spark Structured Streaming or NiFi-to-Spark writer can commit every five minutes while compaction is a scheduled table maintenance job rather than an HMS compactor backlog. Readers see consistent snapshots, and partition metadata does not depend on registering 2,500 HMS partitions per day. The trade-off is a new write path, new catalog behavior, and retraining analysts who use Hive/Impala SQL.

Compare on operational cost, not only query speed. Hive ACID compaction is native to the existing table and SQL, but the backlog, worker placement, major-compaction rewrites, and HMS scale are ongoing costs. Iceberg reduces small-file and partition-registration debt but requires validating Impala and Hive support in your CDP version, handling snapshot expiration, and rewriting ingestion.

Migrate in stages: create the Iceberg table with the same logical schema and partition model, dual-write or backfill a bounded date range, compare row counts and query results, run rewrite_data_files to establish a compact baseline, then switch readers and stop Hive writes. Keep the Hive table read-only for rollback until the new SLA is stable. Do not migrate all 850 TB at once.