Files
zeekay ef352c1051 debrand: rename the wire client name, prose and linter config
proto.Name is sent in ClientHello and lands in the server's system.query_log,
so it is wire visible; it now reads datastore/native and is covered by a test.
Verified against the live server: the handshake succeeds and the new name
appears in query_log.

goimports' local-prefixes still named the upstream module, so it was not
grouping this module's own imports.

Doc comments, the deprecated-error markers in proto/error_codes.go and the
package prose are swept. Dead references are removed rather than repointed:
go-faster.org/docs/clickhouse and the mangled Datastore/clickhouse-cpp link
both 404, and the list of other vendors' clients does not belong here.

Four things deliberately keep the vendor name, and CI records why:
LICENSE and AUTHORS are the copyright notices Apache-2.0 requires; db.system in
query.go is an OpenTelemetry enum whose registered value for this DBMS is fixed
by the specification, so emitting anything else would be non-conformant; and
README names clickhouse-local, which is genuinely the binary our own server
image ships.

Numeric error codes and protocol revision constants are untouched.
2026-07-26 11:50:36 -07:00

62 lines
1.2 KiB
Go

package native
import (
"context"
"github.com/go-faster/errors"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"github.com/hanzo-ds/native/proto"
"github.com/hanzo-ds/native/tracing"
)
// Ping server.
//
// Do not call concurrently with Do.
func (c *Client) Ping(ctx context.Context) (err error) {
if c.IsClosed() {
return ErrClosed
}
if c.otel {
newCtx, span := c.tracer.Start(ctx, "Ping",
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(
tracing.ProtocolVersion(c.protocolVersion),
),
)
ctx = newCtx
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "Failed")
} else {
span.SetStatus(codes.Ok, "")
}
span.End()
}()
}
c.writer.ChainBuffer(func(b *proto.Buffer) {
b.Encode(proto.ClientCodePing)
})
if err := c.flush(ctx); err != nil {
return errors.Wrap(err, "flush")
}
p, err := c.packet(ctx)
if err != nil {
return errors.Wrap(err, "read")
}
switch p {
case proto.ServerCodePong:
return nil
case proto.ServerCodeException:
e, err := c.exception()
if err != nil {
return errors.Wrap(err, "decode exception")
}
return errors.Wrap(e, "exception")
default:
return errors.Errorf("unexpected packet %s", p)
}
}