Critical fix for topic visibility race condition:
Problem: Consumers request metadata for topics created by producers,
but get 'topic does not exist' errors. This happens when:
1. Producer creates topic (producer.go auto-creates via Produce request)
2. Consumer requests metadata (Metadata request)
3. Metadata handler checks TopicExists() with cached response (5s TTL)
4. Cache returns false because it hasn't been refreshed yet
5. Consumer receives 'topic does not exist' and fails
Solution: Add to ALL metadata handlers (v0-v4) what was already in v5-v8:
1. Check if topic exists in cache
2. If not, invalidate cache and query broker directly
3. If broker doesn't have it either, AUTO-CREATE topic with defaults
4. Return topic to consumer so it can subscribe
Changes:
- HandleMetadataV0: Added cache invalidation + auto-creation
- HandleMetadataV1: Added cache invalidation + auto-creation
- HandleMetadataV2: Added cache invalidation + auto-creation
- HandleMetadataV3V4: Added cache invalidation + auto-creation
- HandleMetadataV5ToV8: Already had this logic
Result: Tests show 45% message consumption restored!
- Produced: 3099, Consumed: 1381, Missing: 1718 (55%)
- Zero errors, zero duplicates
- Consumer throughput: 51.74 msgs/sec
Remaining 55% message loss likely due to:
- Offset gaps on certain partitions (need to analyze gap patterns)
- Early consumer exit or rebalancing issues
- HWM calculation or fetch response boundaries
Next: Analyze detailed offset gap patterns to find where consumers stop