Storage
The memory your machines deserve. MynaDB stores time series data in Apache Parquet format, a columnar storage format optimized for analytical queries. This page explains the storage architecture, partitioning strategy, and optimization techniques.
Overview
Write Path Storage
| |
v v
+--------+ Flush +---------------------------+
| Cache | ------------> | Parquet Files |
| (RAM) | (30s) | |
+--------+ | data/ |
| └── mydb/ |
| └── default/ |
| └── cpu/ |
| └── date=.../ |
| ├── L0_... |
| ├── L1_... |
| └── L2_... |
+---------------------------+
Key Features
- Columnar Storage - Read only the columns you need
- Compression - Up to 90% storage reduction
- Date Partitioning - Efficient time-range queries
- LSM Levels - Optimized read/write balance
- Predicate Pushdown - Filter at storage level
Apache Parquet Format
Apache Parquet is a columnar storage format designed for efficient data processing. It's the foundation of MynaDB's high-performance storage.
Why Parquet?
Columnar Layout
Data is stored by column, not by row. Queries that access few columns read less data.
Compression
Similar values in a column compress well. Supports Snappy, ZSTD, LZ4, and more.
Predicate Pushdown
Statistics in file footer allow skipping irrelevant row groups.
Ecosystem
Works with Spark, Pandas, DuckDB, DataFusion, and many other tools.
Parquet File Structure
+------------------------------------------+
| Parquet File |
+------------------------------------------+
| Row Group 1 |
| +--------------------------------------+|
| | Column Chunk: timestamp ||
| | Column Chunk: host ||
| | Column Chunk: usage ||
| +--------------------------------------+|
| |
| Row Group 2 |
| +--------------------------------------+|
| | Column Chunk: timestamp ||
| | Column Chunk: host ||
| | Column Chunk: usage ||
| +--------------------------------------+|
| |
| Footer (Schema + Statistics) |
+------------------------------------------+
Directory Structure
MynaDB organizes files in a hierarchical structure:
data/
├── {catalog}/ # Database name
│ ├── {schema}/ # Schema (service or "default")
│ │ └── {table}/ # Measurement name
│ │ └── date=YYYY-MM-DD/ # Date partition
│ │ ├── L0_xxx.parquet # Level 0 (recent writes)
│ │ ├── L0_yyy.parquet
│ │ ├── L1_aaa.parquet # Level 1 (compacted)
│ │ └── L2_bbb.parquet # Level 2 (more compacted)
│ └── _system/
│ └── series_stats/ # Cardinality tracking
│ └── {catalog}.parquet
│
└── mydb/ # Example database
├── default/
│ ├── cpu/
│ │ ├── date=2024-01-15/
│ │ │ ├── L0_1705312345_abc.parquet
│ │ │ └── L1_1705398745_def.parquet
│ │ └── date=2024-01-16/
│ │ └── L0_1705398800_ghi.parquet
│ └── memory/
│ └── date=2024-01-15/
└── web/
└── requests/
Date Partitioning
Data is automatically partitioned by date based on the timestamp of each data point. This enables efficient time-range queries by skipping irrelevant partitions.
How It Works
- Each data point's timestamp is extracted
- Date is derived:
YYYY-MM-DD - Data is written to the corresponding partition directory
- Queries with time filters skip unneeded partitions
# Data written with timestamp 2024-01-15T10:30:00Z
cpu,host=server01 usage=75.5 1705315800000000000
# Stored in:
data/mydb/default/cpu/date=2024-01-15/L0_xxx.parquet
# Query only reads date=2024-01-15 partition
SELECT * FROM cpu
WHERE time >= '2024-01-15' AND time < '2024-01-16'
Partition Pruning
When you filter by time, only relevant partitions are scanned:
| Query | Partitions Scanned |
|---|---|
WHERE time > '2024-01-15' |
Only date=2024-01-15 and later |
WHERE time BETWEEN '2024-01-10' AND '2024-01-12' |
Only 3 partitions |
SELECT * FROM cpu (no filter) |
All partitions |
Managing Partitions
# List partitions
curl http://localhost:7000/partitions/mydb/default/cpu
# Delete a specific partition
curl -X DELETE http://localhost:7000/partitions/mydb/default/cpu/2024-01-15
# Delete old partitions (retention)
curl -X POST http://localhost:7000/retention/mydb/default/cpu \
-H "Content-Type: application/json" \
-d '{"older_than_days": 30}'
File Naming Convention
Parquet files follow a naming convention that encodes metadata:
L{level}_{timestamp}_{uuid}.parquet
# Examples:
L0_1705312345_a1b2c3d4.parquet # Level 0, recent write
L1_1705398745_e5f6g7h8.parquet # Level 1, compacted
L2_1705485145_i9j0k1l2.parquet # Level 2, more compacted
| Component | Description |
|---|---|
L{level} |
Compaction level (L0-L5) |
{timestamp} |
Unix timestamp when file was created |
{uuid} |
Unique identifier to prevent collisions |
Compression
Parquet supports multiple compression codecs. MynaDB uses Snappy by default for a good balance of speed and compression ratio.
Compression Codecs
| Codec | Ratio | Speed | Use Case |
|---|---|---|---|
| Snappy | Good | Fast | Default, balanced |
| ZSTD | Better | Medium | Cold storage |
| LZ4 | Lower | Fastest | Real-time queries |
| GZIP | Best | Slow | Archival |
Compression Effectiveness
Time series data compresses very well due to:
- Repeated tags - Same host/region values
- Similar values - Metrics change gradually
- Columnar layout - Similar data grouped together
- Dictionary encoding - String deduplication
Time series data typically achieves 5-10x compression with Snappy, and 10-20x with ZSTD. A 100GB raw dataset might compress to 10GB or less.
Storage Optimization
Best Practices
- Use SSD storage - Random reads are common for queries
- Enable compaction - Reduces file count and improves query performance
- Set retention policies - Prevent unbounded growth
- Monitor disk usage - Plan capacity based on ingestion rate
Estimating Storage
Approximate storage calculation:
# Formula (approximate)
Storage = (points_per_second) × (bytes_per_point) × (seconds) × (1/compression_ratio)
# Example: 10,000 points/sec, 50 bytes/point, 30 days, 10x compression
Storage = 10,000 × 50 × (30 × 86400) / 10
= 10,000 × 50 × 2,592,000 / 10
= 129.6 GB
Disk Space Management
# Check disk usage
du -sh /data/stats/*
# Check by database
du -sh /data/stats/mydb/*
# Check by table
du -sh /data/stats/mydb/default/cpu/*
# Force compaction to reduce file count
curl -X POST http://localhost:7000/compact/mydb
# Apply retention to free space
curl -X POST http://localhost:7000/retention/mydb/default/cpu \
-H "Content-Type: application/json" \
-d '{"older_than_days": 7}'
Backup and Recovery
Since data is stored as standard Parquet files, backup is straightforward:
# Backup entire database
tar -czf mydb_backup.tar.gz /data/stats/mydb/
# Backup specific table
tar -czf cpu_backup.tar.gz /data/stats/mydb/default/cpu/
# Restore
tar -xzf mydb_backup.tar.gz -C /data/stats/