jeremyhi 10893e0412 feat: report a downgraded region's last entry once durable and roll back for skip-WAL rows (#10765)
* feat: report a downgraded region's last entry once durable and roll back for skip-WAL rows

A downgrade of a region whose manifest is published conditionally (writes
require a lease and the WAL is the object store WAL) no longer flushes
unless the memtable holds rows that are not in the WAL; the next leader
recovers the rest from the source's WAL. A change to Follower reports the
last entry id only once the WAL is durable through it.

A downgrade reply now carries `has_skip_wal_writes` when the region may
still hold rows outside the WAL after the downgrade; the metasrv then
rolls the migration back instead of retrying or taking the region over,
and aborts with that reason. An empty memtable left marked by a failed
write no longer reports such rows.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: flush a downgrading region that skips the WAL and tighten tests

A handover of a region whose options skip the WAL records no tail of its
source, so a downgrade now flushes such a region even when its memtable
holds only rows logged before the option changed.

Tests cover that case, the metadata region's rows on the Noop WAL, a
Follower change that waits without holding the worker and again on a
region that is already a Follower, a flagged reply after an unflagged
one in the same batch, the failure of a write that installs no row, and
the abort reason of a failed candidate upgrade. Docs scope the meaning
of a false `has_skip_wal_writes` and of the metadata region's flush.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: report logged rows of a region that skips the WAL and bound an abandoned downgrade

A region whose options skip the WAL is handed over without a tail of its
source, so its unflushed rows count as rows the next leader cannot
recover from the WAL: `MitoRegion::has_skip_wal_writes` reports them and
decides the downgrade's flush, so a follower that cannot flush them rolls
the migration back.

The datanode bounds each region's downgrade, the flush and the change to
Follower together, by its flush timeout and replies with a retryable
error past it. The task that waits for the WAL to be durable stops
waiting once nobody waits for its reply, and a role change builds the
durability barrier only for a Follower.

Tests cover a follower whose options were made to skip the WAL, with and
without rows, a downgrade timeout that releases the region, and a
rollback of two requested regions; the abort reason of a failed
candidate upgrade is compared exactly.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: refuse a handover to a candidate with stale skip-WAL options

A candidate whose options skip the WAL commits an empty handover, which
records no tail of its source. An ALTER during the migration reaches only
the routed source, so a candidate can still skip the WAL while the source
logs rows it does not flush. Such a handover now fails, committing
nothing, when the source has unflushed WAL entries; the error is not
retryable, since only closing the candidate after the rollback fixes its
options.

The datanode waits for a shared downgrade flush without its own timer,
under the downgrade's single bound. Docs describe the rollback reason as
rows the candidate may not recover from the WAL, and when a false flag
can be trusted. Tests cover the refused handover and its recovery once
the options match, a flagged reply carrying an error, and a downgrade
timeout that waits until the durability wait is admitted.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: split the abandoned downgrade test and cover a deadline used up by the last attempt

The datanode test of a timed-out downgrade no longer waits for the
durability wait to be admitted, which raced the deadline; a Mito test
drops the reply of a Follower change once its wait is admitted and
checks that the region is released. A metasrv test covers a last
downgrade attempt whose mailbox expiry uses up the procedure's time:
the candidate upgrade then rolls the migration back without sending
anything. The rollback test keeps a flagged success and a flagged error.

Docs describe the skip-WAL predicate as rows the next leader may not
recover, scope the durability comment to a Follower change, note that
the metasrv must also understand the flag, and say why a refused
handover is not retried.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: scope the mock leader to the downgrade deadline test

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* refactor: report only skip-WAL rows now that a handover records the source's tail

A handover or takeover now records the source's tail even when the
candidate's options skip the WAL, so the rows a region logged before its
options turned skip_wal on are recovered from that tail. The downgrade
flush and the flag therefore count only rows written without the WAL:
every other row in the memtable is in the WAL up to the reported last
entry, which the Follower change still waits to be durable whatever the
region's options.

Tests run the source through the graceful downgrade: rows logged before
the option, with and without an earlier flush, reach a candidate by a
handover or by a takeover after the report was lost; a candidate that a
rolled-back migration left awaiting its Leader lease recovers the rows
the source logged since; a downgrade under enqueued acknowledgement
waits for those rows to be durable; and rows written while the WAL was
skipped stay reported after the option is turned off again.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: release the region before the durability wait and tighten downgrade tests

The task that changes a region to Follower finishes the work that needs
the region, including the fencing notification, before it waits for
the last entry to become durable, so a pending wait holds only the last
entry id, the barrier and the reply.

Tests check that a downgrade of an object store WAL region without
write leases still flushes, that each setup role change succeeds, and
that an abandoned wait is dropped, observed through the log store it
holds. Docs state the durability barrier per provider.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: cover a mixed downgrade flush, the flag on a timed-out downgrade and its abort reason

