Skip to content

feat: support partial writes#258

Open
alespour wants to merge 5 commits intomainfrom
feat/partial-writes
Open

feat: support partial writes#258
alespour wants to merge 5 commits intomainfrom
feat/partial-writes

Conversation

@alespour
Copy link
Copy Markdown
Contributor

@alespour alespour commented Apr 30, 2026

Proposed Changes

Adds partial-write support with structured error details in InfluxDBPartialWriteException, including per-line LineNumber, ErrorMessage, and OriginalLine so callers can decide whether to drop/retry/fix specific lines in a ba
tch.

This also aligns write routing with the rollout contract:

  • Default write endpoint is now /api/v3/write_lp
  • AcceptPartial defaults to true (server default behavior)
  • accept_partial=false is sent only when partial writes are explicitly disabled
  • New compatibility option UseV2Api routes writes to /api/v2/write for Clustered/v2-compatible backends

Configuration surfaces now include:

  • Write option: AcceptPartial, UseV2Api
  • Client config / connection string keys: writeAcceptPartial, writeUseV2Api
  • Environment variables: INFLUX_WRITE_ACCEPT_PARTIAL, INFLUX_WRITE_USE_V2_API

Validation:

  • UseV2Api=true with NoSync=true is rejected before request dispatch.

See Partial writes in InfluxDB documentation.

Example:

try
{
    await client.WriteRecordAsync(lp); // AcceptPartial=true by default
}
catch (InfluxDBPartialWriteException e)
{
    foreach (var lineErr in e.LineErrors)
    {
        Console.WriteLine(
            $"line {lineErr.LineNumber} failed: {lineErr.ErrorMessage} ({lineErr.OriginalLine})");
    }
}
catch (InfluxDBApiException e)
{
    Console.WriteLine(e.Message);
}

Optional v2 compatibility mode:

using var v2Client = new InfluxDBClient(new ClientConfig
{
    Host = host,
    Token = token,
    Database = database,
    WriteOptions = new WriteOptions
    {
        UseV2Api = true
    }
});

await v2Client.WriteRecordAsync(lp);

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds structured partial-write error support and updates write routing defaults to align with InfluxDB v3 behavior, while providing an opt-in v2 compatibility route.

Changes:

  • Introduces InfluxDBPartialWriteException with per-line error details and updates REST error parsing to surface it for v3 partial-write responses.
  • Changes default write endpoint to /api/v3/write_lp, adds WriteOptions.AcceptPartial (default true) and WriteOptions.UseV2Api for routing to /api/v2/write, plus config/env/connection-string support.
  • Updates unit/integration tests and documentation/changelog to reflect the new defaults and options.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
README.md Documents partial writes and v2 compatibility mode configuration.
Client/Internal/RestClient.cs Switches error parsing to System.Text.Json and throws InfluxDBPartialWriteException when line errors are present.
Client/InfluxDBPartialWriteException.cs Adds a new exception type carrying structured line-level errors.
Client/InfluxDBClient.cs Routes writes to v3 by default; adds v2 routing option and query params for no_sync / accept_partial.
Client/Config/WriteOptions.cs Adds AcceptPartial and UseV2Api plus validation for incompatible option combinations.
Client/Config/ClientConfig.cs Adds connection string and env var parsing for new write options.
Client/Client.csproj Adds System.Text.Json dependency for netstandard targets.
Client.Test/Internal/RestClientTest.cs Expands tests to cover typed/untyped partial-write parsing and the new exception type.
Client.Test/InfluxDBClientWriteTest.cs Updates expected write paths/query params for new v3 default and v2 compatibility mode.
Client.Test/InfluxDBClientHttpsTest.cs Updates expected write endpoint to v3.
Client.Test/InfluxDBApiExceptionTest.cs Updates expected write endpoint to v3.
Client.Test/Config/ClientConfigTest.cs Adds coverage for new connection string/env config keys.
Client.Test.Integration/WriteTest.cs Minor refactor for exception typing consistency.
CHANGELOG.md Notes breaking default write routing + partial write support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Client/Internal/RestClient.cs
Comment thread Client/Internal/RestClient.cs
Comment thread Client/InfluxDBClient.cs
Comment thread Client/InfluxDBClient.cs
@alespour alespour marked this pull request as ready for review May 4, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants