Skip to content

feat: support partial writes#269

Open
alespour wants to merge 22 commits into
mainfrom
feat/partial-writes
Open

feat: support partial writes#269
alespour wants to merge 22 commits into
mainfrom
feat/partial-writes

Conversation

@alespour
Copy link
Copy Markdown
Contributor

@alespour alespour commented May 15, 2026

Proposed Changes

This PR adds partial-write support in the C# client and finalizes write API selection behavior for product compatibility.

Feature highlights:

  • Adds structured partial-write errors via InfluxDBPartialWriteException with per-line details:
    • LineNumber
    • ErrorMessage
    • OriginalLine
  • AcceptPartial defaults to true (server default behavior)
  • accept_partial=false is sent only when partial writes are explicitly disabled
  • UseV2Api routes writes between:
    • V2 API endpoint: /api/v2/write
    • V3 API endpoint: /api/v3/write_lp

Default behavior and option semantics:

  • Default writes use the V2 API endpoint (UseV2Api=true).
  • NoSync requires UseV2Api=false and is rejected otherwise.
  • AcceptPartial applies only to V3 endpoint writes and is ignored on V2 endpoint writes.

Configuration surfaces:

  • Write options: AcceptPartial, UseV2Api, NoSync
  • Connection string: writeAcceptPartial, writeUseV2Api, writeNoSync
  • Environment variables: INFLUX_WRITE_ACCEPT_PARTIAL, INFLUX_WRITE_USE_V2_API, INFLUX_WRITE_NO_SYNC

See Partial writes for reference.

Example (partial-write handling):

try
{
    await client.WriteRecordAsync(lp);
}
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);
}

Example (enable V3 write options):

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

await client.WriteRecordAsync(lp);

Checklist

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

@alespour alespour marked this pull request as ready for review May 15, 2026 14:16
@alespour alespour requested a review from Copilot May 15, 2026 14:16
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

This PR adds partial-write support to the C# client (including structured per-line error details) and finalizes write routing behavior between InfluxDB’s V2 and V3 write endpoints for product compatibility.

Changes:

  • Introduces InfluxDBPartialWriteException and JSON error parsing to surface v3 partial-write line errors.
  • Adds write routing/behavior controls via WriteOptions (UseV2Api, AcceptPartial, NoSync) plus connection string/env var configuration.
  • Updates tests and docs to reflect default V2 routing and explicit V3 option behavior.

Reviewed changes

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

Show a summary per file
File Description
README.md Documents partial writes and explains default V2 routing + configuration surfaces.
Client/Internal/RestClient.cs Parses JSON error bodies; throws InfluxDBPartialWriteException with structured line errors on v3 partial-write responses.
Client/InfluxDBPartialWriteException.cs Adds new exception type carrying per-line partial-write error details.
Client/InfluxDBClient.cs Routes writes to /api/v2/write by default and applies v3-only query params (no_sync, accept_partial) when using v3.
Client/Config/WriteOptions.cs Adds AcceptPartial/UseV2Api options and validates NoSync usage.
Client/Config/ClientConfig.cs Adds connection string/env parsing for writeAcceptPartial and writeUseV2Api.
Client/Client.csproj Adds System.Text.Json dependency for JSON parsing.
Client.Test/Internal/RestClientTest.cs Adds/updates tests for partial-write error parsing and typed/untyped fallback behavior.
Client.Test/InfluxDBClientWriteTest.cs Updates tests for default V2 routing, explicit V3 routing, and option validation/guidance messages.
Client.Test/InfluxDBClientHttpsTest.cs Formatting-only change.
Client.Test/InfluxDBApiExceptionTest.cs Formatting-only change.
Client.Test/Config/ClientConfigTest.cs Extends tests to cover new connection string/env write options.
Client.Test.Integration/WriteTest.cs Refactors exception check using pattern matching.
CHANGELOG.md Adds unreleased feature entry for partial writes + default V2 routing.

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

Comment thread README.md Outdated
Comment thread Client/Internal/RestClient.cs Outdated
Comment thread Client/Internal/RestClient.cs Outdated
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

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

Comment thread Client/Internal/RestClient.cs
Comment thread Client/Internal/RestClient.cs Outdated
Comment thread Client/InfluxDBPartialWriteException.cs
Comment thread Client/Config/ClientConfig.cs Outdated
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

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

Comments suppressed due to low confidence (1)

Client/InfluxDBClient.cs:848

  • This guidance error message starts with a lowercase "server" while other user-facing exceptions in the client are capitalized (e.g., "Cannot write..."). Consider capitalizing this message for consistency.
                    throw new InfluxDBApiException(
                        $"server doesn't support the V3 API endpoint (/api/v3/write_lp) " +
                        $"(set UseV2Api=true; write options: {{UseV2Api:false,NoSync:{writeOptions.NoSync.ToString().ToLowerInvariant()},AcceptPartial:{writeOptions.AcceptPartial.ToString().ToLowerInvariant()}}})",
                        ex.HttpResponseMessage!);

Comment thread README.md
Comment thread Client/Internal/RestClient.cs
Comment thread Client/InfluxDBClient.cs
Comment thread Client/Config/WriteOptions.cs Outdated
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

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.

Comment thread README.md
Comment thread Client/Config/WriteOptions.cs
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

Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.

Comment thread CHANGELOG.md Outdated
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