A downgrade's flush of logged and skip-WAL rows persists both, as a
reopen without WAL replay shows. A downgrade that times out still
reports the skip-WAL rows its region holds. The last downgrade attempt
that uses up the deadline aborts as a failed candidate upgrade. The
timeout reply is built in a match that rustfmt formats.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* docs: scope the downgrade flush skip and the reply fixture wording

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: let the only downgrade attempt use up the deadline

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: reply to a role change before the fencing notice unless a Follower waits for its WAL

Only a successful change to Follower notifies, releases the region and waits for its WAL before it replies; every other outcome replies first, as before. Log the entry the wait is for and an abandoned wait, and describe the deadline test's lease as ending with the procedure's time.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: drop the retry interval the single-attempt deadline test never waits

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: reply to a Leader change before its sweep, and check the partial-flush handover's bound

A successful change to Leader replies before it schedules the HDFS temp-file sweep, as before. The partial-flush handover case asserts that the source's flushed entry id is the first batch's last entry, strictly between zero and the final entry. The region server's skip-WAL accessor is crate-visible.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* docs: say which logged rows a handover and a takeover recover after a downgrade skips its flush

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: skip a retried downgrade's flush of a metric metadata region that is already a Follower

A downgrade whose change to Follower timed out after the metadata region became a Follower is retried with a Downgrading flush, which failed on the metadata region because a Follower is not flushable, so every retry failed. The flush now skips that region; its handover still fails while it holds entries its manifest does not cover. Drop tests that decide no condition this change adds, and tighten doc wording.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* fix: flush a metric metadata Follower that still holds rows on a retried downgrade

Skip the retried downgrade's flush of the metadata region only when it is a Follower whose memtables are empty; one that still holds rows gets the flush, which fails as before. Restore the check that a flagged downgrade reply decodes into the pre-field layout.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: check the reason first and fence the pair in the dirty metadata Follower test

Read the metadata region's role and memtables only for a Downgrading flush. The dirty metadata Follower test sets the pair to DowngradingLeader through the metric engine, as the downgrade handler does, and checks that the flush fails on the Follower.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* test: check that only a downgrade's flush skips a flushed metadata Follower

The clean retry first sends a flush without a reason, which still fails on the metadata Follower, then the downgrade's flush, which skips it. A shared helper changes a role and asserts that it succeeded.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

* style: address review nits on the downgrade reply and flush test

Name the role states through SettableRegionRoleState instead of importing its variants, order the derives of DowngradeRegionReply as elsewhere in the file, and drop the comment that restates the role helper.

Signed-off-by: jeremyhi <jiachun_feng@proton.me>

---------

Signed-off-by: jeremyhi <jiachun_feng@proton.me>
2026-12-03 10:36:04 +00:00
2023-08-10 08:08:37 +00:00
2023-06-25 11:05:46 +08:00
2023-11-09 10:38:12 +00:00

GreptimeDB Logo

Metrics, logs, and traces.
One engine, on your infrastructure.

User Guide  ·  API Docs  ·  Live Demo  ·  Roadmap 2026  ·  Slack

Stable Canary Nightly Docker Pulls License

stable for production  ·  canary includes pre-releases  ·  nightly is a weekly snapshot of main

Introduction

GreptimeDB is an open-source observability database. Metrics, logs, and traces run on one columnar engine over object storage and share one table model: tags, timestamp, and fields. When signals carry common identifiers such as service, host, or trace ID, you can correlate them in SQL without moving data between databases.

Ingest through OpenTelemetry, Prometheus Remote Write, Loki Push, or Elasticsearch Bulk. Use SQL across observability data and PromQL for metrics. Migrate ingestion one signal at a time without rebuilding your collectors.

One Query Across Signals

OpenTelemetry ingestion writes spans to opentelemetry_traces and log records to opentelemetry_logs. Both tables carry trace_id, so correlating them is a join:

-- The slowest failed spans in the last hour,
-- with the log lines emitted inside those same traces.
SELECT
    t.service_name,
    t.span_name,
    t.duration_nano / 1000000 AS duration_ms,
    l.timestamp AS log_time,
    l.severity_text,
    l.body
FROM opentelemetry_traces t
JOIN opentelemetry_logs l ON l.trace_id = t.trace_id
WHERE t.timestamp > now() - INTERVAL '1' HOUR
  AND t.span_status_code = 'STATUS_CODE_ERROR'
ORDER BY t.duration_nano DESC
LIMIT 20;

Metrics join the same way, on any tag the tables share, such as service, host, or pod.

Try GreptimeDB

For AI agents — paste this prompt into your agent:

Read https://docs.greptime.com/SKILL.md and follow the instructions
to deploy, configure, ingest, and query GreptimeDB.
docker run -p 127.0.0.1:4000-4003:4000-4003 \
  -v "$(pwd)/greptimedb_data:/greptimedb_data" \
  --name greptime --rm \
  greptime/greptimedb:latest standalone start \
  --http-addr 0.0.0.0:4000 \
  --grpc-bind-addr 0.0.0.0:4001 \
  --mysql-addr 0.0.0.0:4002 \
  --postgres-addr 0.0.0.0:4003

