Object Store Support

MynaDB supports cloud object storage backends including AWS S3, MinIO, and Aliyun OSS. This enables scalable, cost-effective storage for large time series datasets.

Storage Architecture

text
┌─────────────────────────────────────────────────────────────┐
│                        MynaDB                                │
│                                                              │
│   ┌─────────────────┐    ┌─────────────────────────────┐    │
│   │   Write Path    │    │        Read Path            │    │
│   │                 │    │                             │    │
│   │  DataCache      │    │  QueryEngine                │    │
│   │  (In-Memory)    │    │  (DataFusion)               │    │
│   └────────┬────────┘    └──────────────┬──────────────┘    │
│            │                            │                    │
│            ▼                            ▼                    │
│   ┌─────────────────────────────────────────────────────┐   │
│   │              Storage Abstraction Layer               │   │
│   │                                                      │   │
│   │   • Local Filesystem                                 │   │
│   │   • AWS S3                                           │   │
│   │   • MinIO                                            │   │
│   │   • Aliyun OSS                                       │   │
│   └──────────────────────────┬──────────────────────────┘   │
└──────────────────────────────┼──────────────────────────────┘
                               │
            ┌──────────────────┼──────────────────┐
            │                  │                  │
            ▼                  ▼                  ▼
    ┌──────────────┐   ┌──────────────┐   ┌──────────────┐
    │   AWS S3     │   │    MinIO     │   │  Aliyun OSS  │
    │              │   │              │   │              │
    │  s3://bucket │   │  minio://    │   │  oss://      │
    └──────────────┘   └──────────────┘   └──────────────┘

Configuration

Local Storage (Default)

toml
[storage]
# Local filesystem storage
backend = "local"
data_dir = "/data/mynadb"

AWS S3

toml
[storage]
backend = "s3"
data_dir = "/data/mynadb"  # Local cache/WAL directory

[storage.s3]
bucket = "my-mynadb-bucket"
region = "us-west-2"

# Credentials (optional if using IAM roles)
access_key = "AKIAIOSFODNN7EXAMPLE"
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

# Optional: custom endpoint for S3-compatible services
# endpoint = "https://s3.us-west-2.amazonaws.com"

# Optional: path prefix within bucket
prefix = "mynadb-data"

MinIO

toml
[storage]
backend = "minio"
data_dir = "/data/mynadb"

[storage.s3]
bucket = "mynadb"
region = "us-east-1"  # Can be any value for MinIO

# MinIO credentials
access_key = "minioadmin"
secret_key = "minioadmin"

# MinIO endpoint
endpoint = "http://localhost:9000"

# Allow HTTP (required for local MinIO)
allow_http = true

Aliyun OSS

toml
[storage]
backend = "oss"
data_dir = "/data/mynadb"

[storage.s3]
bucket = "my-oss-bucket"
region = "oss-cn-hangzhou"

# Aliyun credentials
access_key = "your-access-key-id"
secret_key = "your-access-key-secret"

# OSS endpoint
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"

Setting Up MinIO (Local Development)

Docker Setup

bash
# Run MinIO with Docker
docker run -d \
  --name minio \
  -p 9000:9000 \
  -p 9001:9001 \
  -e MINIO_ROOT_USER=minioadmin \
  -e MINIO_ROOT_PASSWORD=minioadmin \
  -v minio-data:/data \
  minio/minio server /data --console-address ":9001"

# Create a bucket using MinIO client
docker exec minio mc alias set local http://localhost:9000 minioadmin minioadmin
docker exec minio mc mb local/mynadb

Docker Compose

yaml
version: '3.8'
services:
  minio:
    image: minio/minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    command: server /data --console-address ":9001"
    volumes:
      - minio-data:/data

  mynadb:
    image: mynadb:latest
    ports:
      - "7000:7000"
      - "7001:7001"
    volumes:
      - ./config.toml:/etc/mynadb/config.toml
    depends_on:
      - minio

volumes:
  minio-data:

IAM Role Authentication (AWS)

When running on AWS (EC2, ECS, EKS), you can use IAM roles instead of access keys:

toml
[storage]
backend = "s3"
data_dir = "/data/mynadb"

[storage.s3]
bucket = "my-mynadb-bucket"
region = "us-west-2"
# No access_key or secret_key - uses IAM role

Required IAM Policy

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::my-mynadb-bucket",
        "arn:aws:s3:::my-mynadb-bucket/*"
      ]
    }
  ]
}

File Cache for Object Store

When using Object Store, enable the file cache to reduce latency:

toml
[file_cache]
# Enable file caching (highly recommended for Object Store)
enabled = true

# Local SSD cache directory
cache_dir = "/var/cache/mynadb/parquet"

# Maximum cache size (100 GB)
max_size_bytes = 107374182400

# Save cache index every 5 minutes
auto_save_interval_secs = 300

Data Layout

MynaDB organizes data in Object Store using the following structure:

text
s3://bucket/[prefix]/
├── catalog_name/
│   ├── schema_name/
│   │   └── table_name/
│   │       ├── date=2024-01-15/
│   │       │   ├── L0_abc123.parquet
│   │       │   ├── L0_def456.parquet
│   │       │   └── L1_merged_001.parquet
│   │       └── date=2024-01-16/
│   │           └── L0_ghi789.parquet
│   └── _system/
│       └── series_stats/
│           └── catalog_name.parquet
└── _metadata/
    └── catalog_snapshot.json

Performance Considerations

Network Latency

Write Performance

Read Performance

Monitoring

bash
# Check storage stats
curl http://localhost:7000/stats

# Check cache stats (includes file cache)
curl http://localhost:7000/cache/stats

# List files in a table
curl http://localhost:7000/partitions/mydb/default/cpu

Migration

Local to S3

bash
# 1. Stop MynaDB
systemctl stop mynadb

# 2. Sync data to S3
aws s3 sync /data/mynadb s3://my-bucket/mynadb-data/

# 3. Update config.toml to use S3
# 4. Start MynaDB
systemctl start mynadb

S3 to Local

bash
# 1. Stop MynaDB
systemctl stop mynadb

# 2. Sync data from S3
aws s3 sync s3://my-bucket/mynadb-data/ /data/mynadb

# 3. Update config.toml to use local storage
# 4. Start MynaDB
systemctl start mynadb