Files
zeekay 0c90ebe02e debrand: finish the rename across source, docs and dev infra
Source: the unexported clickhouse struct becomes client, the ch receiver and
chproto import alias follow, error message prefixes read datastore, and the
JSON serializer interface drops the vendor infix. resources' metadata key and
its accessor are renamed together, with a test proving the embedded YAML still
unmarshals — a silent drift there would have made every connection take the
unsupported-server-version branch.

Codegen: all three templates still emitted the upstream module paths, so
regenerating would have quietly undone the rename. Note the templates have
drifted from the files they produce (regenerating today drops QBit and
scanTypeDuration), so the generated files are left as tracked and only the
templates are corrected.

Dead links: an earlier mechanical pass invented URLs that do not resolve —
github.com/ClickHouse/datastore-go, hanzo-ds/driver issue numbers that belong to
upstream, and mangled names of independent projects (mailru, uptrace, nikepan,
EpicStep). Third-party names are not ours to rewrite, so those directories are
removed rather than repaired, and provenance comments now point at real files.

Dev infra: compose runs our own server image at the tag production runs, since
the vendor's alpine tag does not exist in our registry. Cluster hostnames,
nginx upstreams and server configs are renamed as one set.

CHANGELOG.md is upstream's release history for versions this module never
released; rewriting it would fabricate a lineage, so it is dropped and the
upstream base recorded in README instead.

The two long-standing vet findings are fixed by keying the struct literals
rather than suppressed. LICENSE and contributors/list keep the vendor name on
purpose: one is the copyright notice Apache-2.0 requires, the other is real
people's names. CI now enforces build, vet, test, gofmt and a grep gate.
2026-07-26 11:46:39 -07:00

149 lines
3.8 KiB
Go

package proto
import (
"fmt"
nativeproto "github.com/hanzo-ds/native/proto"
"go.yaml.in/yaml/v3"
"strconv"
"strings"
"time"
"github.com/hanzo-ds/go/lib/timezone"
)
type ClientHandshake struct {
ProtocolVersion uint64
ClientName string
ClientVersion Version
}
func (h ClientHandshake) Encode(buffer *nativeproto.Buffer) {
buffer.PutString(h.ClientName)
buffer.PutUVarInt(h.ClientVersion.Major)
buffer.PutUVarInt(h.ClientVersion.Minor)
buffer.PutUVarInt(h.ProtocolVersion)
}
func (h ClientHandshake) String() string {
return fmt.Sprintf("%s %d.%d.%d", h.ClientName, h.ClientVersion.Major, h.ClientVersion.Minor, h.ClientVersion.Patch)
}
type ServerHandshake struct {
Name string
DisplayName string
Revision uint64
Version Version
Timezone *time.Location
}
type Version struct {
Major uint64
Minor uint64
Patch uint64
}
func ParseVersion(v string) (ver Version) {
var err error
parts := strings.Split(v, ".")
if len(parts) < 3 {
return ver
}
if ver.Major, err = strconv.ParseUint(parts[0], 10, 8); err != nil {
return ver
}
if ver.Minor, err = strconv.ParseUint(parts[1], 10, 8); err != nil {
return ver
}
if ver.Patch, err = strconv.ParseUint(parts[2], 10, 8); err != nil {
return ver
}
return ver
}
func CheckMinVersion(constraint Version, version Version) bool {
if version.Major < constraint.Major || (version.Major == constraint.Major && version.Minor < constraint.Minor) || (version.Major == constraint.Major && version.Minor == constraint.Minor && version.Patch < constraint.Patch) {
return false
}
return true
}
func (srv *ServerHandshake) Decode(reader *nativeproto.Reader) (err error) {
if srv.Name, err = reader.Str(); err != nil {
return fmt.Errorf("could not read server name: %v", err)
}
if srv.Version.Major, err = reader.UVarInt(); err != nil {
return fmt.Errorf("could not read server major version: %v", err)
}
if srv.Version.Minor, err = reader.UVarInt(); err != nil {
return fmt.Errorf("could not read server minor version: %v", err)
}
if srv.Revision, err = reader.UVarInt(); err != nil {
return fmt.Errorf("could not read server revision: %v", err)
}
if srv.Revision >= DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE {
name, err := reader.Str()
if err != nil {
return fmt.Errorf("could not read server timezone: %v", err)
}
if srv.Timezone, err = timezone.Load(name); err != nil {
return fmt.Errorf("could not load time location: %v", err)
}
}
if srv.Revision >= DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME {
if srv.DisplayName, err = reader.Str(); err != nil {
return fmt.Errorf("could not read server display name: %v", err)
}
}
if srv.Revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH {
if srv.Version.Patch, err = reader.UVarInt(); err != nil {
return fmt.Errorf("could not read server patch: %v", err)
}
} else {
srv.Version.Patch = srv.Revision
}
return nil
}
func (srv ServerHandshake) String() string {
return fmt.Sprintf("%s (%s) server version %d.%d.%d revision %d (timezone %s)", srv.Name, srv.DisplayName,
srv.Version.Major,
srv.Version.Minor,
srv.Version.Patch,
srv.Revision,
srv.Timezone,
)
}
func (v Version) String() string {
return fmt.Sprintf("%d.%d.%d",
v.Major,
v.Minor,
v.Patch,
)
}
func (v *Version) UnmarshalYAML(value *yaml.Node) (err error) {
versions := strings.Split(value.Value, ".")
if len(versions) < 1 || len(versions) > 3 {
return fmt.Errorf("%s is not a valid version", value.Value)
}
for i := range versions {
switch i {
case 0:
if v.Major, err = strconv.ParseUint(versions[i], 10, 8); err != nil {
return err
}
case 1:
if v.Minor, err = strconv.ParseUint(versions[i], 10, 8); err != nil {
return err
}
case 2:
if v.Patch, err = strconv.ParseUint(versions[i], 10, 8); err != nil {
return err
}
}
}
return nil
}