Dashboard: http://localhost:4000/dashboard
Or skip the install and try the Live Demo.

Next: Quickstart, the full Install Guide, Demo Scenes, and the FAQ.

Why You Might Use It

  • You run Prometheus plus Loki or Elasticsearch and want one backend instead of three
  • You have outgrown Prometheus on cardinality or retention and don't want the Thanos/Mimir operational surface
  • You are hitting Loki's query performance limits as log volume grows
  • You need long retention on object storage without a separate analytics stack
  • You want to query telemetry with SQL, not only a domain query language
  • You are storing GenAI or agent telemetry (OTel GenAI conventions) alongside infrastructure signals

Learn more in Why GreptimeDB.

What's Supported

Ingest OpenTelemetry (OTLP), Prometheus Remote Write (with native histograms over Remote Write 2.0), Loki Push, Elasticsearch Bulk, InfluxDB line protocol, gRPC
Query SQL, PromQL, Jaeger-compatible trace queries, MySQL and PostgreSQL wire protocols
Storage S3, GCS, Azure Blob and S3-compatible endpoints as primary storage, with memory and local-disk caches
Built in Pipelines that parse and transform logs at ingestion, retention policies, downsampling, continuous aggregation, explicit table partitioning, and inverted / skipping / fulltext indexes

Compute and storage are disaggregated: object storage holds the data, while memory and local-disk caches keep recent and frequently queried data close to compute.

GreptimeDB Overview

Benchmarks

Compatibility and Migration

Compatibility is per protocol, and query-side coverage is narrower than ingestion.

Compatible Not compatible
Prometheus Remote Write ingestion; PromQL queries Gaps are listed in PromQL compatibility
Loki Push ingestion; dual-write through Grafana Alloy makes the cutover gradual LogQL and the rest of the Loki query API
Elasticsearch _bulk ingestion in the open-source core; QueryDSL partially, in Enterprise Most other Elasticsearch APIs

Limitations and Edition Boundary

Cluster deployment, object storage, the Flow engine, and every ingestion protocol listed above are in the Apache-2.0 build. Repartitioning and region migration are manual operations there.

Read replicas, workload isolation, and automated repartitioning are GreptimeDB Enterprise features, along with enterprise security and governance. The Enterprise overview has the current list, and pricing has the edition comparison. For GreptimeDB Enterprise inquiries, contact us.

Architecture

GreptimeDB can run in two modes:

  • Standalone — single binary for development and small deployments.
  • Distributed — four components, each independently scalable:
    • Frontend — protocol endpoints and the distributed query engine. Stateless, scales horizontally.
    • Datanode — region engine with WAL, memtable, SST, cache, compaction, and indexes. Persists data to object storage.
    • Metasrv — metadata, region routing, and cluster coordination (DDL procedures, failover, region migration, repartitioning). Backed by a pluggable KV layer (etcd or RDS).
    • Flownode (optional) — continuous flow computation (streaming and materialized views).

For deeper coverage, see the architecture doc or DeepWiki.

GreptimeDB System Overview

Build From Source

Prerequisites:

  • Rust toolchain — stable, pinned by rust-toolchain.toml
  • Protobuf compiler (>= 3.15)
  • C/C++ building essentials: gcc / g++ / autoconf and the glibc dev package (libc6-dev on Ubuntu, glibc-devel on Fedora)
  • Python toolchain (optional, only for some test scripts)

Build and run:

make                          # build greptime binary
cargo run -- standalone start # start in standalone mode

Common dev commands:

make fmt            # format Rust code
make clippy         # lint (fails on warnings)
make test           # unit + integration tests (uses cargo-nextest)
make sqlness-test   # SQL regression tests

See the Contribution Guidelines for the full developer workflow.

Tools & Extensions

Project Status

GreptimeDB is generally available, with stable APIs and regular releases. It runs in production at scale — OceanBase Cloud operates 80+ GreptimeDB clusters managing 300 TB of logs, cutting log storage cost by 60%+ after migrating from Grafana Loki. See more in case studies.

Releases follow Semantic Versioning. For where the project is going, read the v1.0 highlights, the 2026 roadmap, and what we mean by an observability database.

Community

If GreptimeDB is useful to you, please star the repo.

Star History Chart Known Users

License

GreptimeDB is an open-core project. Its core is licensed under the Apache License 2.0.

A small set of peripheral, enterprise-only features are gated behind the enterprise Cargo feature (not built by default) and are governed by the separate GreptimeDB Enterprise License. Source files under that license carry an explicit Enterprise License header.

Contributing

Integration CI Codecov

Acknowledgement

Special thanks to all contributors! See AUTHOR.md.


All trademarks, logos, and brand names referenced in this README and in the Overview diagram are the property of their respective owners. Their use is for identification purposes only and does not imply endorsement or affiliation.

Languages
Rust 97.9%
Python 1.5%
Shell 0.3%
JavaScript 0.2%