InfluxDB (HTTP line protocol, InfluxQL and the 2.x API): implementation reference
How the InfluxDB listener is built. For status, scores, how to connect and known gaps see the wire page InfluxDB. Shared authentication rules are in Security and port settings in the configuration reference.
1. Source layout
| File | Role |
|---|---|
src/protocol/influxdb/mod.rs |
InfluxDbHandler: HTTP/1.1 listener, request parsing, routing, authentication, line protocol, storage records, metadata statements, the older substring-based SELECT path, the Flux subset, cluster replica sync |
src/protocol/influxdb/influxql.rs |
InfluxQL tokenizer, parser and evaluator for SELECT, SHOW ..., DELETE, DROP SERIES, DROP MEASUREMENT over the in-memory point set |
The listener is a hand-written HTTP/1.1 server on Tokio; it does not use hyper. Third-party crates used here: serde_json (bodies), regex (InfluxQL regex literals), flate2 (gzip request bodies), base64 (Basic auth), chrono (time), rand (stub ids). (source: src/protocol/influxdb/mod.rs, handle_connection, parse_request, gunzip_body; src/protocol/influxdb/influxql.rs, use lines)
2. Transport
- Port:
[server] influxdb_port, default 8086.with_tlswraps every accepted connection in TLS before any HTTP bytes when TLS is configured (implicit TLS). (source:src/config.rs,ServerConfig::default;src/protocol/influxdb/mod.rs,with_tls,default_port) - Request bodies:
Content-LengthorTransfer-Encoding: chunked, andContent-Encoding: gzipis decompressed. The full body cap isMAX_HTTP_BODY= 256 MiB, applied to the decompressed size too. (source:src/protocol/influxdb/mod.rs,MAX_HTTP_BODY,read_chunked_body,gunzip_body) - Pre-auth limit: a chunked body, or one whose declared length exceeds
PREAUTH_BODY_LIMIT(1 MiB), is read with the full cap only if the URL and headers already authenticate; otherwise the read stops at 1 MiB. (source:src/protocol/influxdb/mod.rs,parse_request;src/protocol/buffer_limits.rs,PREAUTH_BODY_LIMIT;docs/status/2026-11-29-preauth-body-limits.md) - A form-encoded
POST /query(or aPOST /querywith noqin the URL) has its body parsed as URL-encoded parameters and merged into the query parameters. (source:src/protocol/influxdb/mod.rs,parse_request)
3. Authentication
Every request except /ping, /health and /ready is authenticated. (source: src/protocol/influxdb/mod.rs, route_request)
Credentials are taken, in this order, from Authorization: Basic base64(user:pass), Authorization: Token user:pass (2.x token form, but the token must be user:pass), or the u and p query parameters. A presented credential is checked with verify_wire_credential("influxdb", ...) against the shared catalog; a wrong one gets 401 even in dev mode. With no credential, the request is served only when SYNERGYDB_DEV_INSECURE_AUTH is 1 or true; otherwise 401. Error body: {"error": "..."}. (source: src/protocol/influxdb/mod.rs, authenticate, extract_credentials, dev_insecure_auth_enabled; src/auth/wire_auth.rs) Tested by test_requests_fail_closed_without_dev_flag in src/protocol/influxdb/mod.rs.
A non-superuser needs the wire privilege described in Security (docs/status/2026-11-29-nonsql-wire-privileges.md). There is no per-database authorization inside the wire: once authenticated, a principal reaches every database. (source: src/protocol/influxdb/mod.rs, route_request) Not verified: no test of a non-superuser principal on this wire was found.
Audit: when the audit log is enabled, writes, /query, Flux queries, v2 deletes and non-GET bucket calls are recorded with wire influxdb, the database or bucket as the object, the HTTP status, the statement text (truncated to 4096 characters) and, for line protocol writes, the line count. /query text containing ` INTO ` or starting with DELETE is classed as a write; CREATE, DROP, ALTER, GRANT, REVOKE, SET PASSWORD as admin; the rest as read. (source: src/protocol/influxdb/mod.rs, audit_influx_request) Not verified: no test of the audit records was found.
4. Endpoints
The complete route table from route_request. Any other method and path gets 404 Endpoint not found: <METHOD> <path>.
| Method | Path | Auth | Behaviour |
|---|---|---|---|
| GET, HEAD | /ping |
none | 204 |
| GET | /health |
none | 200 JSON {"name":"influxdb","status":"pass","version":"2.7.0-synergydb",...} (fixed content) |
| GET | /ready |
none | 200 JSON {"status":"ready","started":<now>,"up":"1h0m0s"}; started is the request time and up is a constant |
| GET | /metrics |
yes | Prometheus text: influxdb_databases_total, influxdb_measurements_total, influxdb_points_total (gauges, counted from memory) |
| POST | /write |
yes | 1.x line protocol write (section 5) |
| GET, POST | /query |
yes | InfluxQL (section 6) |
| POST | /api/v2/write |
yes | 2.x write: bucket (or db) parameter, default bucket default; creates the database if missing |
| POST | /api/v2/query |
yes | Flux subset (section 7) |
| POST | /api/v2/delete |
yes | JSON {bucket, start, stop} (RFC 3339); removes points in range from memory (see the warning in section 8) |
| GET | /api/v2/buckets |
yes | Lists databases as buckets |
| POST | /api/v2/buckets |
yes | JSON body with name; adds the database in memory; 201 with a bucket object whose id is a hash of the name |
| GET | /api/v2/buckets/{id} |
yes | Stub: returns a bucket object named probe for any id |
| DELETE | /api/v2/buckets/{id} |
yes | Stub: 204, deletes nothing |
| other | /api/v2/buckets/{id} |
yes | 405 |
| GET | /api/v2/orgs |
yes | Two fixed organizations, org and synergydb
|
| POST | /api/v2/orgs |
yes | Echoes an organization object; nothing is stored |
| GET | /api/v2/tasks |
yes | Always an empty task list |
| POST | /api/v2/tasks |
yes | 201 with a task object and a random id; nothing is stored or scheduled |
| GET | /api/v2/dbrps |
yes | One mapping per database, retention policy autogen, random ids on every call |
(source: src/protocol/influxdb/mod.rs, route_request, health_check, ready_check, metrics, list_buckets, create_bucket, list_orgs, create_org, handle_write_v2, handle_flux_query, handle_delete, list_tasks, create_task, list_dbrps)
Not wired: the bucket-by-id, org creation, task and DBRP routes are stubs that let client-library setup code succeed; a code comment says so ("stub routes so influxdb-client setUp helpers … succeed"). They do not store or enforce anything. Not verified: no test of the /api/v2/* routes or /metrics was found; the proof pack's InfluxDB suites run against InfluxDB 1.8 and use only the 1.x API (docs/proof/2026-11-30/proof-pack-a3232c9/logs/influxdb-three-phase-diff.txt).
5. Writes (line protocol)
5.1 Parsing
Each body line is measurement[,tag=v...] field=v[,field=v...] [timestamp]. Empty lines and lines starting with # are skipped. Backslash escapes of space, comma and = are honoured in names; string field values are double-quoted and may contain separators. (source: src/protocol/influxdb/mod.rs, parse_line_protocol_scaled, split_line_protocol, split_line_protocol_kv, unescape_line_protocol)
| Field literal | Stored as |
|---|---|
"text" |
String (\" and \\ unescaped) |
12i, 12u
|
Integer (i64; an unsigned value above i64 range fails to parse) |
t, T, true, True, TRUE / f, F, false, False, FALSE
|
Boolean |
| anything else | Float (f64) |
A field whose value fails to parse is dropped from the point. A missing timestamp takes the server's current time. (source: src/protocol/influxdb/mod.rs, parse_line_protocol_scaled; FieldValue) Tested by test_parse_line_protocol and test_parse_integer_field.
precision maps the timestamp to nanoseconds: empty, n, ns = 1; u, us, µ, µs = 1e3; ms = 1e6; s = 1e9; m = 60e9; h = 3600e9. Any other value is 400 invalid precision. (source: src/protocol/influxdb/mod.rs, precision_scale)
5.2 Write semantics
| Case |
/write (1.x) |
/api/v2/write |
|---|---|---|
No db
|
400 database is required
|
bucket default
|
| Database missing | 404 database not found: "<db>"
|
created |
| No body / bad UTF-8 | 400 | 400 |
| Line that fails to parse | Valid lines kept; 400 partial write: unable to parse '<line>': invalid field format (first bad line) |
Line skipped silently |
| Field type conflict | Point dropped; 400 partial write: field type conflict: ... dropped=<n>
|
Point dropped; 422 {"code":"unprocessable entity", ...}
|
| Storage write fails | Memory rolled back from storage; 500 | same |
| Success | 204 | 204 |
The first write of a field pins its type per measurement; a later point whose field has another type is rejected (check_field_types). A point with the same timestamp and tag set as an existing point replaces it (upsert_point, through point_index). The rp parameter of /write is not read: every point goes to the database, whatever retention policy is named. (source: src/protocol/influxdb/mod.rs, handle_write, handle_write_v2, Measurement::check_field_types, upsert_point, persist_batch, restore_after_failed_persist) Tested by test_upsert_point_index_tracks_outside_changes and test_upsert_point_many_distinct_points; partial-write and type-conflict replies are among the cases of the differential suite (influxdb-three-phase-diff.txt, 337/337).
Points are made durable before 204 is sent, and the batch is persisted while the database map's write lock is held, so a concurrent DROP cannot be overtaken by the write. (source: src/protocol/influxdb/mod.rs, handle_write)
6. InfluxQL (/query)
6.1 Parameters and envelope
| Parameter | Meaning |
|---|---|
q |
Required (400 missing required parameter: q). May hold several statements separated by ;
|
db |
Default database |
epoch |
Time output: absent = RFC 3339 with nanoseconds, trailing zeros trimmed; otherwise integers in ns, u/µ, ms, s, m or h
|
params |
JSON object; $name outside quoted text is replaced by the value (strings single-quoted, numbers and booleans as written). A missing value is 400 |
u, p
|
Credentials (section 3) |
Before running anything, each statement's first word must be one of SELECT DELETE SHOW CREATE DROP EXPLAIN GRANT REVOKE ALTER SET KILL; otherwise the whole request is 400 error parsing query: found X, expected .... With several statements, each result carries its statement_id. Responses are {"results":[{"statement_id":0, "series":[...]}]}; statement-level errors come back as HTTP 200 with "error" inside the result, as in InfluxDB 1.x. (source: src/protocol/influxdb/mod.rs, handle_query, run_influxql, split_influxql_statements, bind_influxql_params; src/protocol/influxdb/influxql.rs, format_time) Tested by binds_strings_numbers_and_skips_quoted_text; docs/status/2026-11-24-influxdb-bind-params.md.
6.2 Statements
| Statement | Handling |
|---|---|
SELECT ... |
InfluxQL parser and evaluator (6.3); a statement it cannot parse falls back to an older substring-matching handler in execute_select
|
SELECT ... INTO target ... |
execute_select_into: evaluates, writes the rows as points into the target measurement and persists them |
SHOW DATABASES |
All databases, including _internal
|
SHOW MEASUREMENTS [ON db] [WITH MEASUREMENT =~ /re/ \| = name] [WHERE ...] [LIMIT n] [OFFSET n] |
Parser parse_show / execute_show
|
SHOW TAG KEYS [ON db] [FROM ...] [WHERE ...] |
same |
SHOW TAG VALUES [ON db] [FROM ...] WITH KEY (= \| != \| =~ \| !~ \| IN) ... |
same |
SHOW FIELD KEYS [ON db] [FROM ...] |
same; types float, integer, string, boolean
|
SHOW SERIES [ON db] [FROM ...] [WHERE ...] |
same |
SHOW RETENTION POLICIES [ON db] |
Name, duration, shard group duration, replica count, default flag |
CREATE DATABASE name / DROP DATABASE name
|
Persisted to __influx__:db: records; drop deletes all point records of the database |
CREATE / ALTER / DROP RETENTION POLICY |
retention_policy_stmt; durations parsed by parse_influx_duration (INF = 0); default shard duration follows InfluxDB's table (1 h under 2 days, 1 day up to 180 days, else 7 days) |
DELETE FROM ... WHERE ..., DROP SERIES ..., DROP MEASUREMENT name
|
run_delete: removed from memory and storage in one batch |
EXPLAIN, GRANT, REVOKE, SET, KILL, ALTER (other than retention policy), other CREATE/DROP
|
Accepted and answered with an empty result {"statement_id":0}; nothing happens |
(source: src/protocol/influxdb/mod.rs, run_influxql, show_databases, create_database, drop_database, retention_policy_stmt, show_retention_policies, run_delete, execute_select, execute_select_into, default_shard_duration; src/protocol/influxdb/influxql.rs, parse_show, execute_show, parse_delete)
Not wired: retention policy durations are stored and reported but nothing expires points; no code in the module removes data by age. GRANT, REVOKE, CREATE USER and similar user statements return success without effect; users are managed over the SQL wires.
6.3 SELECT grammar
The parser covers: projections of fields, tags and *; aggregates and selectors; transformations applied to a field or an aggregate; arithmetic of a projection with a constant (+ - * /); AS aliases; FROM [db.][rp.]measurement (with three parts, or db..m, the first names the database; the retention policy part is ignored) or a subquery FROM (SELECT ...); WHERE with AND, OR, parentheses, comparisons = != <> < <= > >= and regex =~ !~ on time, tags and fields; time expressions with now(), durations, integers and RFC 3339 strings; GROUP BY time(interval[, offset]), tag lists or *; fill(null | none | previous | linear | <number>); ORDER BY time [ASC|DESC]; LIMIT, OFFSET, SLIMIT, SOFFSET. Duration units: ns, u/µ/us, ms, s, m, h, d, w. (source: src/protocol/influxdb/influxql.rs, Parser::parse_select, parse_proj_atom, parse_cmp, parse_time_expr, duration_unit)
| Kind | Functions |
|---|---|
| Aggregates and selectors |
count, sum, mean, median, min, max, first, last, spread, stddev, percentile, mode, distinct
|
| Selectors with N |
top(field[, tag...], N), bottom(field[, tag...], N)
|
| Transformations |
derivative, non_negative_derivative, difference, non_negative_difference, cumulative_sum, moving_average, abs, ceil, floor, round
|
Any other function name returns unsupported function <name>; field::type casts return type casts unsupported. (source: src/protocol/influxdb/influxql.rs, AGGREGATES, TRANSFORMS, parse_proj_atom) Tested by grafana_time_bucketed_mean_by_tag, fill_none_drops_empty_buckets_and_where_or, raw_select_where_field_limit_desc_and_rfc3339, selector_reports_point_time_and_derivative and unsupported_shapes_are_errors_not_wrong_answers in src/protocol/influxdb/influxql.rs.
GROUP BY time() may produce at most SYNERGYDB_INFLUX_MAX_SELECT_BUCKETS buckets (default 10,000,000; 0 = unlimited). (source: src/protocol/influxdb/influxql.rs, max_buckets)
Integral float values are rendered without a fractional part in JSON (42, not 42.0) below 2^53, to match InfluxDB's Go encoder. (source: src/protocol/influxdb/mod.rs, FieldValue::to_json)
Evaluation scans the measurement's in-memory Vec<Point>; there is no index by time or tag beyond point_index, which only serves upserts. (source: src/protocol/influxdb/influxql.rs, execute; src/protocol/influxdb/mod.rs, Measurement)
7. Flux (/api/v2/query)
The body is either raw Flux with Content-Type: application/vnd.flux or JSON {"query": "..."} (application/json or no content type); any other type is 415. (source: src/protocol/influxdb/mod.rs, handle_flux_query)
There is no Flux parser. execute_flux finds substrings in the query text: the bucket name after bucket:, range(start:, stop:), each filter(...) body split on and/&& into r._measurement == "x", r._field == "y" and r.<tag> == "v", and aggregateWindow(every:, fn:) with fn one of mean, sum, count, min, max, first, last (anything else is treated as mean). Every other Flux function in the query is ignored. Output is annotated CSV with columns result, table, _time, _measurement, _field, _value, one table per measurement and field; aggregation uses only numeric values. (source: src/protocol/influxdb/mod.rs, execute_flux, parse_flux_filter, parse_flux_range, parse_flux_aggregate_window, parse_flux_duration)
Not verified: no test of the Flux path was found. A Flux query with |> map(), |> pivot(), |> group(), |> yield() naming, or a filter using or returns results that ignore those steps rather than an error. The wire page records that Flux and the 2.x API are not claimed.
8. Storage
8.1 In memory
All databases, measurements and points live in Arc<RwLock<HashMap<String, Database>>>. A Database holds its measurements and retention policies; a Measurement holds points: Vec<Point> sorted by time after load, point_index: HashMap<(timestamp, tagset), position>, and lazily built field_types. Every query reads this map. At startup with_storage reads every persisted point back into memory, so memory use and start time grow with the number of points stored. (source: src/protocol/influxdb/mod.rs, InfluxDbHandler, Database, Measurement, with_storage, populate_catalog_from_store)
8.2 On disk
Records go into the shared storage engine's key-value space:
| Key | Value |
|---|---|
__influx__:db:<db> |
Creation sequence number as decimal text |
__influx__:rp:<db> |
JSON array of RetentionPolicy {name, duration, shard_duration, replication, default} (nanoseconds; duration 0 = infinite) |
__influx__:pt:<db> 0x1f <measurement> 0x1f <tagset> 0x1f <timestamp> |
One record per point: version byte 1, then per field a u32 name length, the name, a type byte and the value: f f64 big-endian, i i64 big-endian, b one byte, s u32 length plus bytes |
The tag set is sorted key 0x1d value pairs joined by 0x1e. All fields of a point, of every type, are in the one record at full nanosecond precision. (source: src/protocol/influxdb/mod.rs, DB_PREFIX, RP_PREFIX, PT_PREFIX, database_entry, rp_entry, tagset_bytes, point_key, point_entry, decode_point) Tested by test_points_survive_restart in src/protocol/influxdb/mod.rs and by phase 3 (after restart, 218/218) of influxdb-three-phase-diff.txt.
Legacy migration: with_storage also builds a TimeSeriesStore and, through migrate_legacy_format and load_legacy, reads data written by an older format (numeric fields in the columnar time-series store, non-numeric fields under __influx__:nn:) and rewrites it into the current records. New writes do not use TimeSeriesStore. (source: src/protocol/influxdb/mod.rs, with_storage, migrate_legacy_format, load_legacy, load_nonnumeric_fields, NN_PREFIX) Not verified: no test of the legacy migration was found.
Durability gaps found in the code:
-
POST /api/v2/deleteremoves points only from memory; it writes no delete records, so the points return after a restart. (source:src/protocol/influxdb/mod.rs,handle_delete) Not verified: no test. -
POST /api/v2/bucketsadds the database only in memory; an empty bucket created this way is gone after a restart, whileCREATE DATABASEand/api/v2/writepersist a__influx__:db:record. (source:src/protocol/influxdb/mod.rs,create_bucket,create_database,handle_write_v2)
8.3 Cluster
InfluxReplicaSync registers as a replicated-apply listener on the storage engine. Point records replicated from another node are decoded and upserted into memory; any other __influx__: change (database, retention policy, delete) triggers a full reload_from_storage; a storage reset reloads too. (source: src/protocol/influxdb/mod.rs, InfluxReplicaSync::start, on_apply, on_reset, reload_from_storage) Not verified: no test of the replica sync was found.
9. Configuration and limits
| Key / variable | Default | Effect |
|---|---|---|
[server] influxdb_port |
8086 | Listener port; unset disables the wire |
| TLS settings | off | Implicit TLS on the same port |
SYNERGYDB_DEV_INSECURE_AUTH |
unset | Serve requests that present no credential |
SYNERGYDB_INFLUX_MAX_SELECT_BUCKETS |
10,000,000 | Cap on GROUP BY time() buckets; 0 = unlimited |
MAX_HTTP_BODY (constant) |
256 MiB | Body cap, also after gunzip |
PREAUTH_BODY_LIMIT (constant) |
1 MiB | Body cap before authentication for large or chunked bodies |
(source: src/config.rs, ServerConfig; src/server/mod.rs; src/protocol/influxdb/mod.rs, MAX_HTTP_BODY; src/protocol/influxdb/influxql.rs, max_buckets; src/protocol/buffer_limits.rs)
10. Test coverage
| Suite | What it covers |
|---|---|
tests/protocol_influxdb.rs |
2 tests: handler name and default port only |
Unit tests in src/protocol/influxdb/mod.rs
|
9: handler creation, line protocol parsing, integer fields, upsert index (2), SHOW DATABASES, restart durability, fail-closed auth, bind parameters |
Unit tests in src/protocol/influxdb/influxql.rs
|
5: Grafana time-bucketed mean by tag, fill(none) and OR, raw select with field filter / LIMIT / DESC / RFC 3339, selector time and derivative, unsupported shapes return errors |
docs/proof/2026-11-30/proof-pack-a3232c9/logs/influxdb-three-phase-diff.txt |
Differential against InfluxDB 1.8: single connection 112/112, multi-connection 7/7, after restart 218/218, total 337/337 |
.../logs/influxdb-feature-matrix.txt |
Feature matrix against InfluxDB 1.8: 29/29 parity |
The doc comment at the top of tests/protocol_influxdb.rs says numeric fields go to the columnar TimeSeriesStore and string and boolean fields to the KV engine. That is stale: current code writes every field of a point into one __influx__:pt: record and uses TimeSeriesStore only to migrate old data (section 8.2). A comment inside execute_flux about "dual-write into TimeSeriesStore" is stale for the same reason.