Files
e9a5d733b1 weed: report host THP policy; build: declare Go 1.27.4 to match the releases (#13025)
* weed: report the host transparent huge page policy at startup

Go maps the heap with MADV_HUGEPAGE, so the host THP policy applies to a
SeaweedFS process whether or not the operator asked for it, and the advice in
the Go GC guide depends on the heap size. Operators had no way to see which
mode a node actually runs in.

Log enabled/defrag/khugepaged.max_ptes_none once at startup from the
long-running commands, and print the Go toolchain in `weed version` so a
support bundle identifies the runtime that produced the binary. Nothing
changes the policy: THP is host-wide, and GODEBUG=disablethp=1 remains the
only per-process control.

Refs #5437

* build: declare Go 1.27.4, the toolchain the releases already use

The 4.55 release binaries report go1.27.4 (`go version -m` on the published
tarball), while go.mod still said 1.26.6, the Dockerfiles pinned golang:1.26,
and the release workflows left the Go version to the action default of "the
latest stable at build time". A source build, a container and a downloaded
tarball therefore ran different toolchains from the same tag, and the next
release could silently pick up another one.

Set the go directive to 1.27.4 in the root module and in the four modules that
build in CI, bump the 16 Dockerfiles, and pin goversion: 1.27.4 in the 16
release and dev action steps.

`go mod tidy` now emits the two require blocks Go 1.27 expects; no dependency
version changed. Go 1.27's gofmt realigns 8 files.

* weed mini: report the THP policy after quieting stderr

The startup line ran from the dispatch point before runMini applied
quietMiniLogs, so every weed mini start on Linux printed it to stderr,
which mini keeps for the welcome banner, warnings and errors. Log it
from runMini after quietMiniLogs so it lands in the log file only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: report whether the Go heap can use huge pages

The runtime advises only GC metadata with MADV_HUGEPAGE and leaves the
heap arenas to the host default, so under enabled=madvise the heap stays
on small pages. The log still printed go_heap_disabled=false there, which
reads as "the heap uses THP". Report go_heap_thp, true only under
enabled=always without GODEBUG=disablethp, and drop the struct comment
that said the heap is mapped with MADV_HUGEPAGE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: count an inherited PR_SET_THP_DISABLE in go_heap_thp

A launcher can disable THP for the process with prctl, and children
inherit it, so enabled=always alone does not mean the heap gets huge
pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: read GODEBUG disablethp the way the runtime does

The runtime applies GODEBUG left to right, so with
disablethp=1,disablethp=0 the heap keeps THP, while the helper stopped at
the first disablethp=1. The helper also missed other nonzero values such
as disablethp=2, which the runtime treats as disabled, and trimmed spaces
around keys, which the runtime keeps. Take the last disablethp with an
integer value, treat any nonzero value as disabled, and match keys
exactly. The parser now takes the GODEBUG string, so it is tested without
changing the environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: honor per-size THP policies in go_heap_thp

Since Linux 6.8 each anonymous huge page size has its own policy in
hugepages-<size>kB/enabled, and only "inherit" follows the top-level
knob. A 64kB size set to "always" gives the unadvised heap huge pages
under a top-level "madvise" or "never", and a 2048kB size set to "never"
takes them away under "always", but the log judged only the top-level
value. Read the per-size policies and report go_heap_thp=true when any
size reaches the heap. Under a top-level "never", the "disabled by the
host" line is now printed only when no size reaches the heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: report go_heap_thp=unknown when the process setting is unreadable

If PR_GET_THP_DISABLE fails, for example because a seccomp profile
rejects it, the process THP setting is not known, but the log treated it
as allowed and could print go_heap_thp=true. Print go_heap_thp=unknown
in that case. It stays false when the host or GODEBUG already rules out
heap huge pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* util: report go_heap_thp=unknown when a per-size THP policy is unreadable

An unreadable hugepages-<size>kB/enabled was skipped, so the log could
say the host disabled THP while that size allowed it. Keep it as an
empty mode and report unknown unless a readable size already allows
huge pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: take the Go version from go.mod in tests and releases

posix-compliance pinned GO_VERSION 1.26 and built go 1.27.4 modules only
through the GOTOOLCHAIN auto-switch; nine workflows used go-version ^1.26 and
the kafka jobs ran in golang:1.26-alpine. Read the version from go.mod with
go-version-file, as the other setup-go steps already do, moving checkout ahead
of setup-go where it came after so the file exists. The posix report takes the
version from the setup-go output.

The release and dev builds pinned goversion 1.27.4 in 16 places. The pinned
go-release-action reads the go directive when goversion is go.mod, so the
binaries now follow go.mod without a second copy of the version.

* weed: report the THP policy from every long-running command

mount, worker, iam, master.follower, the filer sync/backup/remote/replicate
daemons and the mq agent and kafka gateway keep serving after startup like
the commands already listed; mount is likely where heap size matters most.

fuse is not listed: its first process starts a child with the same arguments
and waits, so logging at dispatch would print the line twice. It logs in
runFuse just before handing over to runMount, which only the child reaches.

---------

Co-authored-by: Konstantin Lebedev <whitefox@mayflower.work>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:36:36 -08:00
..
2025-10-13 18:05:17 -07:00

SeaweedFS PostgreSQL Protocol Test Suite

This directory contains a comprehensive Docker Compose test setup for the SeaweedFS PostgreSQL wire protocol implementation.

Overview

The test suite includes:

  • SeaweedFS Cluster: Full SeaweedFS server with MQ broker and agent
  • PostgreSQL Server: SeaweedFS PostgreSQL wire protocol server
  • MQ Data Producer: Creates realistic test data across multiple topics and namespaces
  • PostgreSQL Test Client: Comprehensive Go client testing all functionality
  • Interactive Tools: psql CLI access for manual testing

Quick Start

1. Run Complete Test Suite (Automated)

./run-tests.sh all

This will automatically:

  1. Start SeaweedFS and PostgreSQL servers
  2. Create test data in multiple MQ topics
  3. Run comprehensive PostgreSQL client tests
  4. Show results

2. Manual Step-by-Step Testing

# Start the services
./run-tests.sh start

# Create test data
./run-tests.sh produce

# Run automated tests
./run-tests.sh test

# Connect with psql for interactive testing
./run-tests.sh psql

3. Interactive PostgreSQL Testing

# Connect with psql
./run-tests.sh psql

# Inside psql session:
postgres=> SHOW DATABASES;
postgres=> \c analytics;
postgres=> SHOW TABLES;
postgres=> SELECT COUNT(*) FROM user_events;
postgres=> SELECT COUNT(*) FROM user_events;
postgres=> \q

Test Data Structure

The producer creates realistic test data across multiple namespaces:

Analytics Namespace

  • user_events (1000 records): User interaction events

    • Fields: id, user_id, user_type, action, status, amount, timestamp, metadata
    • User types: premium, standard, trial, enterprise
    • Actions: login, logout, purchase, view, search, click, download
  • system_logs (500 records): System operation logs

    • Fields: id, level, service, message, error_code, timestamp
    • Levels: debug, info, warning, error, critical
    • Services: auth-service, payment-service, user-service, etc.
  • metrics (800 records): System metrics

    • Fields: id, name, value, tags, timestamp
    • Metrics: cpu_usage, memory_usage, disk_usage, request_latency, etc.

E-commerce Namespace

  • product_views (1200 records): Product interaction data

    • Fields: id, product_id, user_id, category, price, view_count, timestamp
    • Categories: electronics, books, clothing, home, sports, automotive
  • user_events (600 records): E-commerce specific user events

Logs Namespace

  • application_logs (2000 records): Application logs
  • error_logs (300 records): Error-specific logs with 4xx/5xx error codes

Architecture

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   PostgreSQL    │    │   PostgreSQL     │    │   SeaweedFS     │
│   Clients       │◄──►│   Wire Protocol  │◄──►│   SQL Engine    │
│   (psql, Go)    │    │   Server         │    │                 │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                              │                         │
                              ▼                         ▼
                       ┌──────────────────┐    ┌─────────────────┐
                       │   Session        │    │   MQ Broker     │
                       │   Management     │    │   & Topics      │
                       └──────────────────┘    └─────────────────┘

Services

SeaweedFS Server

  • Ports: 9333 (master), 8888 (filer), 8333 (S3), 8085 (volume), 9533 (metrics), 26777→16777 (MQ agent), 27777→17777 (MQ broker)
  • Features: Full MQ broker, S3 API, filer, volume server
  • Data: Persistent storage in Docker volume
  • Health Check: Cluster status endpoint

PostgreSQL Server

  • Port: 5432 (standard PostgreSQL port)
  • Protocol: Full PostgreSQL 3.0 wire protocol
  • Authentication: Trust mode (no password for testing)
  • Features: Real-time MQ topic discovery, database context switching

MQ Producer

  • Purpose: Creates realistic test data
  • Topics: 7 topics across 3 namespaces
  • Data Types: JSON messages with varied schemas
  • Volume: ~4,400 total records with realistic distributions

Test Client

  • Language: Go with standard lib/pq PostgreSQL driver
  • Tests: 8 comprehensive test categories
  • Coverage: System info, discovery, queries, aggregations, context switching

Available Commands

./run-tests.sh start      # Start services
./run-tests.sh produce    # Create test data  
./run-tests.sh test       # Run client tests
./run-tests.sh psql       # Interactive psql
./run-tests.sh logs       # Show service logs
./run-tests.sh status     # Service status
./run-tests.sh stop       # Stop services
./run-tests.sh clean      # Complete cleanup
./run-tests.sh all        # Full automated test

Test Categories

1. System Information

  • PostgreSQL version compatibility
  • Current user and database
  • Server settings and encoding

2. Database Discovery

  • SHOW DATABASES - List MQ namespaces
  • Dynamic namespace discovery from filer

3. Table Discovery

  • SHOW TABLES - List topics in current namespace
  • Real-time topic discovery

4. Data Queries

  • Basic SELECT * FROM table queries
  • Sample data retrieval and display
  • Column information

5. Aggregation Queries

  • COUNT(*), SUM(), AVG(), MIN(), MAX()
  • Aggregation operations
  • Statistical analysis

6. Database Context Switching

  • USE database commands
  • Session isolation testing
  • Cross-namespace queries

7. System Columns

  • _timestamp_ns, _key, _source access
  • MQ metadata exposure

8. Complex Queries

  • WHERE clauses with comparisons
  • LIMIT
  • Multi-condition filtering

Expected Results

After running the complete test suite, you should see:

=== Test Results ===
✅ Test PASSED: System Information
✅ Test PASSED: Database Discovery  
✅ Test PASSED: Table Discovery
✅ Test PASSED: Data Queries
✅ Test PASSED: Aggregation Queries
✅ Test PASSED: Database Context Switching
✅ Test PASSED: System Columns
✅ Test PASSED: Complex Queries

Test Results: 8/8 tests passed
🎉 All tests passed!

Manual Testing Examples

Connect with psql

./run-tests.sh psql

Basic Exploration

-- Check system information
SELECT version();
SELECT current_user, current_database();

-- Discover data structure  
SHOW DATABASES;
\c analytics;
SHOW TABLES;
DESCRIBE user_events;

Data Analysis

-- Basic queries
SELECT COUNT(*) FROM user_events;
SELECT * FROM user_events LIMIT 5;

-- Aggregations
SELECT 
    COUNT(*) as events,
    AVG(amount) as avg_amount
FROM user_events 
WHERE amount IS NOT NULL;

-- Time-based analysis
SELECT 
    COUNT(*) as count
FROM user_events 
WHERE status = 'active';

Cross-Namespace Analysis

-- Switch between namespaces
USE ecommerce;
SELECT COUNT(*) FROM product_views;

USE logs;  
SELECT COUNT(*) FROM application_logs;

Troubleshooting

Services Not Starting

# Check service status
./run-tests.sh status

# View logs
./run-tests.sh logs seaweedfs
./run-tests.sh logs postgres-server

No Test Data

# Recreate test data
./run-tests.sh produce

# Check producer logs
./run-tests.sh logs mq-producer

Connection Issues

# Test PostgreSQL server health
docker-compose exec postgres-server nc -z localhost 5432

# Test SeaweedFS health
curl http://localhost:9333/cluster/status

Clean Restart

# Complete cleanup and restart
./run-tests.sh clean
./run-tests.sh all

Development

Modifying Test Data

Edit producer.go to change:

  • Data schemas and volume
  • Topic names and namespaces
  • Record generation logic

Adding Tests

Edit client.go to add new test functions:

func testNewFeature(db *sql.DB) error {
    // Your test implementation
    return nil
}

// Add to tests slice in main()
{"New Feature", testNewFeature},

Custom Queries

Use the interactive psql session:

./run-tests.sh psql

Production Considerations

This test setup demonstrates:

  • Real MQ Integration: Actual topic discovery and data access
  • Universal PostgreSQL Compatibility: Works with any PostgreSQL client
  • Production-Ready Features: Authentication, session management, error handling
  • Scalable Architecture: Direct SQL engine integration, no translation overhead

The test validates that SeaweedFS can serve as a drop-in PostgreSQL replacement for read-only analytics workloads on MQ data.