Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ make integration
The opt-in `integration` build tag starts MongoDB, Elasticsearch, two Store
owners and a discovery node. Tagged tests require a prepared `WEIR_TEST_BINARY`.
Coverage includes discovery through every node, direct owner connections, typed
CRUD and Lua transformations, independent persistence checks, same-Store batches,
slice preflight and per-frame validation, finite Scan continuation, Native response evidence,
CRUD and Lua transformations, independent persistence checks, same-Store calls
containing many records, slice preflight and per-record validation, finite Scan continuation, Native response evidence,
cancellation, owner restart, directory convergence and persistent client recovery.
Separate multi-process tests verify independent single-record callers.
One-RPC reads deliver 64 MiB and 256 MiB across 1024 distinct documents while
checking bounded result credits and sampled owner RSS. Interrupted streams retain
confirmed record outcomes; unconfirmed mutations remain indeterminate.

Each Execute request carries one record and its consecutive index. The client
streams records as they are produced; server aggregation stays within the Store.
Later invalid records stop the stream while preserving earlier acknowledged writes.
Document and Native body formats use the public `ContentType` fields.

Services bind to loopback and own exclusive namespaces. Cleanup verifies exact
process and container ownership. Fixture logs, manifests and cleanup receipts
are retained in the printed output directory, including startup failures.
Expand Down
6 changes: 2 additions & 4 deletions cmd/weir-lab/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/signal"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -184,10 +185,7 @@ func runLab(ctx context.Context, opts labOptions) (resultErr error) {
"topology": "native client and Weir on one host; dedicated database Docker containers with loopback ports",
"client_operation_timeout": businessTimeout.String(),
"weir_backend_timeout": businessTimeout.String(),
"weir_store_concurrency": fmt.Sprint(opts.concurrency),
"weir_max_batch_operations": fmt.Sprint(opts.backendBatchLimit),
"weir_memory_budget": "8GiB (declared process admission budget; not an OS reservation)",
"weir_ingress_max_sessions": "64",
"weir_ingress_max_connections": "64",
"host_cpus": fmt.Sprint(runtime.NumCPU()),
}
Expand All @@ -202,7 +200,7 @@ func runLab(ctx context.Context, opts labOptions) (resultErr error) {
return err
}
provenance["weir_source"] = identity.Revision
if opts.mongoBinary != "" {
if opts.mongoBinary != "" && slices.Contains(backends, "mongo") {
provenance["topology"] = "native client, Weir and isolated MongoDB on one host; Elasticsearch in a dedicated loopback Docker container"
}
if pinsRaw, err := os.ReadFile("versions.json"); err == nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/batchstream/weir-tests
go 1.27.1

require (
github.com/batchstream/weir-go v0.6.0
github.com/batchstream/weir-protocol v0.4.0
github.com/batchstream/weir-go v0.7.0
github.com/batchstream/weir-protocol v0.5.0
go.mongodb.org/mongo-driver/v2 v2.9.1
google.golang.org/grpc v1.83.2
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/batchstream/weir-go v0.6.0 h1:S9/+7diNNNbVEH68lg6GbepzXAiCJpF0K74R5pTNFmo=
github.com/batchstream/weir-go v0.6.0/go.mod h1:YsokqwtYw2sN7zVbt4yIgqJUnuoHsDyiA1vQlXPE2VU=
github.com/batchstream/weir-protocol v0.4.0 h1:t4dDLAKeOOGz/wajfsfrYZgbILDvVceoPvJYKxTQuiM=
github.com/batchstream/weir-protocol v0.4.0/go.mod h1:hHmwPoE9yHYAz7Auc3a14Ijo/uxAef4sQ9nBtyXNcGc=
github.com/batchstream/weir-go v0.7.0 h1:PfuZaRH6A8sMOZ5qa0pyLna8A9qsBOydAX3yH2v2t4s=
github.com/batchstream/weir-go v0.7.0/go.mod h1:3hOZQtFCmS7ZbWuM32jOQxdL1sKQD+hdk1d6U5bcglo=
github.com/batchstream/weir-protocol v0.5.0 h1:ARPy3pcEL0EB5pJsGL10R2/MyH+gb0TqO31t18rOrPE=
github.com/batchstream/weir-protocol v0.5.0/go.mod h1:hHmwPoE9yHYAz7Auc3a14Ijo/uxAef4sQ9nBtyXNcGc=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
20 changes: 4 additions & 16 deletions internal/workload/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workload
import (
"context"
"errors"
"io"

weir "github.com/batchstream/weir-go"
)
Expand All @@ -11,8 +12,7 @@ import (
// Only the coordinator owns setup, reset and independent verification.
type Client struct {
Executor Executor
direct *directPath
weir *weir.Client
io.Closer
}

type ClientOptions struct {
Expand All @@ -25,32 +25,20 @@ func OpenClient(ctx context.Context, opts ClientOptions) (*Client, error) {
if opts.Dataset == nil || (opts.Path != "direct" && opts.Path != "weir") {
return nil, errors.New("client requires a dataset and direct or weir path")
}
client := &Client{}
if opts.Path == "direct" {
direct, err := openDirect(ctx, opts.Dataset)
if err != nil {
return nil, err
}
client.direct, client.Executor = direct, direct
client := &Client{Executor: direct, Closer: direct}
return client, nil
}
open := weir.OpenOptions{Seed: opts.Dataset.Config.WeirSeed, Stores: []string{opts.Dataset.Config.StoreName}}
sdk, err := weir.Open(ctx, open)
if err != nil {
return nil, err
}
client.weir = sdk
path := &weirPath{dataset: opts.Dataset, client: sdk, info: opts.Evidence}
client.Executor = path
client := &Client{Executor: path, Closer: sdk}
return client, nil
}

func (c *Client) Close() error {
if c.direct != nil {
return c.direct.close()
}
if c.weir != nil {
return c.weir.Close()
}
return nil
}
2 changes: 1 addition & 1 deletion internal/workload/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (d *Dataset) Document(operation Operation) []byte {
return d.docs[operation.Record][operation.Revision]
}

func (d *Dataset) MediaType() string {
func (d *Dataset) ContentType() string {
if d.Config.Backend == "mongo" {
return "application/bson"
}
Expand Down
14 changes: 7 additions & 7 deletions internal/workload/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func openDirect(ctx context.Context, dataset *Dataset) (*directPath, error) {
direct.baseURL = strings.TrimSuffix(address.String(), "/")
status, body, err := direct.request(ctx, http.MethodGet, "/", nil)
if err != nil || status != http.StatusOK {
_ = direct.close()
_ = direct.Close()
return nil, errors.New("direct Search version query failed")
}
var root struct {
Expand All @@ -172,7 +172,7 @@ func openDirect(ctx context.Context, dataset *Dataset) (*directPath, error) {
} `json:"version"`
}
if err := json.Unmarshal(body, &root); err != nil || root.Version.Number == "" {
_ = direct.close()
_ = direct.Close()
return nil, errors.New("invalid Search version evidence")
}
direct.info.Protocol = "Elasticsearch HTTP/1.1 JSON"
Expand Down Expand Up @@ -322,10 +322,10 @@ func (p *Paths) Close() error {
if p.client != nil {
sdkErr = p.client.Close()
}
return errors.Join(sdkErr, p.direct.close())
return errors.Join(sdkErr, p.direct.Close())
}

func (p *directPath) close() error {
func (p *directPath) Close() error {
if p.search != nil {
p.search.CloseIdleConnections()
}
Expand Down Expand Up @@ -488,7 +488,7 @@ func (p *weirPath) Execute(ctx context.Context, operation Operation) Outcome {
result, err := p.client.AtomicTransform(ctx, opts)
return mutationOutcome(result, len(program.Source), err)
}
document := &weir.Document{MediaType: p.dataset.MediaType(), Data: p.dataset.Document(operation)}
document := &weir.Document{ContentType: p.dataset.ContentType(), Data: p.dataset.Document(operation)}
request := &weir.WriteRequest{Resource: p.dataset.Resource(operation.Record), Document: document}
opts := weir.WriteOptions{StoreName: p.dataset.Config.StoreName, Request: request}
result, err := p.client.Put(ctx, opts)
Expand All @@ -507,8 +507,8 @@ func (p *weirPath) readOutcome(result *weir.ReadResult, operation Operation, rpc
if result == nil || result.Document == nil || result.Failure != nil || result.Missing {
return failed(errors.New("Weir Read lacks a successful document"), false)
}
if result.Document.MediaType != p.dataset.MediaType() {
return failed(errors.New("Weir document media type mismatch"), false)
if result.Document.ContentType != p.dataset.ContentType() {
return failed(errors.New("Weir document content type mismatch"), false)
}
if err := p.dataset.Validate(result.Document.Data, operation); err != nil {
return failed(err, false)
Expand Down
2 changes: 1 addition & 1 deletion internal/workload/weir_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (p *weirPath) ExecuteBatch(ctx context.Context, operations []Operation) []O
if operations[0].Write {
requests := make([]*weir.MutateRequest, len(operations))
for index, operation := range operations {
document := &weir.Document{MediaType: p.dataset.MediaType(), Data: p.dataset.Document(operation)}
document := &weir.Document{ContentType: p.dataset.ContentType(), Data: p.dataset.Document(operation)}
request := &weir.MutateRequest{Resource: p.dataset.Resource(operation.Record), Action: weir.MutationPut, Document: document}
requests[index] = request
}
Expand Down
73 changes: 42 additions & 31 deletions internal/workload/weir_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (

type acknowledgementPeer struct {
pb.UnimplementedStoreServiceServer
mode string
calls atomic.Int64
applied atomic.Int64
document []byte
mode string
calls atomic.Int64
applied atomic.Int64
document []byte
firstMutation chan struct{}
}

func (p *acknowledgementPeer) Execute(stream grpc.BidiStreamingServer[pb.ExecuteRequest, pb.ExecuteResponse]) error {
Expand All @@ -37,7 +38,7 @@ func (p *acknowledgementPeer) Execute(stream grpc.BidiStreamingServer[pb.Execute
return err
}
if request.Command.GetRead() != nil {
document := &pb.Document{MediaType: "application/json", Data: p.document}
document := &pb.Document{ContentType: "application/json", Data: p.document}
payload := &pb.ReadResult_Document{Document: document}
result := &pb.ReadResult{Result: payload}
value := &pb.Event_ReadResult{ReadResult: result}
Expand All @@ -48,31 +49,33 @@ func (p *acknowledgementPeer) Execute(stream grpc.BidiStreamingServer[pb.Execute
}
return status.Error(codes.Unavailable, "later read result lost")
}
mutations := request.Command.GetMutate().Requests
if request.Command.GetMutate() == nil {
return status.Error(codes.InvalidArgument, "mutation required")
}
// Durable writes can precede lost acknowledgements; never infer replay safety.
p.applied.Add(int64(len(mutations)))
if p.applied.Add(1) == 1 && p.firstMutation != nil {
close(p.firstMutation)
}
switch p.mode {
case "lost_after_apply":
return status.Error(codes.Unavailable, "window acknowledgement lost")
return status.Error(codes.Unavailable, "record acknowledgement lost")
case "deadline_after_apply", "canceled_after_apply":
<-stream.Context().Done()
return status.FromContextError(stream.Context().Err()).Err()
}
for index := range mutations {
var failure *pb.Failure
if p.mode == "applied_failure" {
failure = protocol.Fail(pb.FailureCode_UNAVAILABLE, "write applied but replica confirmation failed")
}
result := protocol.Mutation(pb.MutationOutcome_APPLIED, failure)
payload := &pb.Event_MutationResult{MutationResult: result}
event := &pb.Event{Value: payload}
response := &pb.ExecuteResponse{Index: request.Index + uint64(index), Event: event}
if err := stream.Send(response); err != nil {
return err
}
if p.mode == "partial_after_apply" {
return status.Error(codes.Unavailable, "later acknowledgement lost")
}
var failure *pb.Failure
if p.mode == "applied_failure" {
failure = protocol.Fail(pb.FailureCode_UNAVAILABLE, "write applied but replica confirmation failed")
}
result := protocol.Mutation(pb.MutationOutcome_APPLIED, failure)
payload := &pb.Event_MutationResult{MutationResult: result}
event := &pb.Event{Value: payload}
response := &pb.ExecuteResponse{Index: request.Index, Event: event}
if err := stream.Send(response); err != nil {
return err
}
if p.mode == "partial_after_apply" {
return status.Error(codes.Unavailable, "later acknowledgement lost")
}
}
}
Expand Down Expand Up @@ -123,24 +126,32 @@ func TestSDKStreamMutationAcknowledgementAndNoReplay(t *testing.T) {
for _, mode := range []string{"applied_failure", "partial_after_apply", "lost_after_apply", "deadline_after_apply", "canceled_after_apply"} {
t.Run(mode, func(t *testing.T) {
peer := &acknowledgementPeer{mode: mode}
if mode == "canceled_after_apply" {
peer.firstMutation = make(chan struct{})
}
client := mutationTransport(t, peer)
document := &weir.Document{MediaType: "application/json", Data: []byte(`{"n":1}`)}
document := &weir.Document{ContentType: "application/json", Data: []byte(`{"n":1}`)}
first := &weir.MutateRequest{Resource: "records/s:first", Action: weir.MutationPut, Document: document}
second := &weir.MutateRequest{Resource: "records/s:second", Action: weir.MutationPut, Document: document}
opts := weir.MutateOptions{StoreName: "search", Requests: []*weir.MutateRequest{first, second}}
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
if mode == "canceled_after_apply" {
go func() {
for peer.applied.Load() == 0 && ctx.Err() == nil {
time.Sleep(time.Millisecond)
select {
case <-peer.firstMutation:
cancel()
case <-ctx.Done():
}
cancel()
}()
}
replies, rpcErr := weir.Mutate(ctx, client, opts)
if len(replies) != 2 || peer.calls.Load() != 1 || peer.applied.Load() != 2 {
t.Fatalf("whole batch lost accounting or replayed: replies=%v calls=%d applied=%d err=%v", replies, peer.calls.Load(), peer.applied.Load(), rpcErr)
applied := int64(1)
if mode == "applied_failure" {
applied = 2
}
if len(replies) != 2 || peer.calls.Load() != 1 || peer.applied.Load() != applied {
t.Fatalf("stream lost accounting or replayed: replies=%v calls=%d applied=%d err=%v", replies, peer.calls.Load(), peer.applied.Load(), rpcErr)
}
if mode == "applied_failure" && rpcErr != nil || mode != "applied_failure" && rpcErr == nil {
t.Fatal("unexpected final status", rpcErr)
Expand All @@ -163,10 +174,10 @@ func TestSDKStreamMutationAcknowledgementAndNoReplay(t *testing.T) {
}
}

func TestSDKStreamMutationPreflightSendsNoBatch(t *testing.T) {
func TestSDKStreamMutationPreflightSendsNoRecord(t *testing.T) {
peer := &acknowledgementPeer{mode: "applied_failure"}
client := mutationTransport(t, peer)
document := &weir.Document{MediaType: "application/json", Data: []byte(`{"n":1}`)}
document := &weir.Document{ContentType: "application/json", Data: []byte(`{"n":1}`)}
first := &weir.MutateRequest{Resource: "records/s:first", Action: weir.MutationPut, Document: document}
invalid := &weir.MutateRequest{Resource: "records/s:second", Action: 0, Document: document}
opts := weir.MutateOptions{StoreName: "search", Requests: []*weir.MutateRequest{first, invalid}}
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *backendData) resource(id string) string {

func (b *backendData) write(t *testing.T, id string, n int64) *weir.WriteRequest {
t.Helper()
document := &weir.Document{MediaType: "application/json", Data: []byte(fmt.Sprintf("{\"n\":%d}", n))}
document := &weir.Document{ContentType: "application/json", Data: []byte(fmt.Sprintf("{\"n\":%d}", n))}
if b.name == "mongo" {
value := bson.D{{Key: "_id", Value: id}, {Key: "n", Value: n}}
document = bsonDocument(t, value)
Expand All @@ -115,14 +115,14 @@ func (b *backendData) write(t *testing.T, id string, n int64) *weir.WriteRequest
func (b *backendData) transform(t *testing.T, id string) *weir.AtomicTransformRequest {
t.Helper()
expression := &weir.Document{
MediaType: "application/vnd.weir.search-update.v1+json",
Data: []byte("{\"doc\":{\"n\":4}}"),
ContentType: "application/vnd.weir.search-update.v1+json",
Data: []byte("{\"doc\":{\"n\":4}}"),
}
if b.name == "mongo" {
fields := bson.D{{Key: "n", Value: int64(1)}}
update := bson.D{{Key: "$inc", Value: fields}}
expression = bsonDocument(t, update)
expression.MediaType = "application/vnd.weir.mongodb-update.v1+bson"
expression.ContentType = "application/vnd.weir.mongodb-update.v1+bson"
}
request := &weir.AtomicTransformRequest{Resource: b.resource(id), BackendExpression: expression}
return request
Expand All @@ -134,7 +134,7 @@ func bsonDocument(t *testing.T, value bson.D) *weir.Document {
if err != nil {
t.Fatal(err)
}
document := &weir.Document{MediaType: "application/bson", Data: data}
document := &weir.Document{ContentType: "application/bson", Data: data}
return document
}

Expand All @@ -143,8 +143,8 @@ func (b *backendData) number(document *weir.Document) (int64, error) {
return 0, errors.New("missing document")
}
if b.name == "mongo" {
if document.GetMediaType() != "application/bson" {
return 0, fmt.Errorf("MongoDB document media type %q", document.GetMediaType())
if document.GetContentType() != "application/bson" {
return 0, fmt.Errorf("MongoDB document content type %q", document.GetContentType())
}
raw := bson.Raw(document.GetData())
if err := raw.Validate(); err != nil {
Expand All @@ -159,8 +159,8 @@ func (b *backendData) number(document *weir.Document) (int64, error) {
var value struct {
N int64 `json:"n"`
}
if document.GetMediaType() != "application/json" {
return 0, fmt.Errorf("Search document media type %q", document.GetMediaType())
if document.GetContentType() != "application/json" {
return 0, fmt.Errorf("Search document content type %q", document.GetContentType())
}
if err := json.Unmarshal(document.GetData(), &value); err != nil {
return 0, err
Expand Down
Loading
Loading