ADAPT-Chase commited on
Commit
344d241
·
verified ·
1 Parent(s): 1c79be5

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. platform/dbops/binaries/weaviate-src/test/acceptance/replication/async_replication/async_repair_updates_test.go +131 -0
  2. platform/dbops/binaries/weaviate-src/test/acceptance/replication/common/crud_ops.go +340 -0
  3. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/crud_test.go +309 -0
  4. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/graphql_test.go +133 -0
  5. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/multi_tenancy_test.go +287 -0
  6. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_deleteonconflict_test.go +217 -0
  7. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_test.go +189 -0
  8. platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_timebasedresolution_test.go +225 -0
  9. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/conflicts_test.go +213 -0
  10. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/delete_class_test.go +98 -0
  11. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/delete_tenant_test.go +193 -0
  12. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/endpoints_test.go +327 -0
  13. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/force_delete_ops_test.go +132 -0
  14. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/lazy_shards_test.go +169 -0
  15. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/move_test.go +87 -0
  16. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/mutating_data_test.go +287 -0
  17. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/not_implemented_test.go +114 -0
  18. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/replica_replication_test.go +702 -0
  19. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/large_shard_test.go +139 -0
  20. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/scale_out_test.go +190 -0
platform/dbops/binaries/weaviate-src/test/acceptance/replication/async_replication/async_repair_updates_test.go ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "math/rand"
18
+ "testing"
19
+ "time"
20
+
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ "github.com/weaviate/weaviate/client/nodes"
24
+ "github.com/weaviate/weaviate/cluster/router/types"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/entities/verbosity"
27
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
28
+ "github.com/weaviate/weaviate/test/docker"
29
+ "github.com/weaviate/weaviate/test/helper"
30
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
31
+ )
32
+
33
+ func (suite *AsyncReplicationTestSuite) TestAsyncRepairObjectUpdateScenario() {
34
+ t := suite.T()
35
+ mainCtx := context.Background()
36
+
37
+ clusterSize := 3
38
+
39
+ compose, err := docker.New().
40
+ WithWeaviateCluster(clusterSize).
41
+ WithText2VecContextionary().
42
+ Start(mainCtx)
43
+ require.Nil(t, err)
44
+ defer func() {
45
+ if err := compose.Terminate(mainCtx); err != nil {
46
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
47
+ }
48
+ }()
49
+
50
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
51
+ defer cancel()
52
+
53
+ paragraphClass := articles.ParagraphsClass()
54
+
55
+ t.Run("create schema", func(t *testing.T) {
56
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
57
+ Factor: int64(clusterSize),
58
+ AsyncEnabled: true,
59
+ }
60
+ paragraphClass.Vectorizer = "text2vec-contextionary"
61
+
62
+ helper.SetupClient(compose.GetWeaviate().URI())
63
+ helper.CreateClass(t, paragraphClass)
64
+ })
65
+
66
+ node := 2
67
+
68
+ t.Run(fmt.Sprintf("stop node %d", node), func(t *testing.T) {
69
+ common.StopNodeAt(ctx, t, compose, node)
70
+ })
71
+
72
+ t.Run("upsert paragraphs", func(t *testing.T) {
73
+ batch := make([]*models.Object, len(paragraphIDs))
74
+ for i, id := range paragraphIDs {
75
+ batch[i] = articles.NewParagraph().
76
+ WithID(id).
77
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
78
+ Object()
79
+ }
80
+
81
+ // choose one more node to insert the objects into
82
+ var targetNode int
83
+ for {
84
+ targetNode = 1 + rand.Intn(clusterSize)
85
+ if targetNode != node {
86
+ break
87
+ }
88
+ }
89
+
90
+ common.CreateObjectsCL(t, compose.GetWeaviateNode(targetNode).URI(), batch, types.ConsistencyLevelOne)
91
+ })
92
+
93
+ t.Run(fmt.Sprintf("restart node %d", node), func(t *testing.T) {
94
+ common.StartNodeAt(ctx, t, compose, node)
95
+ time.Sleep(5 * time.Second)
96
+ })
97
+
98
+ t.Run("verify that all nodes are running", func(t *testing.T) {
99
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
100
+ verbose := verbosity.OutputVerbose
101
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose)
102
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
103
+ require.NoError(ct, clientErr)
104
+ require.NotNil(ct, body.Payload)
105
+
106
+ resp := body.Payload
107
+ require.Len(ct, resp.Nodes, clusterSize)
108
+ for _, n := range resp.Nodes {
109
+ require.NotNil(ct, n.Status)
110
+ require.Equal(ct, "HEALTHY", *n.Status)
111
+ }
112
+ }, 15*time.Second, 500*time.Millisecond)
113
+ })
114
+
115
+ t.Run(fmt.Sprintf("assert node %d has all the objects at its latest version", node), func(t *testing.T) {
116
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
117
+ count := common.CountObjects(t, compose.GetWeaviateNode(node).URI(), paragraphClass.Class)
118
+ require.EqualValues(ct, len(paragraphIDs), count)
119
+
120
+ for i, id := range paragraphIDs {
121
+ resp, err := common.GetObjectCL(t, compose.GetWeaviateNode(node).URI(), paragraphClass.Class, id, types.ConsistencyLevelOne)
122
+ require.NoError(ct, err)
123
+ require.NotNil(ct, resp)
124
+ require.Equal(ct, id, resp.ID)
125
+
126
+ props := resp.Properties.(map[string]interface{})
127
+ props["contents"] = fmt.Sprintf("paragraph#%d", i)
128
+ }
129
+ }, 120*time.Second, 5*time.Second, "not all the objects have been asynchronously replicated")
130
+ })
131
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/common/crud_ops.go ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package common
13
+
14
+ import (
15
+ "context"
16
+ "encoding/json"
17
+ "fmt"
18
+ "strings"
19
+ "testing"
20
+ "time"
21
+
22
+ "github.com/go-openapi/strfmt"
23
+ "github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
25
+ "github.com/weaviate/weaviate/client/nodes"
26
+ "github.com/weaviate/weaviate/client/objects"
27
+ "github.com/weaviate/weaviate/cluster/router/types"
28
+ "github.com/weaviate/weaviate/entities/filters"
29
+ "github.com/weaviate/weaviate/entities/models"
30
+ "github.com/weaviate/weaviate/entities/verbosity"
31
+ "github.com/weaviate/weaviate/test/docker"
32
+ "github.com/weaviate/weaviate/test/helper"
33
+ graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
34
+ )
35
+
36
+ // stopNodeAt stops the node container at the given index.
37
+ //
38
+ // NOTE: the index is 1-based, so stopping the first node requires index=1, not 0
39
+ func StopNodeAt(ctx context.Context, t *testing.T, compose *docker.DockerCompose, index int) {
40
+ <-time.After(1 * time.Second)
41
+ if err := compose.StopAt(ctx, index, nil); err != nil {
42
+ // try one more time after 1 second
43
+ <-time.After(1 * time.Second)
44
+ require.NoError(t, compose.StopAt(ctx, index, nil))
45
+ }
46
+ <-time.After(1 * time.Second) // give time for shutdown
47
+ }
48
+
49
+ // startNodeAt starts the node container at the given index.
50
+ //
51
+ // NOTE: the index is 1-based, so starting the first node requires index=1, not 0
52
+ func StartNodeAt(ctx context.Context, t *testing.T, compose *docker.DockerCompose, index int) {
53
+ t.Helper()
54
+ if err := compose.StartAt(ctx, index); err != nil {
55
+ // try one more time after 1 second
56
+ <-time.After(1 * time.Second)
57
+ require.NoError(t, compose.StartAt(ctx, index))
58
+ }
59
+ <-time.After(1 * time.Second)
60
+ }
61
+
62
+ func GetClass(t *testing.T, host, class string) *models.Class {
63
+ t.Helper()
64
+ helper.SetupClient(host)
65
+ return helper.GetClass(t, class)
66
+ }
67
+
68
+ func UpdateClass(t *testing.T, host string, class *models.Class) {
69
+ t.Helper()
70
+ helper.SetupClient(host)
71
+ helper.UpdateClass(t, class)
72
+ }
73
+
74
+ func CreateObjectCL(t *testing.T, host string, obj *models.Object, cl types.ConsistencyLevel) error {
75
+ t.Helper()
76
+ helper.SetupClient(host)
77
+ return helper.CreateObjectCL(t, obj, cl)
78
+ }
79
+
80
+ func CreateObjects(t *testing.T, host string, batch []*models.Object) {
81
+ t.Helper()
82
+ helper.SetupClient(host)
83
+ helper.CreateObjectsBatch(t, batch)
84
+ }
85
+
86
+ func CreateObjectsCL(t *testing.T, host string, batch []*models.Object, cl types.ConsistencyLevel) {
87
+ helper.SetupClient(host)
88
+ helper.CreateObjectsBatchCL(t, batch, cl)
89
+ }
90
+
91
+ func CreateTenantObjects(t *testing.T, host string, batch []*models.Object) {
92
+ t.Helper()
93
+ helper.SetupClient(host)
94
+ helper.CreateObjectsBatch(t, batch)
95
+ }
96
+
97
+ func GetObject(t *testing.T, host, class string, id strfmt.UUID, withVec bool) (*models.Object, error) {
98
+ t.Helper()
99
+ helper.SetupClient(host)
100
+ var include string
101
+ if withVec {
102
+ include = "vector"
103
+ }
104
+ return helper.GetObject(t, class, id, include)
105
+ }
106
+
107
+ func GetTenantObject(t *testing.T, host, class string, id strfmt.UUID, tenant string) (*models.Object, error) {
108
+ t.Helper()
109
+ helper.SetupClient(host)
110
+ return helper.TenantObject(t, class, id, tenant)
111
+ }
112
+
113
+ func ObjectExistsCL(t *testing.T, host, class string, id strfmt.UUID, cl types.ConsistencyLevel) (bool, error) {
114
+ t.Helper()
115
+ helper.SetupClient(host)
116
+ return helper.ObjectExistsCL(t, class, id, cl)
117
+ }
118
+
119
+ func GetObjectCL(t *testing.T, host, class string, id strfmt.UUID, cl types.ConsistencyLevel) (*models.Object, error) {
120
+ t.Helper()
121
+ helper.SetupClient(host)
122
+ return helper.GetObjectCL(t, class, id, cl)
123
+ }
124
+
125
+ func GetObjectFromNode(t *testing.T, host, class string, id strfmt.UUID, nodename string) (*models.Object, error) {
126
+ t.Helper()
127
+ helper.SetupClient(host)
128
+ return helper.GetObjectFromNode(t, class, id, nodename)
129
+ }
130
+
131
+ func GetTenantObjectFromNode(t *testing.T, host, class string, id strfmt.UUID, nodename, tenant string) (*models.Object, error) {
132
+ t.Helper()
133
+ helper.SetupClient(host)
134
+ return helper.GetTenantObjectFromNode(t, class, id, nodename, tenant)
135
+ }
136
+
137
+ func PatchObject(t *testing.T, host string, patch *models.Object) {
138
+ t.Helper()
139
+ helper.SetupClient(host)
140
+ helper.PatchObject(t, patch)
141
+ }
142
+
143
+ func UpdateObjectCL(t *testing.T, host string, obj *models.Object, cl types.ConsistencyLevel) error {
144
+ t.Helper()
145
+ helper.SetupClient(host)
146
+ return helper.UpdateObjectCL(t, obj, cl)
147
+ }
148
+
149
+ func AddReferences(t *testing.T, host string, refs []*models.BatchReference) {
150
+ t.Helper()
151
+ helper.SetupClient(host)
152
+ resp, err := helper.AddReferences(t, refs)
153
+ helper.CheckReferencesBatchResponse(t, resp, err)
154
+ }
155
+
156
+ func AddTenantReferences(t *testing.T, host string, refs []*models.BatchReference) {
157
+ t.Helper()
158
+ helper.SetupClient(host)
159
+ resp, err := helper.AddReferences(t, refs)
160
+ helper.CheckReferencesBatchResponse(t, resp, err)
161
+ }
162
+
163
+ func DeleteObject(t *testing.T, host, class string, id strfmt.UUID, cl types.ConsistencyLevel) {
164
+ t.Helper()
165
+ helper.SetupClient(host)
166
+
167
+ _, err := helper.GetObject(t, class, id)
168
+ require.Nil(t, err)
169
+
170
+ helper.DeleteObjectCL(t, class, id, cl)
171
+
172
+ _, err = helper.GetObject(t, class, id)
173
+ require.Equal(t, &objects.ObjectsClassGetNotFound{}, err)
174
+ }
175
+
176
+ func DeleteTenantObject(t *testing.T, host, class string, id strfmt.UUID, tenant string, cl types.ConsistencyLevel) {
177
+ helper.SetupClient(host)
178
+ helper.DeleteTenantObject(t, class, id, tenant, cl)
179
+
180
+ _, err := helper.TenantObject(t, class, id, tenant)
181
+ assert.Equal(t, &objects.ObjectsClassGetNotFound{}, err)
182
+ }
183
+
184
+ func DeleteObjects(t *testing.T, host, class string, path []string, valueText string, cl types.ConsistencyLevel) {
185
+ t.Helper()
186
+ helper.SetupClient(host)
187
+
188
+ batchDelete := &models.BatchDelete{
189
+ Match: &models.BatchDeleteMatch{
190
+ Class: class,
191
+ Where: &models.WhereFilter{
192
+ Operator: filters.OperatorLike.Name(),
193
+ Path: path,
194
+ ValueText: &valueText,
195
+ },
196
+ },
197
+ }
198
+ helper.DeleteObjectsBatch(t, batchDelete, cl)
199
+
200
+ resp := GQLGet(t, host, class, types.ConsistencyLevelAll)
201
+ assert.Empty(t, resp)
202
+ }
203
+
204
+ func DeleteTenantObjects(t *testing.T, host, class string, path []string, valueText, tenant string, cl types.ConsistencyLevel) {
205
+ t.Helper()
206
+ helper.SetupClient(host)
207
+
208
+ batchDelete := &models.BatchDelete{
209
+ Match: &models.BatchDeleteMatch{
210
+ Class: class,
211
+ Where: &models.WhereFilter{
212
+ Operator: filters.OperatorLike.Name(),
213
+ Path: path,
214
+ ValueText: &valueText,
215
+ },
216
+ },
217
+ }
218
+ resp, err := helper.DeleteTenantObjectsBatchCL(t, batchDelete, tenant, cl)
219
+ helper.AssertRequestOk(t, resp, err, nil)
220
+
221
+ deleted := GQLTenantGet(t, host, class, types.ConsistencyLevelAll, tenant)
222
+ assert.Empty(t, deleted)
223
+ }
224
+
225
+ func GQLGet(t *testing.T, host, class string, cl types.ConsistencyLevel, fields ...string) []interface{} {
226
+ t.Helper()
227
+ helper.SetupClient(host)
228
+
229
+ if cl == "" {
230
+ cl = types.ConsistencyLevelQuorum
231
+ }
232
+
233
+ q := fmt.Sprintf("{Get {%s (consistencyLevel: %s)", class, cl) + " {%s}}}"
234
+ if len(fields) == 0 {
235
+ fields = []string{"_additional{id isConsistent vector}"}
236
+ }
237
+ q = fmt.Sprintf(q, strings.Join(fields, " "))
238
+
239
+ return GQLDo(t, class, q)
240
+ }
241
+
242
+ func GQLGetNearVec(t *testing.T, host, class string, vec []interface{}, cl types.ConsistencyLevel, fields ...string) []interface{} {
243
+ t.Helper()
244
+ helper.SetupClient(host)
245
+
246
+ if cl == "" {
247
+ cl = types.ConsistencyLevelQuorum
248
+ }
249
+
250
+ q := fmt.Sprintf("{Get {%s (consistencyLevel: %s, nearVector: {vector: %s, certainty: 0.8})",
251
+ class, cl, Vec2String(vec)) + " {%s}}}"
252
+ if len(fields) == 0 {
253
+ fields = []string{"_additional{id isConsistent}"}
254
+ }
255
+ q = fmt.Sprintf(q, strings.Join(fields, " "))
256
+
257
+ return GQLDo(t, class, q)
258
+ }
259
+
260
+ func GQLDo(t *testing.T, class, query string) []interface{} {
261
+ t.Helper()
262
+ resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
263
+
264
+ result := resp.Get("Get").Get(class)
265
+ return result.Result.([]interface{})
266
+ }
267
+
268
+ func GQLTenantGet(t *testing.T, host, class string, cl types.ConsistencyLevel,
269
+ tenant string, fields ...string,
270
+ ) []interface{} {
271
+ t.Helper()
272
+ helper.SetupClient(host)
273
+
274
+ if cl == "" {
275
+ cl = types.ConsistencyLevelQuorum
276
+ }
277
+
278
+ q := fmt.Sprintf("{Get {%s (tenant: %q, consistencyLevel: %s, limit: 1000)", class, tenant, cl) + " {%s}}}"
279
+ if len(fields) == 0 {
280
+ fields = []string{"_additional{id isConsistent}"}
281
+ }
282
+ q = fmt.Sprintf(q, strings.Join(fields, " "))
283
+
284
+ resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, q)
285
+
286
+ result := resp.Get("Get").Get(class)
287
+ return result.Result.([]interface{})
288
+ }
289
+
290
+ func CountObjects(t *testing.T, host, class string) int64 {
291
+ helper.SetupClient(host)
292
+
293
+ q := fmt.Sprintf(`{Aggregate{%s{meta{count}}}}`, class)
294
+
295
+ resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, q)
296
+
297
+ result := resp.Get("Aggregate").Get(class).AsSlice()
298
+ require.Len(t, result, 1)
299
+ meta := result[0].(map[string]interface{})["meta"].(map[string]interface{})
300
+ count, err := meta["count"].(json.Number).Int64()
301
+ require.Nil(t, err)
302
+ return count
303
+ }
304
+
305
+ func CountTenantObjects(t *testing.T, host, class string,
306
+ tenant string,
307
+ ) int64 {
308
+ t.Helper()
309
+ helper.SetupClient(host)
310
+
311
+ q := fmt.Sprintf(`{Aggregate{%s(tenant: %q){meta{count}}}}`, class, tenant)
312
+
313
+ resp := graphqlhelper.AssertGraphQL(t, helper.RootAuth, q)
314
+
315
+ result := resp.Get("Aggregate").Get(class).AsSlice()
316
+ require.Len(t, result, 1)
317
+ meta := result[0].(map[string]interface{})["meta"].(map[string]interface{})
318
+ count, err := meta["count"].(json.Number).Int64()
319
+ require.Nil(t, err)
320
+ return count
321
+ }
322
+
323
+ func GetNodes(t *testing.T, host string) *models.NodesStatusResponse {
324
+ t.Helper()
325
+ helper.SetupClient(host)
326
+ verbose := verbosity.OutputVerbose
327
+ params := nodes.NewNodesGetParams().WithOutput(&verbose)
328
+ resp, err := helper.Client(t).Nodes.NodesGet(params, nil)
329
+ helper.AssertRequestOk(t, resp, err, nil)
330
+ return resp.Payload
331
+ }
332
+
333
+ func Vec2String(v []interface{}) (s string) {
334
+ for _, n := range v {
335
+ x := n.(json.Number)
336
+ s = fmt.Sprintf("%s, %s", s, x.String())
337
+ }
338
+ s = strings.TrimLeft(s, ", ")
339
+ return fmt.Sprintf("[%s]", s)
340
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/crud_test.go ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "encoding/json"
17
+ "fmt"
18
+ "testing"
19
+ "time"
20
+
21
+ "github.com/go-openapi/strfmt"
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ "github.com/stretchr/testify/suite"
25
+
26
+ "github.com/weaviate/weaviate/client/objects"
27
+ "github.com/weaviate/weaviate/cluster/router/types"
28
+ "github.com/weaviate/weaviate/entities/models"
29
+ "github.com/weaviate/weaviate/entities/schema/crossref"
30
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
31
+ "github.com/weaviate/weaviate/test/docker"
32
+ "github.com/weaviate/weaviate/test/helper"
33
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
34
+ )
35
+
36
+ var (
37
+ paragraphIDs = []strfmt.UUID{
38
+ strfmt.UUID("3bf331ac-8c86-4f95-b127-2f8f96bbc093"),
39
+ strfmt.UUID("47b26ba1-6bc9-41f8-a655-8b9a5b60e1a3"),
40
+ strfmt.UUID("5fef6289-28d2-4ea2-82a9-48eb501200cd"),
41
+ strfmt.UUID("34a673b4-8859-4cb4-bb30-27f5622b47e9"),
42
+ strfmt.UUID("9fa362f5-c2dc-4fb8-b5b2-11701adc5f75"),
43
+ strfmt.UUID("63735238-6723-4caf-9eaa-113120968ff4"),
44
+ strfmt.UUID("2236744d-b2d2-40e5-95d8-2574f20a7126"),
45
+ strfmt.UUID("1a54e25d-aaf9-48d2-bc3c-bef00b556297"),
46
+ strfmt.UUID("0b8a0e70-a240-44b2-ac6d-26dda97523b9"),
47
+ strfmt.UUID("50566856-5d0a-4fb1-a390-e099bc236f66"),
48
+ }
49
+
50
+ articleIDs = []strfmt.UUID{
51
+ strfmt.UUID("aeaf8743-5a8f-4149-b960-444181d3131a"),
52
+ strfmt.UUID("2a1e9834-064e-4ca8-9efc-35707c6bae6d"),
53
+ strfmt.UUID("8d101c0c-4deb-48d0-805c-d9c691042a1a"),
54
+ strfmt.UUID("b9715fec-ef6c-4e8d-a89e-55e2eebee3f6"),
55
+ strfmt.UUID("faf520f2-f6c3-4cdf-9c16-0348ffd0f8ac"),
56
+ strfmt.UUID("d4c695dd-4dc7-4e49-bc73-089ef5f90fc8"),
57
+ strfmt.UUID("c7949324-e07f-4ffc-8be0-194f0470d375"),
58
+ strfmt.UUID("9c112e01-7759-43ed-a6e8-5defb267c8ee"),
59
+ strfmt.UUID("9bf847f3-3a1a-45a5-b656-311163e536b5"),
60
+ strfmt.UUID("c1975388-d67c-404a-ae77-5983fbaea4bb"),
61
+ }
62
+ )
63
+
64
+ type ReplicationTestSuite struct {
65
+ suite.Suite
66
+ }
67
+
68
+ func (suite *ReplicationTestSuite) SetupTest() {
69
+ suite.T().Setenv("TEST_WEAVIATE_IMAGE", "weaviate/test-server")
70
+ }
71
+
72
+ func TestReplicationTestSuite(t *testing.T) {
73
+ suite.Run(t, new(ReplicationTestSuite))
74
+ }
75
+
76
+ func (suite *ReplicationTestSuite) TestImmediateReplicaCRUD() {
77
+ t := suite.T()
78
+ mainCtx := context.Background()
79
+
80
+ compose, err := docker.New().
81
+ With3NodeCluster().
82
+ WithText2VecContextionary().
83
+ Start(mainCtx)
84
+ require.Nil(t, err)
85
+ defer func() {
86
+ if err := compose.Terminate(mainCtx); err != nil {
87
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
88
+ }
89
+ }()
90
+
91
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
92
+ defer cancel()
93
+
94
+ helper.SetupClient(compose.ContainerURI(1))
95
+ paragraphClass := articles.ParagraphsClass()
96
+ articleClass := articles.ArticlesClass()
97
+
98
+ t.Run("CreateSchema", func(t *testing.T) {
99
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
100
+ Factor: 3,
101
+ }
102
+ helper.CreateClass(t, paragraphClass)
103
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
104
+ Factor: 3,
105
+ }
106
+ helper.CreateClass(t, articleClass)
107
+ })
108
+
109
+ t.Run("InsertParagraphsBatch", func(t *testing.T) {
110
+ t.Run("CreateObjectsOnNode-3", func(t *testing.T) {
111
+ batch := make([]*models.Object, len(paragraphIDs))
112
+ for i, id := range paragraphIDs {
113
+ batch[i] = articles.NewParagraph().
114
+ WithID(id).
115
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
116
+ Object()
117
+ }
118
+ common.CreateObjects(t, compose.ContainerURI(3), batch)
119
+ })
120
+
121
+ t.Run("StopNode-3", func(t *testing.T) {
122
+ common.StopNodeAt(ctx, t, compose, 3)
123
+ })
124
+
125
+ t.Run("ObjectsExistOnNode-1", func(t *testing.T) {
126
+ resp := common.GQLGet(t, compose.ContainerURI(1), "Paragraph", types.ConsistencyLevelOne)
127
+ assert.Len(t, resp, len(paragraphIDs))
128
+ })
129
+
130
+ t.Run("ObjectsExistOnNode-2", func(t *testing.T) {
131
+ resp := common.GQLGet(t, compose.ContainerURI(2), "Paragraph", types.ConsistencyLevelOne)
132
+ require.Len(t, resp, len(paragraphIDs))
133
+ })
134
+
135
+ t.Run("RestartNode-3", func(t *testing.T) {
136
+ err = compose.StartAt(ctx, 3)
137
+ require.Nil(t, err)
138
+ })
139
+ })
140
+
141
+ t.Run("InsertArticlesIndividually", func(t *testing.T) {
142
+ t.Run("CreateObjectsOnNode 3", func(t *testing.T) {
143
+ for i, id := range articleIDs {
144
+ obj := articles.NewArticle().
145
+ WithID(id).
146
+ WithTitle(fmt.Sprintf("Article#%d", i)).
147
+ Object()
148
+ common.CreateObjectCL(t, compose.ContainerURI(3), obj, types.ConsistencyLevelOne)
149
+ }
150
+ })
151
+
152
+ t.Run("StopNode-3", func(t *testing.T) {
153
+ common.StopNodeAt(ctx, t, compose, 3)
154
+ })
155
+
156
+ t.Run("ObjectsExistOnNode-1", func(t *testing.T) {
157
+ resp := common.GQLGet(t, compose.ContainerURI(1), "Article", types.ConsistencyLevelOne)
158
+ require.Len(t, resp, len(articleIDs))
159
+ })
160
+
161
+ t.Run("ObjectsExistOnNode-2", func(t *testing.T) {
162
+ resp := common.GQLGet(t, compose.ContainerURI(2), "Article", types.ConsistencyLevelOne)
163
+ require.Len(t, resp, len(articleIDs))
164
+ })
165
+
166
+ t.Run("RestartNode-3", func(t *testing.T) {
167
+ err = compose.StartAt(ctx, 3)
168
+ require.Nil(t, err)
169
+ })
170
+ })
171
+
172
+ t.Run("AddReferences", func(t *testing.T) {
173
+ refs := make([]*models.BatchReference, len(articleIDs))
174
+ for i := range articleIDs {
175
+ refs[i] = &models.BatchReference{
176
+ From: strfmt.URI(crossref.NewSource("Article", "hasParagraphs", articleIDs[i]).String()),
177
+ To: strfmt.URI(crossref.NewLocalhost("Paragraph", paragraphIDs[i]).String()),
178
+ }
179
+ }
180
+
181
+ t.Run("OnNode-3", func(t *testing.T) {
182
+ common.AddReferences(t, compose.ContainerURI(3), refs)
183
+ })
184
+
185
+ t.Run("StopNode-3", func(t *testing.T) {
186
+ common.StopNodeAt(ctx, t, compose, 3)
187
+ })
188
+
189
+ t.Run("ExistOnNode-2", func(t *testing.T) {
190
+ type additional struct {
191
+ ID strfmt.UUID `json:"id"`
192
+ }
193
+
194
+ type article struct {
195
+ Additional additional `json:"_additional"`
196
+ HasParagraphs []struct {
197
+ Additional additional `json:"_additional"`
198
+ } `json:"hasParagraphs"`
199
+ }
200
+
201
+ // maps article id to referenced paragraph id
202
+ refPairs := make(map[strfmt.UUID]strfmt.UUID)
203
+ resp := common.GQLGet(t, compose.ContainerURI(2), "Article", types.ConsistencyLevelOne,
204
+ "_additional{id}", "hasParagraphs {... on Paragraph {_additional{id}}}")
205
+ require.Len(t, resp, len(articleIDs))
206
+
207
+ for _, r := range resp {
208
+ b, err := json.Marshal(r)
209
+ require.Nil(t, err)
210
+ var art article
211
+ err = json.Unmarshal(b, &art)
212
+ require.Nil(t, err)
213
+ require.Len(t, art.HasParagraphs, 1)
214
+ refPairs[art.Additional.ID] = art.HasParagraphs[0].Additional.ID
215
+ }
216
+
217
+ for i := range articleIDs {
218
+ paragraphID, ok := refPairs[articleIDs[i]]
219
+ require.True(t, ok, "expected %q to be in refPairs: %+v", articleIDs[i], refPairs)
220
+ require.Equal(t, paragraphIDs[i], paragraphID)
221
+ }
222
+ })
223
+
224
+ t.Run("RestartNode-3", func(t *testing.T) {
225
+ err = compose.StartAt(ctx, 3)
226
+ require.Nil(t, err)
227
+ })
228
+ })
229
+
230
+ t.Run("UpdateObject", func(t *testing.T) {
231
+ before, err := common.GetObject(t, compose.ContainerURI(3), "Article", articleIDs[0], false)
232
+ require.Nil(t, err)
233
+ newTitle := "Article#9000"
234
+
235
+ t.Run("OnNode-3", func(t *testing.T) {
236
+ patch := &models.Object{
237
+ ID: before.ID,
238
+ Class: "Article",
239
+ Properties: map[string]interface{}{"title": newTitle},
240
+ }
241
+ common.UpdateObjectCL(t, compose.ContainerURI(3), patch, types.ConsistencyLevelQuorum)
242
+ })
243
+
244
+ t.Run("StopNode-3", func(t *testing.T) {
245
+ common.StopNodeAt(ctx, t, compose, 3)
246
+ })
247
+
248
+ t.Run("PatchedOnNode-1", func(t *testing.T) {
249
+ after, err := common.GetObjectFromNode(t, compose.ContainerURI(1), "Article", articleIDs[0], "node1")
250
+ require.Nil(t, err)
251
+
252
+ newVal, ok := after.Properties.(map[string]interface{})["title"]
253
+ require.True(t, ok)
254
+ require.Equal(t, newTitle, newVal)
255
+ })
256
+
257
+ t.Run("RestartNode-3", func(t *testing.T) {
258
+ require.Nil(t, compose.StartAt(ctx, 3))
259
+ })
260
+ })
261
+
262
+ t.Run("DeleteObject", func(t *testing.T) {
263
+ t.Run("OnNode-3", func(t *testing.T) {
264
+ common.DeleteObject(t, compose.ContainerURI(3), "Article", articleIDs[0], types.ConsistencyLevelAll)
265
+ })
266
+
267
+ t.Run("StopNode-3", func(t *testing.T) {
268
+ common.StopNodeAt(ctx, t, compose, 3)
269
+ })
270
+
271
+ t.Run("OnNode-1", func(t *testing.T) {
272
+ _, err := common.GetObjectFromNode(t, compose.ContainerURI(1), "Article", articleIDs[0], "node1")
273
+ require.Equal(t, &objects.ObjectsClassGetNotFound{}, err)
274
+ })
275
+ t.Run("OnNode-2", func(t *testing.T) {
276
+ _, err := common.GetObjectFromNode(t, compose.ContainerURI(2), "Article", articleIDs[0], "node2")
277
+ require.Equal(t, &objects.ObjectsClassGetNotFound{}, err)
278
+ })
279
+
280
+ t.Run("RestartNode-3", func(t *testing.T) {
281
+ require.Nil(t, compose.StartAt(ctx, 3))
282
+ })
283
+ })
284
+
285
+ t.Run("BatchAllObjects", func(t *testing.T) {
286
+ t.Run("OnNode-3", func(t *testing.T) {
287
+ common.DeleteObjects(t, compose.ContainerURI(3),
288
+ "Article", []string{"title"}, "Article#*", types.ConsistencyLevelAll)
289
+ })
290
+
291
+ t.Run("StopNode-3", func(t *testing.T) {
292
+ common.StopNodeAt(ctx, t, compose, 3)
293
+ })
294
+
295
+ t.Run("OnNode-1", func(t *testing.T) {
296
+ resp := common.GQLGet(t, compose.ContainerURI(1), "Article", types.ConsistencyLevelOne)
297
+ require.Empty(t, resp)
298
+ })
299
+
300
+ t.Run("OnNode-2", func(t *testing.T) {
301
+ resp := common.GQLGet(t, compose.ContainerURI(2), "Article", types.ConsistencyLevelOne)
302
+ require.Empty(t, resp)
303
+ })
304
+
305
+ t.Run("RestartNode-3", func(t *testing.T) {
306
+ require.Nil(t, compose.StartAt(ctx, 3))
307
+ })
308
+ })
309
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/graphql_test.go ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ "github.com/weaviate/weaviate/cluster/router/types"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
25
+ "github.com/weaviate/weaviate/test/docker"
26
+ "github.com/weaviate/weaviate/test/helper"
27
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
28
+ )
29
+
30
+ func (suite *ReplicationTestSuite) TestGraphqlSearch() {
31
+ t := suite.T()
32
+ mainCtx := context.Background()
33
+
34
+ compose, err := docker.New().
35
+ WithWeaviateCluster(3).
36
+ WithText2VecContextionary().
37
+ Start(mainCtx)
38
+ require.Nil(t, err)
39
+ defer func() {
40
+ if err := compose.Terminate(mainCtx); err != nil {
41
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
42
+ }
43
+ }()
44
+
45
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
46
+ defer cancel()
47
+
48
+ helper.SetupClient(compose.ContainerURI(1))
49
+ paragraphClass := articles.ParagraphsClass()
50
+ paragraphClass.Vectorizer = "text2vec-contextionary"
51
+ articleClass := articles.ArticlesClass()
52
+
53
+ t.Run("CreateSchema", func(t *testing.T) {
54
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
55
+ Factor: 2,
56
+ }
57
+ helper.CreateClass(t, paragraphClass)
58
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
59
+ Factor: 2,
60
+ }
61
+ helper.CreateClass(t, articleClass)
62
+ })
63
+
64
+ t.Run("InsertParagraphs", func(t *testing.T) {
65
+ batch := make([]*models.Object, len(paragraphIDs))
66
+ for i, id := range paragraphIDs {
67
+ batch[i] = articles.NewParagraph().
68
+ WithID(id).
69
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
70
+ Object()
71
+ }
72
+ common.CreateObjects(t, compose.ContainerURI(1), batch)
73
+ })
74
+
75
+ t.Run("InsertArticles", func(t *testing.T) {
76
+ batch := make([]*models.Object, len(articleIDs))
77
+ for i, id := range articleIDs {
78
+ batch[i] = articles.NewArticle().
79
+ WithID(id).
80
+ WithTitle(fmt.Sprintf("Article#%d", i)).
81
+ Object()
82
+ }
83
+ common.CreateObjects(t, compose.ContainerURI(2), batch)
84
+ })
85
+
86
+ t.Run("StopNode-2", func(t *testing.T) {
87
+ common.StopNodeAt(ctx, t, compose, 2)
88
+ })
89
+
90
+ t.Run("get consistent search results with ONE (1/2 nodes up)", func(t *testing.T) {
91
+ resp := common.GQLGet(t, compose.ContainerURI(1), paragraphClass.Class, types.ConsistencyLevelOne)
92
+ checkResultsConsistency(t, resp, true)
93
+ })
94
+
95
+ t.Run("RestartNode-2", func(t *testing.T) {
96
+ err = compose.StartAt(ctx, 2)
97
+ require.Nil(t, err)
98
+ })
99
+
100
+ t.Run("get consistent search results with ALL (2/2 nodes up)", func(t *testing.T) {
101
+ resp := common.GQLGet(t, compose.ContainerURI(1), paragraphClass.Class, types.ConsistencyLevelAll)
102
+ checkResultsConsistency(t, resp, true)
103
+ })
104
+
105
+ t.Run("get consistent search results with QUORUM (2/2 nodes up)", func(t *testing.T) {
106
+ resp := common.GQLGet(t, compose.ContainerURI(1), paragraphClass.Class, types.ConsistencyLevelQuorum)
107
+ checkResultsConsistency(t, resp, true)
108
+ })
109
+
110
+ t.Run("get consistent search results with ONE (2/2 nodes up)", func(t *testing.T) {
111
+ resp := common.GQLGet(t, compose.ContainerURI(1), paragraphClass.Class, types.ConsistencyLevelOne)
112
+ checkResultsConsistency(t, resp, true)
113
+ })
114
+
115
+ t.Run("get consistent search results with ONE (2/2 nodes up)", func(t *testing.T) {
116
+ resp := common.GQLGet(t, compose.ContainerURI(1), paragraphClass.Class, types.ConsistencyLevelOne)
117
+ require.GreaterOrEqual(t, len(resp), 1)
118
+ vec := resp[0].(map[string]interface{})["_additional"].(map[string]interface{})["vector"].([]interface{})
119
+ resp = common.GQLGetNearVec(t, compose.ContainerURI(1), paragraphClass.Class, vec, types.ConsistencyLevelQuorum)
120
+ checkResultsConsistency(t, resp, true)
121
+ })
122
+ }
123
+
124
+ func checkResultsConsistency(t *testing.T, results []interface{}, expectConsistent bool) {
125
+ for _, res := range results {
126
+ addl := res.(map[string]interface{})["_additional"].(map[string]interface{})
127
+ if expectConsistent {
128
+ assert.True(t, addl["isConsistent"].(bool))
129
+ } else {
130
+ assert.False(t, addl["isConsistent"].(bool))
131
+ }
132
+ }
133
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/multi_tenancy_test.go ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "encoding/json"
17
+ "fmt"
18
+ "testing"
19
+ "time"
20
+
21
+ "github.com/go-openapi/strfmt"
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ "github.com/weaviate/weaviate/client/objects"
25
+ "github.com/weaviate/weaviate/cluster/router/types"
26
+ "github.com/weaviate/weaviate/entities/models"
27
+ "github.com/weaviate/weaviate/entities/schema/crossref"
28
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
29
+ "github.com/weaviate/weaviate/test/docker"
30
+ "github.com/weaviate/weaviate/test/helper"
31
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
32
+ )
33
+
34
+ const (
35
+ tenantID = strfmt.UUID("45e9e17e-8102-4011-95f0-3079ca188bbf")
36
+ )
37
+
38
+ func (suite *ReplicationTestSuite) TestMultiTenancyEnabled() {
39
+ t := suite.T()
40
+ mainCtx := context.Background()
41
+
42
+ compose, err := docker.New().
43
+ With3NodeCluster().
44
+ WithText2VecContextionary().
45
+ Start(mainCtx)
46
+ require.Nil(t, err)
47
+ defer func() {
48
+ if err := compose.Terminate(mainCtx); err != nil {
49
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
50
+ }
51
+ }()
52
+
53
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
54
+ defer cancel()
55
+
56
+ helper.SetupClient(compose.ContainerURI(1))
57
+ paragraphClass := articles.ParagraphsClass()
58
+ articleClass := articles.ArticlesClass()
59
+
60
+ t.Run("CreateSchema", func(t *testing.T) {
61
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
62
+ Factor: 3,
63
+ }
64
+ paragraphClass.MultiTenancyConfig = &models.MultiTenancyConfig{
65
+ Enabled: true,
66
+ }
67
+ helper.CreateClass(t, paragraphClass)
68
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
69
+ Factor: 3,
70
+ }
71
+ articleClass.MultiTenancyConfig = &models.MultiTenancyConfig{
72
+ Enabled: true,
73
+ }
74
+ helper.CreateClass(t, articleClass)
75
+ })
76
+
77
+ time.Sleep(1 * time.Second) // remove once eventual consistency has been addressed
78
+
79
+ t.Run("AddTenants", func(t *testing.T) {
80
+ tenants := []*models.Tenant{{Name: tenantID.String()}}
81
+ helper.CreateTenants(t, paragraphClass.Class, tenants)
82
+ helper.CreateTenants(t, articleClass.Class, tenants)
83
+ })
84
+
85
+ t.Run("InsertParagraphsBatch", func(t *testing.T) {
86
+ t.Run("OnNode-3", func(t *testing.T) {
87
+ batch := make([]*models.Object, len(paragraphIDs))
88
+ for i, id := range paragraphIDs {
89
+ batch[i] = articles.NewParagraph().
90
+ WithID(id).
91
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
92
+ WithTenant(tenantID.String()).
93
+ Object()
94
+ }
95
+ common.CreateTenantObjects(t, compose.ContainerURI(3), batch)
96
+ })
97
+
98
+ t.Run("StopNode-3", func(t *testing.T) {
99
+ common.StopNodeAt(ctx, t, compose, 3)
100
+ })
101
+
102
+ t.Run("ObjectsExistOnNode-1", func(t *testing.T) {
103
+ count := common.CountTenantObjects(t, compose.ContainerURI(1),
104
+ "Paragraph", tenantID.String())
105
+ assert.Equal(t, int64(len(paragraphIDs)), count)
106
+ })
107
+
108
+ t.Run("ObjectsExistOnNode-2", func(t *testing.T) {
109
+ count := common.CountTenantObjects(t, compose.ContainerURI(2),
110
+ "Paragraph", tenantID.String())
111
+ assert.Equal(t, int64(len(paragraphIDs)), count)
112
+ })
113
+
114
+ t.Run("RestartNode-3", func(t *testing.T) {
115
+ common.StartNodeAt(ctx, t, compose, 3)
116
+ time.Sleep(time.Second)
117
+ })
118
+ })
119
+
120
+ t.Run("InsertArticlesIndividually", func(t *testing.T) {
121
+ t.Run("CreateObjectsOnNode-3", func(t *testing.T) {
122
+ for i, id := range articleIDs {
123
+ obj := articles.NewArticle().
124
+ WithID(id).
125
+ WithTitle(fmt.Sprintf("Article#%d", i)).
126
+ WithTenant(tenantID.String()).
127
+ Object()
128
+ common.CreateObjectCL(t, compose.ContainerURI(3), obj, types.ConsistencyLevelQuorum)
129
+ }
130
+ })
131
+
132
+ t.Run("StopNode-3", func(t *testing.T) {
133
+ time.Sleep(time.Second)
134
+ common.StopNodeAt(ctx, t, compose, 3)
135
+ })
136
+
137
+ t.Run("ObjectsExistOnNode-1", func(t *testing.T) {
138
+ count := common.CountTenantObjects(t, compose.ContainerURI(1),
139
+ "Article", tenantID.String())
140
+ assert.Equal(t, int64(len(articleIDs)), count)
141
+ })
142
+ t.Run("ObjectsExistOnNode-2", func(t *testing.T) {
143
+ count := common.CountTenantObjects(t, compose.ContainerURI(2),
144
+ "Article", tenantID.String())
145
+ assert.Equal(t, int64(len(articleIDs)), count)
146
+ })
147
+
148
+ t.Run("RestartNode-3", func(t *testing.T) {
149
+ common.StartNodeAt(ctx, t, compose, 3)
150
+ time.Sleep(time.Second)
151
+ })
152
+ })
153
+
154
+ t.Run("AddReferences", func(t *testing.T) {
155
+ refs := make([]*models.BatchReference, len(articleIDs))
156
+ for i := range articleIDs {
157
+ refs[i] = &models.BatchReference{
158
+ From: strfmt.URI(crossref.NewSource("Article", "hasParagraphs", articleIDs[i]).String()),
159
+ To: strfmt.URI(crossref.NewLocalhost("Paragraph", paragraphIDs[i]).String()),
160
+ Tenant: tenantID.String(),
161
+ }
162
+ }
163
+
164
+ t.Run("AddReferencesToNode-3", func(t *testing.T) {
165
+ common.AddTenantReferences(t, compose.ContainerURI(3), refs)
166
+ })
167
+
168
+ t.Run("StopNode-3", func(t *testing.T) {
169
+ common.StopNodeAt(ctx, t, compose, 3)
170
+ })
171
+
172
+ t.Run("ReferencesExistsONNode-2", func(t *testing.T) {
173
+ type additional struct {
174
+ ID strfmt.UUID `json:"id"`
175
+ }
176
+
177
+ type article struct {
178
+ Additional additional `json:"_additional"`
179
+ HasParagraphs []struct {
180
+ Additional additional `json:"_additional"`
181
+ } `json:"hasParagraphs"`
182
+ }
183
+
184
+ // maps article id to referenced paragraph id
185
+ refPairs := make(map[strfmt.UUID]strfmt.UUID)
186
+ resp := common.GQLTenantGet(t, compose.ContainerURI(2), "Article", types.ConsistencyLevelOne,
187
+ tenantID.String(), "_additional{id}", "hasParagraphs {... on Paragraph {_additional{id}}}")
188
+ assert.Len(t, resp, len(articleIDs))
189
+
190
+ for _, r := range resp {
191
+ b, err := json.Marshal(r)
192
+ require.Nil(t, err)
193
+ var art article
194
+ err = json.Unmarshal(b, &art)
195
+ require.Nil(t, err)
196
+ require.Len(t, art.HasParagraphs, 1)
197
+ refPairs[art.Additional.ID] = art.HasParagraphs[0].Additional.ID
198
+ }
199
+
200
+ for i := range articleIDs {
201
+ paragraphID, ok := refPairs[articleIDs[i]]
202
+ require.True(t, ok, "expected %q to be in refPairs: %+v", articleIDs[i], refPairs)
203
+ assert.Equal(t, paragraphIDs[i], paragraphID)
204
+ }
205
+ })
206
+
207
+ t.Run("RestartNode-3", func(t *testing.T) {
208
+ common.StartNodeAt(ctx, t, compose, 3)
209
+ time.Sleep(time.Second)
210
+ })
211
+ })
212
+
213
+ t.Run("UpdateObject", func(t *testing.T) {
214
+ before, err := common.GetTenantObject(t, compose.ContainerURI(1), "Article", articleIDs[0], tenantID.String())
215
+ require.Nil(t, err)
216
+ newTitle := "Article#9000"
217
+
218
+ t.Run("OnNode-3", func(t *testing.T) {
219
+ patch := &models.Object{
220
+ ID: before.ID,
221
+ Class: "Article",
222
+ Properties: map[string]interface{}{"title": newTitle},
223
+ Tenant: tenantID.String(),
224
+ }
225
+ common.UpdateObjectCL(t, compose.ContainerURI(3), patch, types.ConsistencyLevelQuorum)
226
+ })
227
+
228
+ t.Run("StopNode-3", func(t *testing.T) {
229
+ common.StopNodeAt(ctx, t, compose, 3)
230
+ })
231
+
232
+ t.Run("PatchedOnNode-1", func(t *testing.T) {
233
+ after, err := common.GetTenantObjectFromNode(t, compose.ContainerURI(1),
234
+ "Article", articleIDs[0], "node1", tenantID.String())
235
+ require.Nil(t, err)
236
+
237
+ newVal, ok := after.Properties.(map[string]interface{})["title"]
238
+ require.True(t, ok)
239
+ assert.Equal(t, newTitle, newVal)
240
+ })
241
+
242
+ t.Run("RestartNode-3", func(t *testing.T) {
243
+ common.StartNodeAt(ctx, t, compose, 3)
244
+ time.Sleep(time.Second)
245
+ })
246
+ })
247
+
248
+ t.Run("DeleteObject", func(t *testing.T) {
249
+ t.Run("OnNode-1", func(t *testing.T) {
250
+ common.DeleteTenantObject(t, compose.ContainerURI(1), "Article", articleIDs[0], tenantID.String(), types.ConsistencyLevelAll)
251
+ })
252
+
253
+ t.Run("StopNode-3", func(t *testing.T) {
254
+ common.StartNodeAt(ctx, t, compose, 3)
255
+ })
256
+
257
+ t.Run("OnNode-2", func(t *testing.T) {
258
+ _, err := common.GetTenantObjectFromNode(t, compose.ContainerURI(2),
259
+ "Article", articleIDs[0], "node2", tenantID.String())
260
+ assert.Equal(t, &objects.ObjectsClassGetNotFound{}, err)
261
+ })
262
+
263
+ t.Run("RestartNode-3", func(t *testing.T) {
264
+ common.StartNodeAt(ctx, t, compose, 3)
265
+ })
266
+ })
267
+
268
+ t.Run("BatchAllObjects", func(t *testing.T) {
269
+ t.Run("OnNode-2", func(t *testing.T) {
270
+ common.DeleteTenantObjects(t, compose.ContainerURI(2),
271
+ "Article", []string{"title"}, "Article#*", tenantID.String(), types.ConsistencyLevelAll)
272
+ })
273
+
274
+ t.Run("StopNode-2", func(t *testing.T) {
275
+ common.StopNodeAt(ctx, t, compose, 2)
276
+ })
277
+
278
+ t.Run("OnNode-1", func(t *testing.T) {
279
+ count := common.CountTenantObjects(t, compose.ContainerURI(1), "Article", tenantID.String())
280
+ assert.Zero(t, count)
281
+ })
282
+
283
+ t.Run("RestartNode-2", func(t *testing.T) {
284
+ common.StartNodeAt(ctx, t, compose, 2)
285
+ })
286
+ })
287
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_deleteonconflict_test.go ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/weaviate/weaviate/cluster/router/types"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
24
+ "github.com/weaviate/weaviate/test/docker"
25
+ "github.com/weaviate/weaviate/test/helper"
26
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
27
+ )
28
+
29
+ func (suite *ReplicationTestSuite) TestReadRepairDeleteOnConflict() {
30
+ t := suite.T()
31
+ mainCtx := context.Background()
32
+
33
+ compose, err := docker.New().
34
+ With3NodeCluster().
35
+ WithText2VecContextionary().
36
+ Start(mainCtx)
37
+ require.Nil(t, err)
38
+ defer func() {
39
+ if err := compose.Terminate(mainCtx); err != nil {
40
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
41
+ }
42
+ }()
43
+
44
+ ctx, cancel := context.WithTimeout(mainCtx, 15*time.Minute)
45
+ defer cancel()
46
+
47
+ helper.SetupClient(compose.GetWeaviate().URI())
48
+ paragraphClass := articles.ParagraphsClass()
49
+ articleClass := articles.ArticlesClass()
50
+
51
+ t.Run("create schema", func(t *testing.T) {
52
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
53
+ Factor: 3,
54
+ DeletionStrategy: models.ReplicationConfigDeletionStrategyDeleteOnConflict,
55
+ }
56
+ paragraphClass.Vectorizer = "text2vec-contextionary"
57
+ helper.CreateClass(t, paragraphClass)
58
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
59
+ Factor: 3,
60
+ DeletionStrategy: models.ReplicationConfigDeletionStrategyDeleteOnConflict,
61
+ }
62
+ helper.CreateClass(t, articleClass)
63
+ })
64
+
65
+ t.Run("insert paragraphs", func(t *testing.T) {
66
+ batch := make([]*models.Object, len(paragraphIDs))
67
+ for i, id := range paragraphIDs {
68
+ batch[i] = articles.NewParagraph().
69
+ WithID(id).
70
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
71
+ Object()
72
+ }
73
+ common.CreateObjects(t, compose.GetWeaviate().URI(), batch)
74
+ })
75
+
76
+ t.Run("insert articles", func(t *testing.T) {
77
+ batch := make([]*models.Object, len(articleIDs))
78
+ for i, id := range articleIDs {
79
+ batch[i] = articles.NewArticle().
80
+ WithID(id).
81
+ WithTitle(fmt.Sprintf("Article#%d", i)).
82
+ Object()
83
+ }
84
+ common.CreateObjects(t, compose.GetWeaviateNode2().URI(), batch)
85
+ })
86
+
87
+ t.Run("stop node 2", func(t *testing.T) {
88
+ common.StopNodeAt(ctx, t, compose, 2)
89
+ })
90
+
91
+ repairObj := models.Object{
92
+ ID: "e5390693-5a22-44b8-997d-2a213aaf5884",
93
+ Class: "Paragraph",
94
+ Properties: map[string]interface{}{
95
+ "contents": "a new paragraph",
96
+ },
97
+ }
98
+
99
+ t.Run("add new object to node one with node2 down", func(t *testing.T) {
100
+ common.CreateObjectCL(t, compose.GetWeaviate().URI(), &repairObj, types.ConsistencyLevelOne)
101
+ })
102
+
103
+ t.Run("restart node 2", func(t *testing.T) {
104
+ common.StartNodeAt(ctx, t, compose, 2)
105
+ })
106
+
107
+ t.Run("run fetch to trigger read repair", func(t *testing.T) {
108
+ _, err := common.GetObjectCL(t, compose.GetWeaviate().URI(), repairObj.Class, repairObj.ID, types.ConsistencyLevelAll)
109
+ require.Nil(t, err)
110
+ })
111
+
112
+ t.Run("require new object read repair was made", func(t *testing.T) {
113
+ resp, err := common.GetObjectCL(t, compose.GetWeaviateNode2().URI(),
114
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelOne)
115
+ require.Nil(t, err)
116
+ require.Equal(t, repairObj.ID, resp.ID)
117
+ require.Equal(t, repairObj.Class, resp.Class)
118
+ require.EqualValues(t, repairObj.Properties, resp.Properties)
119
+ require.EqualValues(t, repairObj.Vector, resp.Vector)
120
+ })
121
+
122
+ t.Run("stop node 3", func(t *testing.T) {
123
+ common.StopNodeAt(ctx, t, compose, 3)
124
+ })
125
+
126
+ replaceObj := repairObj
127
+ replaceObj.Properties = map[string]interface{}{
128
+ "contents": "this paragraph was replaced",
129
+ }
130
+
131
+ t.Run("replace object with node3 down", func(t *testing.T) {
132
+ common.UpdateObjectCL(t, compose.GetWeaviateNode2().URI(), &replaceObj, types.ConsistencyLevelOne)
133
+ })
134
+
135
+ t.Run("restart node 3", func(t *testing.T) {
136
+ common.StartNodeAt(ctx, t, compose, 3)
137
+ })
138
+
139
+ t.Run("run exists to trigger read repair", func(t *testing.T) {
140
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
141
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
142
+ require.Nil(t, err)
143
+ require.True(t, exists)
144
+ })
145
+
146
+ t.Run("require updated object read repair was made", func(t *testing.T) {
147
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
148
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
149
+ require.Nil(t, err)
150
+ require.True(t, exists)
151
+
152
+ resp, err := common.GetObjectCL(t, compose.GetWeaviateNode3().URI(),
153
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelOne)
154
+ require.Nil(t, err)
155
+ require.Equal(t, replaceObj.ID, resp.ID)
156
+ require.Equal(t, replaceObj.Class, resp.Class)
157
+ require.EqualValues(t, replaceObj.Properties, resp.Properties)
158
+ require.EqualValues(t, replaceObj.Vector, resp.Vector)
159
+ })
160
+
161
+ t.Run("stop node 2", func(t *testing.T) {
162
+ common.StopNodeAt(ctx, t, compose, 2)
163
+ })
164
+
165
+ t.Run("delete article with consistency level ONE and node2 down", func(t *testing.T) {
166
+ helper.SetupClient(compose.GetWeaviate().URI())
167
+ helper.DeleteObjectCL(t, replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
168
+ })
169
+
170
+ t.Run("restart node 2", func(t *testing.T) {
171
+ common.StartNodeAt(ctx, t, compose, 2)
172
+ })
173
+
174
+ t.Run("stop node3", func(t *testing.T) {
175
+ common.StopNodeAt(ctx, t, compose, 3)
176
+ })
177
+
178
+ replaceObj.Properties = map[string]interface{}{
179
+ "contents": "this paragraph was replaced for second time",
180
+ }
181
+
182
+ t.Run("replace object in node2 with node3 down", func(t *testing.T) {
183
+ common.UpdateObjectCL(t, compose.GetWeaviateNode2().URI(), &replaceObj, types.ConsistencyLevelOne)
184
+ })
185
+
186
+ t.Run("restart node 3", func(t *testing.T) {
187
+ common.StartNodeAt(ctx, t, compose, 3)
188
+ })
189
+
190
+ t.Run("deleted article should not be present in node3", func(t *testing.T) {
191
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
192
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
193
+ require.Nil(t, err)
194
+ require.False(t, exists)
195
+ })
196
+
197
+ t.Run("run exists to trigger read repair with deleted object resolution", func(t *testing.T) {
198
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
199
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
200
+ require.Nil(t, err)
201
+ require.False(t, exists)
202
+ })
203
+
204
+ t.Run("deleted article should not be present in node3", func(t *testing.T) {
205
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
206
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
207
+ require.Nil(t, err)
208
+ require.False(t, exists)
209
+ })
210
+
211
+ t.Run("deleted article should not be present in node2", func(t *testing.T) {
212
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
213
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
214
+ require.Nil(t, err)
215
+ require.False(t, exists)
216
+ })
217
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_test.go ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/weaviate/weaviate/cluster/router/types"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
24
+ "github.com/weaviate/weaviate/test/docker"
25
+ "github.com/weaviate/weaviate/test/helper"
26
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
27
+ )
28
+
29
+ func (suite *ReplicationTestSuite) TestReadRepair() {
30
+ t := suite.T()
31
+ mainCtx := context.Background()
32
+
33
+ compose, err := docker.New().
34
+ With3NodeCluster().
35
+ WithText2VecContextionary().
36
+ Start(mainCtx)
37
+ require.Nil(t, err)
38
+ defer func() {
39
+ if err := compose.Terminate(mainCtx); err != nil {
40
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
41
+ }
42
+ }()
43
+
44
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
45
+ defer cancel()
46
+
47
+ helper.SetupClient(compose.ContainerURI(1))
48
+ paragraphClass := articles.ParagraphsClass()
49
+ articleClass := articles.ArticlesClass()
50
+
51
+ t.Run("CreateSchema", func(t *testing.T) {
52
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
53
+ Factor: 3,
54
+ }
55
+ paragraphClass.Vectorizer = "text2vec-contextionary"
56
+ helper.CreateClass(t, paragraphClass)
57
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
58
+ Factor: 3,
59
+ }
60
+ helper.CreateClass(t, articleClass)
61
+ })
62
+
63
+ time.Sleep(time.Second) // remove once eventual consistency has been addressed
64
+
65
+ t.Run("InsertParagraphs/Node-1", func(t *testing.T) {
66
+ batch := make([]*models.Object, len(paragraphIDs))
67
+ for i, id := range paragraphIDs {
68
+ batch[i] = articles.NewParagraph().
69
+ WithID(id).
70
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
71
+ Object()
72
+ }
73
+ common.CreateObjects(t, compose.ContainerURI(1), batch)
74
+ })
75
+
76
+ t.Run("InsertArticles/Node-3", func(t *testing.T) {
77
+ batch := make([]*models.Object, len(articleIDs))
78
+ for i, id := range articleIDs {
79
+ batch[i] = articles.NewArticle().
80
+ WithID(id).
81
+ WithTitle(fmt.Sprintf("Article#%d", i)).
82
+ Object()
83
+ }
84
+ common.CreateObjects(t, compose.ContainerURI(3), batch)
85
+ })
86
+
87
+ t.Run("StopNode-3", func(t *testing.T) {
88
+ common.StopNodeAt(ctx, t, compose, 3)
89
+ })
90
+
91
+ repairObj := models.Object{
92
+ ID: "e5390693-5a22-44b8-997d-2a213aaf5884",
93
+ Class: "Paragraph",
94
+ Properties: map[string]interface{}{
95
+ "contents": "a new paragraph",
96
+ },
97
+ }
98
+ t.Run("AddObjectToNode-1", func(t *testing.T) {
99
+ common.CreateObjectCL(t, compose.ContainerURI(1), &repairObj, types.ConsistencyLevelOne)
100
+ })
101
+
102
+ t.Run("RestartNode-3", func(t *testing.T) {
103
+ common.StartNodeAt(ctx, t, compose, 3)
104
+ time.Sleep(time.Second)
105
+ })
106
+
107
+ t.Run("TriggerRepairQuorumOnNode-3", func(t *testing.T) {
108
+ resp, err := common.GetObjectCL(t, compose.ContainerURI(3),
109
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelQuorum)
110
+ require.Nil(t, err)
111
+ require.Equal(t, repairObj.ID, resp.ID)
112
+ require.Equal(t, repairObj.Class, resp.Class)
113
+ require.EqualValues(t, repairObj.Properties, resp.Properties)
114
+ require.EqualValues(t, repairObj.Vector, resp.Vector)
115
+ })
116
+
117
+ t.Run("StopNode-3", func(t *testing.T) {
118
+ common.StopNodeAt(ctx, t, compose, 3)
119
+ })
120
+
121
+ replaceObj := repairObj
122
+ replaceObj.Properties = map[string]interface{}{
123
+ "contents": "this paragraph was replaced",
124
+ }
125
+
126
+ t.Run("ReplaceObjectOneOnNode2", func(t *testing.T) {
127
+ common.UpdateObjectCL(t, compose.ContainerURI(2), &replaceObj, types.ConsistencyLevelOne)
128
+ })
129
+
130
+ t.Run("RestartNode-3", func(t *testing.T) {
131
+ common.StartNodeAt(ctx, t, compose, 3)
132
+ })
133
+
134
+ t.Run("TriggerRepairAllOnNode1", func(t *testing.T) {
135
+ exists, err := common.ObjectExistsCL(t, compose.ContainerURI(1),
136
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
137
+ require.Nil(t, err)
138
+ require.True(t, exists)
139
+ })
140
+
141
+ t.Run("UpdatedObjectRepairedOnNode-3", func(t *testing.T) {
142
+ exists, err := common.ObjectExistsCL(t, compose.ContainerURI(3),
143
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
144
+ require.Nil(t, err)
145
+ require.True(t, exists)
146
+
147
+ resp, err := common.GetObjectCL(t, compose.ContainerURI(1),
148
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelOne)
149
+ require.Nil(t, err)
150
+ require.Equal(t, replaceObj.ID, resp.ID)
151
+ require.Equal(t, replaceObj.Class, resp.Class)
152
+ require.EqualValues(t, replaceObj.Properties, resp.Properties)
153
+ require.EqualValues(t, replaceObj.Vector, resp.Vector)
154
+ })
155
+
156
+ t.Run("stop node2", func(t *testing.T) {
157
+ common.StopNodeAt(ctx, t, compose, 2)
158
+ })
159
+
160
+ t.Run("delete article with consistency level ONE and node2 down", func(t *testing.T) {
161
+ helper.SetupClient(compose.GetWeaviate().URI())
162
+ helper.DeleteObjectCL(t, replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
163
+ })
164
+
165
+ t.Run("restart node2", func(t *testing.T) {
166
+ common.StartNodeAt(ctx, t, compose, 2)
167
+ })
168
+
169
+ t.Run("deleted article should be present in node2", func(t *testing.T) {
170
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
171
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
172
+ require.Nil(t, err)
173
+ require.True(t, exists)
174
+ })
175
+
176
+ t.Run("run exists to trigger read repair with deleted object resolution", func(t *testing.T) {
177
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
178
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
179
+ require.Nil(t, err)
180
+ require.False(t, exists)
181
+ })
182
+
183
+ t.Run("deleted article should still be present in node2 (object deletion is not resolved)", func(t *testing.T) {
184
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
185
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
186
+ require.Nil(t, err)
187
+ require.True(t, exists)
188
+ })
189
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/read_repair/read_repair_timebasedresolution_test.go ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/weaviate/weaviate/cluster/router/types"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
24
+ "github.com/weaviate/weaviate/test/docker"
25
+ "github.com/weaviate/weaviate/test/helper"
26
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
27
+ )
28
+
29
+ func (suite *ReplicationTestSuite) TestReadRepairTimebasedResolution() {
30
+ t := suite.T()
31
+ mainCtx := context.Background()
32
+
33
+ compose, err := docker.New().
34
+ With3NodeCluster().
35
+ WithText2VecContextionary().
36
+ Start(mainCtx)
37
+ require.Nil(t, err)
38
+ defer func() {
39
+ if err := compose.Terminate(mainCtx); err != nil {
40
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
41
+ }
42
+ }()
43
+
44
+ ctx, cancel := context.WithTimeout(mainCtx, 15*time.Minute)
45
+ defer cancel()
46
+
47
+ helper.SetupClient(compose.GetWeaviate().URI())
48
+ paragraphClass := articles.ParagraphsClass()
49
+ articleClass := articles.ArticlesClass()
50
+
51
+ t.Run("create schema", func(t *testing.T) {
52
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
53
+ Factor: 3,
54
+ DeletionStrategy: models.ReplicationConfigDeletionStrategyTimeBasedResolution,
55
+ }
56
+ paragraphClass.Vectorizer = "text2vec-contextionary"
57
+ helper.CreateClass(t, paragraphClass)
58
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
59
+ Factor: 3,
60
+ DeletionStrategy: models.ReplicationConfigDeletionStrategyTimeBasedResolution,
61
+ }
62
+ helper.CreateClass(t, articleClass)
63
+ })
64
+
65
+ t.Run("insert paragraphs", func(t *testing.T) {
66
+ batch := make([]*models.Object, len(paragraphIDs))
67
+ for i, id := range paragraphIDs {
68
+ batch[i] = articles.NewParagraph().
69
+ WithID(id).
70
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
71
+ Object()
72
+ }
73
+ common.CreateObjects(t, compose.GetWeaviate().URI(), batch)
74
+ })
75
+
76
+ t.Run("insert articles", func(t *testing.T) {
77
+ batch := make([]*models.Object, len(articleIDs))
78
+ for i, id := range articleIDs {
79
+ batch[i] = articles.NewArticle().
80
+ WithID(id).
81
+ WithTitle(fmt.Sprintf("Article#%d", i)).
82
+ Object()
83
+ }
84
+ common.CreateObjects(t, compose.GetWeaviateNode2().URI(), batch)
85
+ })
86
+
87
+ t.Run("stop node 2", func(t *testing.T) {
88
+ common.StopNodeAt(ctx, t, compose, 2)
89
+ })
90
+
91
+ repairObj := models.Object{
92
+ ID: "e5390693-5a22-44b8-997d-2a213aaf5884",
93
+ Class: "Paragraph",
94
+ Properties: map[string]interface{}{
95
+ "contents": "a new paragraph",
96
+ },
97
+ }
98
+
99
+ t.Run("add new object to node1 with node2 down", func(t *testing.T) {
100
+ common.CreateObjectCL(t, compose.GetWeaviate().URI(), &repairObj, types.ConsistencyLevelOne)
101
+ })
102
+
103
+ t.Run("restart node 2", func(t *testing.T) {
104
+ common.StartNodeAt(ctx, t, compose, 2)
105
+ })
106
+
107
+ t.Run("run fetch to trigger read repair", func(t *testing.T) {
108
+ _, err := common.GetObjectCL(t, compose.GetWeaviate().URI(), repairObj.Class, repairObj.ID, types.ConsistencyLevelAll)
109
+ require.Nil(t, err)
110
+ })
111
+
112
+ t.Run("require new object read repair was made", func(t *testing.T) {
113
+ resp, err := common.GetObjectCL(t, compose.GetWeaviateNode2().URI(),
114
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelOne)
115
+ require.Nil(t, err)
116
+ require.Equal(t, repairObj.ID, resp.ID)
117
+ require.Equal(t, repairObj.Class, resp.Class)
118
+ require.EqualValues(t, repairObj.Properties, resp.Properties)
119
+ require.EqualValues(t, repairObj.Vector, resp.Vector)
120
+ })
121
+
122
+ replaceObj := repairObj
123
+ replaceObj.Properties = map[string]interface{}{
124
+ "contents": "this paragraph was replaced",
125
+ }
126
+
127
+ t.Run("stop node 3", func(t *testing.T) {
128
+ common.StopNodeAt(ctx, t, compose, 3)
129
+ })
130
+
131
+ t.Run("replace object", func(t *testing.T) {
132
+ common.UpdateObjectCL(t, compose.GetWeaviateNode2().URI(), &replaceObj, types.ConsistencyLevelOne)
133
+ })
134
+
135
+ t.Run("restart node 3", func(t *testing.T) {
136
+ common.StartNodeAt(ctx, t, compose, 3)
137
+ })
138
+
139
+ t.Run("run exists to trigger read repair", func(t *testing.T) {
140
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
141
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
142
+ require.Nil(t, err)
143
+ require.True(t, exists)
144
+ })
145
+
146
+ t.Run("require updated object read repair was made", func(t *testing.T) {
147
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
148
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
149
+ require.Nil(t, err)
150
+ require.True(t, exists)
151
+
152
+ resp, err := common.GetObjectCL(t, compose.GetWeaviateNode3().URI(),
153
+ repairObj.Class, repairObj.ID, types.ConsistencyLevelOne)
154
+ require.Nil(t, err)
155
+ require.Equal(t, replaceObj.ID, resp.ID)
156
+ require.Equal(t, replaceObj.Class, resp.Class)
157
+ require.EqualValues(t, replaceObj.Properties, resp.Properties)
158
+ require.EqualValues(t, replaceObj.Vector, resp.Vector)
159
+ })
160
+
161
+ t.Run("stop node 2", func(t *testing.T) {
162
+ common.StopNodeAt(ctx, t, compose, 2)
163
+ })
164
+
165
+ t.Run("delete article with consistency level ONE and node2 down", func(t *testing.T) {
166
+ helper.SetupClient(compose.GetWeaviate().URI())
167
+ helper.DeleteObjectCL(t, replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
168
+ })
169
+
170
+ t.Run("restart node 2", func(t *testing.T) {
171
+ common.StartNodeAt(ctx, t, compose, 2)
172
+ })
173
+
174
+ t.Run("stop node3", func(t *testing.T) {
175
+ common.StopNodeAt(ctx, t, compose, 3)
176
+ })
177
+
178
+ replaceObj.Properties = map[string]interface{}{
179
+ "contents": "this paragraph was replaced for second time",
180
+ }
181
+
182
+ t.Run("replace object in node2", func(t *testing.T) {
183
+ err := common.UpdateObjectCL(t, compose.GetWeaviateNode2().URI(), &replaceObj, types.ConsistencyLevelOne)
184
+ require.Nil(t, err)
185
+ })
186
+
187
+ t.Run("deleted article should be present in node2", func(t *testing.T) {
188
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
189
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
190
+ require.Nil(t, err)
191
+ require.True(t, exists)
192
+ })
193
+
194
+ t.Run("restart node 3", func(t *testing.T) {
195
+ common.StartNodeAt(ctx, t, compose, 3)
196
+ })
197
+
198
+ t.Run("deleted article should not be present in node3", func(t *testing.T) {
199
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
200
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
201
+ require.Nil(t, err)
202
+ require.False(t, exists)
203
+ })
204
+
205
+ t.Run("run exists to trigger read repair with deleted object resolution", func(t *testing.T) {
206
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
207
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelAll)
208
+ require.Nil(t, err)
209
+ require.True(t, exists)
210
+ })
211
+
212
+ t.Run("deleted article should be present in node2", func(t *testing.T) {
213
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode2().URI(),
214
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
215
+ require.Nil(t, err)
216
+ require.True(t, exists)
217
+ })
218
+
219
+ t.Run("deleted article should be present in node3", func(t *testing.T) {
220
+ exists, err := common.ObjectExistsCL(t, compose.GetWeaviateNode3().URI(),
221
+ replaceObj.Class, replaceObj.ID, types.ConsistencyLevelOne)
222
+ require.Nil(t, err)
223
+ require.True(t, exists)
224
+ })
225
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/conflicts_test.go ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "testing"
17
+ "time"
18
+
19
+ "github.com/go-openapi/strfmt"
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ "github.com/weaviate/weaviate/client/nodes"
23
+ "github.com/weaviate/weaviate/client/replication"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/verbosity"
26
+ "github.com/weaviate/weaviate/test/helper"
27
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
28
+ )
29
+
30
+ func (suite *ReplicationTestSuite) TestReplicationReplicateConflictsCOPY() {
31
+ t := suite.T()
32
+
33
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
34
+ paragraphClass := articles.ParagraphsClass()
35
+ helper.DeleteClass(t, paragraphClass.Class)
36
+ helper.CreateClass(t, paragraphClass)
37
+
38
+ batch := make([]*models.Object, 10000)
39
+ for i := 0; i < 10000; i++ {
40
+ batch[i] = articles.NewParagraph().
41
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
42
+ Object()
43
+ }
44
+ helper.CreateObjectsBatch(t, batch)
45
+
46
+ req := getRequest(t, paragraphClass.Class)
47
+
48
+ var id strfmt.UUID
49
+ t.Run("create COPY replication operation and wait until the replica is in the sharding state", func(t *testing.T) {
50
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(req), nil)
51
+ require.Nil(t, err)
52
+ id = *created.Payload.ID
53
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
54
+ shardingState, err := helper.Client(t).Replication.
55
+ GetCollectionShardingState(replication.
56
+ NewGetCollectionShardingStateParams().
57
+ WithCollection(&paragraphClass.Class), nil)
58
+ require.Nil(t, err)
59
+ replicaPresent := false
60
+ for _, shard := range shardingState.Payload.ShardingState.Shards {
61
+ if shard.Shard != *req.Shard {
62
+ continue
63
+ }
64
+ for _, replica := range shard.Replicas {
65
+ if replica == *req.TargetNode {
66
+ replicaPresent = true
67
+ break
68
+ }
69
+ }
70
+ }
71
+ require.True(ct, replicaPresent)
72
+ }, 60*time.Second, 100*time.Millisecond, "replica should be present in the destination node")
73
+ })
74
+
75
+ t.Run("verify uncancelable state when getting details", func(t *testing.T) {
76
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
77
+ require.Nil(t, err)
78
+ require.True(t, details.Payload.Uncancelable)
79
+ })
80
+
81
+ t.Run("fail to cancel replication operation due to operation being uncancellable", func(t *testing.T) {
82
+ _, err := helper.Client(t).Replication.CancelReplication(replication.NewCancelReplicationParams().WithID(id), nil)
83
+ require.NotNil(t, err)
84
+ require.IsType(t, &replication.CancelReplicationConflict{}, err)
85
+ })
86
+
87
+ // Wait until the replication operation is READY
88
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
89
+ status, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
90
+ require.Nil(t, err)
91
+ require.Equal(ct, "READY", status.Payload.Status.State)
92
+ }, 180*time.Second, 100*time.Millisecond, "Replication operation should be in READY state")
93
+
94
+ t.Run("succeed to delete the replication operation without a conflict", func(t *testing.T) {
95
+ _, err := helper.Client(t).Replication.DeleteReplication(replication.NewDeleteReplicationParams().WithID(id), nil)
96
+ require.Nil(t, err)
97
+ })
98
+
99
+ t.Run("ensure target and source shards are still there", func(t *testing.T) {
100
+ verbose := verbosity.OutputVerbose
101
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class), nil)
102
+ require.Nil(t, err)
103
+ foundSrc := false
104
+ foundDst := false
105
+ for _, node := range nodes.Payload.Nodes {
106
+ if *req.SourceNode == node.Name {
107
+ for _, shard := range node.Shards {
108
+ if shard.Name == *req.Shard {
109
+ foundSrc = true
110
+ }
111
+ }
112
+ }
113
+ if *req.TargetNode == node.Name {
114
+ for _, shard := range node.Shards {
115
+ if shard.Name == *req.Shard {
116
+ foundDst = true
117
+ }
118
+ }
119
+ }
120
+ }
121
+ require.True(t, foundSrc, "source shard should be there")
122
+ require.True(t, foundDst, "destination shard should be there")
123
+ })
124
+ }
125
+
126
+ func (suite *ReplicationTestSuite) TestReplicationReplicateConflictsMOVE() {
127
+ t := suite.T()
128
+
129
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
130
+ paragraphClass := articles.ParagraphsClass()
131
+ helper.DeleteClass(t, paragraphClass.Class)
132
+ helper.CreateClass(t, paragraphClass)
133
+
134
+ req := getRequest(t, paragraphClass.Class)
135
+
136
+ move := "MOVE"
137
+ req.Type = &move
138
+ // Create MOVE replication operation and wait until the shard is in the sharding state (meaning it is uncancellable)
139
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(req), nil)
140
+ require.Nil(t, err)
141
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
142
+ shardingState, err := helper.Client(t).Replication.
143
+ GetCollectionShardingState(replication.
144
+ NewGetCollectionShardingStateParams().
145
+ WithCollection(&paragraphClass.Class), nil)
146
+ require.Nil(t, err)
147
+ replicaPresent := false
148
+ for _, shard := range shardingState.Payload.ShardingState.Shards {
149
+ if shard.Shard != *req.Shard {
150
+ continue
151
+ }
152
+ for _, replica := range shard.Replicas {
153
+ if replica == *req.TargetNode {
154
+ replicaPresent = true
155
+ break
156
+ }
157
+ }
158
+ }
159
+ require.True(ct, replicaPresent)
160
+ }, 60*time.Second, 100*time.Millisecond, "replica should be present in the destination node")
161
+ id := *created.Payload.ID
162
+
163
+ t.Run("fail to cancel replication operation due to uncancellable state", func(t *testing.T) {
164
+ _, err := helper.Client(t).Replication.CancelReplication(replication.NewCancelReplicationParams().WithID(id), nil)
165
+ require.NotNil(t, err)
166
+ require.IsType(t, &replication.CancelReplicationConflict{}, err)
167
+ })
168
+
169
+ t.Run("fail to delete replication operation due to uncancellable state", func(t *testing.T) {
170
+ _, err := helper.Client(t).Replication.DeleteReplication(replication.NewDeleteReplicationParams().WithID(id), nil)
171
+ require.NotNil(t, err)
172
+ require.IsType(t, &replication.DeleteReplicationConflict{}, err)
173
+ })
174
+
175
+ // Wait until the replication operation is READY
176
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
177
+ status, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
178
+ require.Nil(t, err)
179
+ require.Equal(ct, "READY", status.Payload.Status.State)
180
+ }, 180*time.Second, 100*time.Millisecond, "Replication operation should be in READY state")
181
+
182
+ t.Run("succeed to delete the replication operation without a conflict", func(t *testing.T) {
183
+ _, err := helper.Client(t).Replication.DeleteReplication(replication.NewDeleteReplicationParams().WithID(id), nil)
184
+ require.Nil(t, err)
185
+ })
186
+
187
+ // Ensure that the source shard is still there and the destination shard is there
188
+ t.Run("ensure target and source shards are still there", func(t *testing.T) {
189
+ verbose := verbosity.OutputVerbose
190
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class), nil)
191
+ require.Nil(t, err)
192
+ foundSrc := false
193
+ foundDst := false
194
+ for _, node := range nodes.Payload.Nodes {
195
+ if *req.SourceNode == node.Name {
196
+ for _, shard := range node.Shards {
197
+ if shard.Name == *req.Shard {
198
+ foundSrc = true
199
+ }
200
+ }
201
+ }
202
+ if *req.TargetNode == node.Name {
203
+ for _, shard := range node.Shards {
204
+ if shard.Name == *req.Shard {
205
+ foundDst = true
206
+ }
207
+ }
208
+ }
209
+ }
210
+ require.False(t, foundSrc, "source replica should not be there")
211
+ require.True(t, foundDst, "destination replica should be there")
212
+ })
213
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/delete_class_test.go ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "testing"
17
+ "time"
18
+
19
+ "github.com/go-openapi/strfmt"
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ "github.com/weaviate/weaviate/client/nodes"
23
+ "github.com/weaviate/weaviate/client/replication"
24
+ "github.com/weaviate/weaviate/cluster/proto/api"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/test/helper"
27
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
28
+ )
29
+
30
+ func (suite *ReplicationTestSuite) TestReplicationDeletingClassCleansUpOperations() {
31
+ t := suite.T()
32
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
33
+
34
+ paragraphClass := articles.ParagraphsClass()
35
+
36
+ stateToDeleteIn := []api.ShardReplicationState{
37
+ api.REGISTERED,
38
+ api.HYDRATING,
39
+ api.FINALIZING,
40
+ }
41
+
42
+ for _, state := range stateToDeleteIn {
43
+ helper.DeleteClass(t, paragraphClass.Class)
44
+ helper.CreateClass(t, paragraphClass)
45
+
46
+ t.Run("insert paragraphs", func(t *testing.T) {
47
+ batch := make([]*models.Object, 10000)
48
+ for i := 0; i < 10000; i++ {
49
+ batch[i] = articles.NewParagraph().
50
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
51
+ Object()
52
+ }
53
+ helper.CreateObjectsBatch(t, batch)
54
+ })
55
+
56
+ var id strfmt.UUID
57
+ t.Run("create replication operation", func(t *testing.T) {
58
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(getRequest(t, paragraphClass.Class)), nil)
59
+ require.Nil(t, err)
60
+ require.NotNil(t, created)
61
+ require.NotNil(t, created.Payload)
62
+ require.NotNil(t, created.Payload.ID)
63
+ id = *created.Payload.ID
64
+ })
65
+
66
+ if state != api.REGISTERED {
67
+ t.Run(fmt.Sprintf("wait until op is in %s state", state), func(t *testing.T) {
68
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
69
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
70
+ require.Nil(ct, err)
71
+ require.Equal(ct, state.String(), details.Payload.Status.State)
72
+ }, 60*time.Second, 10*time.Millisecond, "replication operation should be in %s state", state)
73
+ })
74
+ }
75
+
76
+ t.Run("delete class", func(t *testing.T) {
77
+ helper.DeleteClass(t, paragraphClass.Class)
78
+ })
79
+
80
+ t.Run("wait for replication operation to be deleted", func(t *testing.T) {
81
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
82
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
83
+ require.NotNil(ct, err)
84
+ assert.IsType(ct, replication.NewReplicationDetailsNotFound(), err)
85
+ }, 120*time.Second, 1*time.Second, fmt.Sprintf("replication operation should be deleted: %s", id))
86
+ })
87
+
88
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
89
+ nodes, err := helper.Client(t).Nodes.NodesGet(nodes.NewNodesGetParams(), nil)
90
+ require.Nil(t, err)
91
+ for _, node := range nodes.Payload.Nodes {
92
+ for _, shard := range node.Shards {
93
+ require.Len(t, shard.AsyncReplicationStatus, 0)
94
+ }
95
+ }
96
+ })
97
+ }
98
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/delete_tenant_test.go ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "slices"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ "github.com/weaviate/weaviate/client/nodes"
24
+ "github.com/weaviate/weaviate/client/replication"
25
+ "github.com/weaviate/weaviate/cluster/proto/api"
26
+ "github.com/weaviate/weaviate/entities/models"
27
+ "github.com/weaviate/weaviate/entities/verbosity"
28
+ "github.com/weaviate/weaviate/test/helper"
29
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
30
+ )
31
+
32
+ func (suite *ReplicationTestSuite) TestReplicationDeletingTenantCleansUpOperations() {
33
+ t := suite.T()
34
+
35
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
36
+ paragraphClass := articles.ParagraphsClass()
37
+ paragraphClass.MultiTenancyConfig = &models.MultiTenancyConfig{
38
+ AutoTenantCreation: true,
39
+ Enabled: true,
40
+ }
41
+
42
+ tenant1 := "tenant1"
43
+ tenant2 := "tenant2"
44
+
45
+ stateToDeleteIn := []api.ShardReplicationState{
46
+ api.REGISTERED,
47
+ api.HYDRATING,
48
+ api.FINALIZING,
49
+ }
50
+
51
+ for _, state := range stateToDeleteIn {
52
+ t.Run(fmt.Sprintf("delete tenant when op is %s", state), func(t *testing.T) {
53
+ helper.DeleteClass(t, paragraphClass.Class)
54
+ helper.CreateClass(t, paragraphClass)
55
+
56
+ t.Run(fmt.Sprintf("insert paragraphs into %s", tenant1), func(t *testing.T) {
57
+ batch := make([]*models.Object, 5000)
58
+ for i := 0; i < 5000; i++ {
59
+ batch[i] = (*models.Object)(articles.NewParagraph().
60
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
61
+ WithTenant(tenant1).
62
+ Object())
63
+ }
64
+ helper.CreateObjectsBatch(t, batch)
65
+ })
66
+
67
+ t.Run(fmt.Sprintf("insert paragraphs into %s", tenant2), func(t *testing.T) {
68
+ batch := make([]*models.Object, 5000)
69
+ for i := 0; i < 5000; i++ {
70
+ batch[i] = (*models.Object)(articles.NewParagraph().
71
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
72
+ WithTenant(tenant2).
73
+ Object())
74
+ }
75
+ helper.CreateObjectsBatch(t, batch)
76
+ })
77
+
78
+ var id1 strfmt.UUID
79
+ t.Run(fmt.Sprintf("create replication operation for %s", tenant1), func(t *testing.T) {
80
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(getMTRequest(t, paragraphClass.Class, tenant1)), nil)
81
+ require.Nil(t, err)
82
+ require.NotNil(t, created)
83
+ require.NotNil(t, created.Payload)
84
+ require.NotNil(t, created.Payload.ID)
85
+ id1 = *created.Payload.ID
86
+ })
87
+
88
+ var id2 strfmt.UUID
89
+ t.Run(fmt.Sprintf("create replication operation for %s", tenant2), func(t *testing.T) {
90
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(getMTRequest(t, paragraphClass.Class, tenant2)), nil)
91
+ require.Nil(t, err)
92
+ require.NotNil(t, created)
93
+ require.NotNil(t, created.Payload)
94
+ require.NotNil(t, created.Payload.ID)
95
+ id2 = *created.Payload.ID
96
+ })
97
+
98
+ if state != api.REGISTERED {
99
+ t.Run(fmt.Sprintf("wait until op for %s is in %s state", tenant1, state), func(t *testing.T) {
100
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
101
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id1), nil)
102
+ require.Nil(ct, err)
103
+ require.Equal(ct, state.String(), details.Payload.Status.State)
104
+ }, 30*time.Second, 100*time.Millisecond, "replication operation should be in %s state", state)
105
+ })
106
+ }
107
+
108
+ t.Run(fmt.Sprintf("delete %s", tenant1), func(t *testing.T) {
109
+ helper.DeleteTenants(t, paragraphClass.Class, []string{tenant1})
110
+ })
111
+
112
+ t.Run("wait for replication operation to be deleted", func(t *testing.T) {
113
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
114
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id1), nil)
115
+ require.NotNil(ct, err)
116
+ assert.IsType(ct, replication.NewReplicationDetailsNotFound(), err)
117
+ }, 30*time.Second, 1*time.Second, "replication operation should be deleted")
118
+ })
119
+
120
+ t.Run(fmt.Sprintf("ensure that the replication operation for %s is still there", tenant2), func(t *testing.T) {
121
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id2), nil)
122
+ require.Nil(t, err)
123
+ require.NotNil(t, details)
124
+ require.NotNil(t, details.Payload)
125
+ require.NotNil(t, details.Payload.ID)
126
+ require.Equal(t, id2, *details.Payload.ID)
127
+ })
128
+
129
+ // Required so we can loop again for other replication operation stages without waiting for it to complete
130
+ // and potentially colliding with replication ops on a per-shard basis, which is a 500
131
+
132
+ t.Run(fmt.Sprintf("delete %s", tenant2), func(t *testing.T) {
133
+ helper.DeleteTenants(t, paragraphClass.Class, []string{tenant2})
134
+ })
135
+
136
+ t.Run("wait for replication operation to be deleted", func(t *testing.T) {
137
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
138
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id2), nil)
139
+ require.NotNil(ct, err)
140
+ assert.IsType(ct, replication.NewReplicationDetailsNotFound(), err)
141
+ }, 30*time.Second, 1*time.Second, "replication operation should be deleted")
142
+ })
143
+
144
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
145
+ nodes, err := helper.Client(t).Nodes.
146
+ NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class), nil)
147
+ require.Nil(t, err)
148
+ for _, node := range nodes.Payload.Nodes {
149
+ for _, shard := range node.Shards {
150
+ require.Len(t, shard.AsyncReplicationStatus, 0)
151
+ }
152
+ }
153
+ })
154
+ })
155
+ }
156
+ }
157
+
158
+ func getMTRequest(t *testing.T, className, tenant string) *models.ReplicationReplicateReplicaRequest {
159
+ verbosity := verbosity.OutputVerbose
160
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithOutput(&verbosity).WithClassName(className), nil)
161
+ require.Nil(t, err)
162
+
163
+ // find node with tenant
164
+ sourceNode := ""
165
+ for _, node := range nodes.Payload.Nodes {
166
+ for _, shard := range node.Shards {
167
+ if shard.Name == tenant {
168
+ sourceNode = node.Name
169
+ break
170
+ }
171
+ }
172
+ }
173
+
174
+ // find node without tenant
175
+ destinationNode := ""
176
+ for _, node := range nodes.Payload.Nodes {
177
+ shards := make([]string, 0)
178
+ for _, shard := range node.Shards {
179
+ shards = append(shards, shard.Name)
180
+ }
181
+ if sourceNode != node.Name && !slices.Contains(shards, tenant) {
182
+ destinationNode = node.Name
183
+ break
184
+ }
185
+ }
186
+
187
+ return &models.ReplicationReplicateReplicaRequest{
188
+ Collection: &className,
189
+ SourceNode: &sourceNode,
190
+ TargetNode: &destinationNode,
191
+ Shard: &tenant,
192
+ }
193
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/endpoints_test.go ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+ "time"
18
+
19
+ "github.com/go-openapi/strfmt"
20
+ "github.com/google/uuid"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ "github.com/stretchr/testify/suite"
24
+ "github.com/weaviate/weaviate/client/nodes"
25
+ "github.com/weaviate/weaviate/client/replication"
26
+ "github.com/weaviate/weaviate/cluster/proto/api"
27
+ "github.com/weaviate/weaviate/entities/models"
28
+ "github.com/weaviate/weaviate/entities/verbosity"
29
+ "github.com/weaviate/weaviate/test/docker"
30
+ "github.com/weaviate/weaviate/test/helper"
31
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
32
+ )
33
+
34
+ type ReplicationTestSuite struct {
35
+ suite.Suite
36
+ compose *docker.DockerCompose
37
+ down func()
38
+ }
39
+
40
+ func (suite *ReplicationTestSuite) SetupSuite() {
41
+ t := suite.T()
42
+ t.Setenv("TEST_WEAVIATE_IMAGE", "weaviate/test-server")
43
+
44
+ mainCtx := context.Background()
45
+
46
+ compose, err := docker.New().
47
+ WithWeaviateCluster(3).
48
+ WithWeaviateEnv("REPLICATION_ENGINE_MAX_WORKERS", "100").
49
+ WithWeaviateEnv("REPLICA_MOVEMENT_MINIMUM_ASYNC_WAIT", "5s").
50
+ Start(mainCtx)
51
+ require.Nil(t, err)
52
+ suite.compose = compose
53
+ suite.down = func() {
54
+ if err := compose.Terminate(mainCtx); err != nil {
55
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
56
+ }
57
+ }
58
+ }
59
+
60
+ func (suite *ReplicationTestSuite) TearDownSuite() {
61
+ if suite.down != nil {
62
+ suite.down()
63
+ }
64
+ }
65
+
66
+ func TestReplicationTestSuite(t *testing.T) {
67
+ suite.Run(t, new(ReplicationTestSuite))
68
+ }
69
+
70
+ func (suite *ReplicationTestSuite) TestReplicationReplicateEndpoints() {
71
+ t := suite.T()
72
+
73
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
74
+ paragraphClass := articles.ParagraphsClass()
75
+ helper.DeleteClass(t, paragraphClass.Class)
76
+ helper.CreateClass(t, paragraphClass)
77
+
78
+ var id strfmt.UUID
79
+ t.Run("get collection sharding state", func(t *testing.T) {
80
+ shardingState, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams().WithCollection(&paragraphClass.Class), nil)
81
+ require.Nil(t, err)
82
+ require.NotNil(t, shardingState)
83
+ require.NotNil(t, shardingState.Payload)
84
+ require.NotNil(t, shardingState.Payload.ShardingState)
85
+ require.NotNil(t, shardingState.Payload.ShardingState.Collection)
86
+ require.NotNil(t, shardingState.Payload.ShardingState.Shards)
87
+ require.Equal(t, paragraphClass.Class, shardingState.Payload.ShardingState.Collection)
88
+ require.Len(t, shardingState.Payload.ShardingState.Shards, 3)
89
+ for _, shard := range shardingState.Payload.ShardingState.Shards {
90
+ require.Len(t, shard.Replicas, 1)
91
+ }
92
+ })
93
+
94
+ t.Run("get collection and shard sharding state", func(t *testing.T) {
95
+ shard := getRequest(t, paragraphClass.Class).Shard
96
+ shardingState, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams().WithCollection(&paragraphClass.Class).WithShard(shard), nil)
97
+ require.Nil(t, err)
98
+ require.NotNil(t, shardingState)
99
+ require.NotNil(t, shardingState.Payload)
100
+ require.NotNil(t, shardingState.Payload.ShardingState)
101
+ require.NotNil(t, shardingState.Payload.ShardingState.Collection)
102
+ require.NotNil(t, shardingState.Payload.ShardingState.Shards)
103
+ require.Equal(t, paragraphClass.Class, shardingState.Payload.ShardingState.Collection)
104
+ require.Len(t, shardingState.Payload.ShardingState.Shards, 1)
105
+ require.Equal(t, *shard, shardingState.Payload.ShardingState.Shards[0].Shard)
106
+ require.Len(t, shardingState.Payload.ShardingState.Shards[0].Replicas, 1)
107
+ })
108
+
109
+ t.Run("get sharding state for non-existing collection", func(t *testing.T) {
110
+ collection := "non-existing"
111
+ _, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams().WithCollection(&collection), nil)
112
+ require.Error(t, err)
113
+ require.IsType(t, replication.NewGetCollectionShardingStateNotFound(), err)
114
+ })
115
+
116
+ t.Run("get sharding state for non-existing collection and shard", func(t *testing.T) {
117
+ collection := "non-existing"
118
+ shard := "non-existing"
119
+ _, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams().WithCollection(&collection).WithShard(&shard), nil)
120
+ require.Error(t, err)
121
+ require.IsType(t, replication.NewGetCollectionShardingStateNotFound(), err)
122
+ })
123
+ t.Run("get sharding state for existing collection and non-existing shard", func(t *testing.T) {
124
+ shard := "non-existing"
125
+ _, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams().WithCollection(&paragraphClass.Class).WithShard(&shard), nil)
126
+ require.Error(t, err)
127
+ require.IsType(t, replication.NewGetCollectionShardingStateNotFound(), err)
128
+ })
129
+
130
+ t.Run("create replication operation", func(t *testing.T) {
131
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(getRequest(t, paragraphClass.Class)), nil)
132
+ require.Nil(t, err)
133
+ require.NotNil(t, created)
134
+ require.NotNil(t, created.Payload)
135
+ require.NotNil(t, created.Payload.ID)
136
+ id = *created.Payload.ID
137
+ })
138
+
139
+ t.Run("get replication operation", func(t *testing.T) {
140
+ includeHistory := true
141
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id).WithIncludeHistory(&includeHistory), nil)
142
+ require.Nil(t, err)
143
+ require.NotNil(t, details)
144
+ require.NotNil(t, details.Payload)
145
+ require.NotNil(t, details.Payload.ID)
146
+ require.False(t, details.Payload.ScheduledForCancel)
147
+ require.False(t, details.Payload.ScheduledForDelete)
148
+ require.False(t, details.Payload.Uncancelable)
149
+ require.Equal(t, id, *details.Payload.ID)
150
+ require.NotNil(t, details.Payload.WhenStartedUnixMs)
151
+ require.Less(t, details.Payload.WhenStartedUnixMs, time.Now().UnixMilli())
152
+ require.NotNil(t, details.Payload.Status.WhenStartedUnixMs)
153
+ require.Less(t, details.Payload.Status.WhenStartedUnixMs, time.Now().UnixMilli())
154
+ for _, status := range details.Payload.StatusHistory {
155
+ require.NotNil(t, status.WhenStartedUnixMs)
156
+ require.Less(t, status.WhenStartedUnixMs, time.Now().UnixMilli())
157
+ }
158
+ })
159
+
160
+ t.Run("get replication operation by collection", func(t *testing.T) {
161
+ details, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithCollection(&paragraphClass.Class), nil)
162
+ require.Nil(t, err)
163
+ found := false
164
+ for _, op := range details.Payload {
165
+ if op.ID != nil && *op.ID == id {
166
+ found = true
167
+ break
168
+ }
169
+ }
170
+ require.True(t, found, "replication operation should be found by collection")
171
+ })
172
+
173
+ t.Run("get replication operation by collection and shard", func(t *testing.T) {
174
+ shard := getRequest(t, paragraphClass.Class).Shard
175
+ details, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithCollection(&paragraphClass.Class).WithShard(shard), nil)
176
+ require.Nil(t, err)
177
+ found := false
178
+ for _, op := range details.Payload {
179
+ if op.ID != nil && *op.ID == id {
180
+ found = true
181
+ break
182
+ }
183
+ }
184
+ require.True(t, found, "replication operation should be found by collection")
185
+ })
186
+
187
+ t.Run("get replication operation by target node", func(t *testing.T) {
188
+ nodeID := getRequest(t, paragraphClass.Class).TargetNode
189
+ details, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithTargetNode(nodeID), nil)
190
+ require.Nil(t, err)
191
+ found := false
192
+ for _, op := range details.Payload {
193
+ if op.ID != nil && *op.ID == id {
194
+ found = true
195
+ break
196
+ }
197
+ }
198
+ require.True(t, found, "replication operation should be found by collection")
199
+ })
200
+
201
+ t.Run("get non-existing replication operation", func(t *testing.T) {
202
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(strfmt.UUID(uuid.New().String())), nil)
203
+ require.NotNil(t, err)
204
+ require.IsType(t, replication.NewReplicationDetailsNotFound(), err)
205
+ })
206
+
207
+ t.Run("list non-existing replication operations by collection", func(t *testing.T) {
208
+ collection := "non-existing"
209
+ res, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithCollection(&collection), nil)
210
+ require.Nil(t, err)
211
+ require.Len(t, res.Payload, 0)
212
+ })
213
+
214
+ t.Run("list non-existing replication operations by collection and shard", func(t *testing.T) {
215
+ collection := "non-existing"
216
+ shard := "non-existing"
217
+ res, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithCollection(&collection).WithShard(&shard), nil)
218
+ require.Nil(t, err)
219
+ require.Len(t, res.Payload, 0)
220
+ })
221
+
222
+ t.Run("list non-existing replication operations with valid collection and non-existing shard", func(t *testing.T) {
223
+ collection := paragraphClass.Class
224
+ shard := "non-existing"
225
+ res, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithCollection(&collection).WithShard(&shard), nil)
226
+ require.Nil(t, err)
227
+ require.Len(t, res.Payload, 0)
228
+ })
229
+
230
+ t.Run("list non-existing replication operations by target node", func(t *testing.T) {
231
+ nodeID := "non-existing"
232
+ res, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams().WithTargetNode(&nodeID), nil)
233
+ require.Nil(t, err)
234
+ require.Len(t, res.Payload, 0)
235
+ })
236
+
237
+ t.Run("cancel replication operation", func(t *testing.T) {
238
+ cancelled, err := helper.Client(t).Replication.CancelReplication(replication.NewCancelReplicationParams().WithID(id), nil)
239
+ require.Nil(t, err)
240
+ require.NotNil(t, cancelled)
241
+ })
242
+
243
+ t.Run("wait for replication operation to be cancelled", func(t *testing.T) {
244
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
245
+ details, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
246
+ require.Nil(t, err)
247
+ assert.Equal(ct, string(api.CANCELLED), details.Payload.Status.State)
248
+ }, 30*time.Second, 1*time.Second, "replication operation should be cancelled")
249
+ })
250
+
251
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
252
+ nodes, err := helper.Client(t).Nodes.
253
+ NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class), nil)
254
+ require.Nil(t, err)
255
+ for _, node := range nodes.Payload.Nodes {
256
+ for _, shard := range node.Shards {
257
+ require.Len(t, shard.AsyncReplicationStatus, 0)
258
+ }
259
+ }
260
+ })
261
+
262
+ t.Run("delete replication operation", func(t *testing.T) {
263
+ deleted, err := helper.Client(t).Replication.DeleteReplication(replication.NewDeleteReplicationParams().WithID(id), nil)
264
+ require.Nil(t, err)
265
+ require.NotNil(t, deleted)
266
+ })
267
+
268
+ t.Run("wait for replication operation to be deleted", func(t *testing.T) {
269
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
270
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
271
+ require.NotNil(ct, err)
272
+ assert.IsType(ct, replication.NewReplicationDetailsNotFound(), err)
273
+ }, 30*time.Second, 1*time.Second, "replication operation should be deleted")
274
+ })
275
+
276
+ t.Run("create one op and immediately delete all replication ops", func(t *testing.T) {
277
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(getRequest(t, paragraphClass.Class)), nil)
278
+ require.Nil(t, err)
279
+ require.NotNil(t, created)
280
+ require.NotNil(t, created.Payload)
281
+ require.NotNil(t, created.Payload.ID)
282
+ id = *created.Payload.ID
283
+
284
+ deleted, err := helper.Client(t).Replication.DeleteAllReplications(replication.NewDeleteAllReplicationsParams(), nil)
285
+ require.Nil(t, err)
286
+ require.NotNil(t, deleted)
287
+ })
288
+
289
+ t.Run("wait for second replication operation to be deleted", func(t *testing.T) {
290
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
291
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
292
+ require.NotNil(ct, err)
293
+ assert.IsType(ct, replication.NewReplicationDetailsNotFound(), err)
294
+ }, 30*time.Second, 1*time.Second, "replication operation should be deleted")
295
+ })
296
+
297
+ t.Run("assert that there are no replication operations", func(t *testing.T) {
298
+ details, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams(), nil)
299
+ require.Nil(t, err)
300
+ require.NotNil(t, details)
301
+ require.NotNil(t, details.Payload)
302
+ require.Len(t, details.Payload, 0)
303
+ })
304
+
305
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
306
+ nodes, err := helper.Client(t).Nodes.
307
+ NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class), nil)
308
+ require.Nil(t, err)
309
+ for _, node := range nodes.Payload.Nodes {
310
+ for _, shard := range node.Shards {
311
+ require.Len(t, shard.AsyncReplicationStatus, 0)
312
+ }
313
+ }
314
+ })
315
+ }
316
+
317
+ func getRequest(t *testing.T, className string) *models.ReplicationReplicateReplicaRequest {
318
+ verbose := verbosity.OutputVerbose
319
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(className), nil)
320
+ require.Nil(t, err)
321
+ return &models.ReplicationReplicateReplicaRequest{
322
+ Collection: &className,
323
+ SourceNode: &nodes.Payload.Nodes[0].Name,
324
+ TargetNode: &nodes.Payload.Nodes[1].Name,
325
+ Shard: &nodes.Payload.Nodes[0].Shards[0].Name,
326
+ }
327
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/force_delete_ops_test.go ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "testing"
17
+
18
+ "github.com/stretchr/testify/require"
19
+ "github.com/weaviate/weaviate/client/nodes"
20
+ "github.com/weaviate/weaviate/client/replication"
21
+ "github.com/weaviate/weaviate/entities/models"
22
+ "github.com/weaviate/weaviate/entities/verbosity"
23
+ "github.com/weaviate/weaviate/test/helper"
24
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
25
+ )
26
+
27
+ func (suite *ReplicationTestSuite) TestReplicationForceDeleteOperations() {
28
+ t := suite.T()
29
+
30
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
31
+
32
+ paragraphClass := articles.ParagraphsClass()
33
+ // Create the class
34
+ helper.DeleteClass(t, paragraphClass.Class)
35
+ helper.CreateClass(t, paragraphClass)
36
+
37
+ // Load data
38
+ batch := make([]*models.Object, 10000)
39
+ for i := 0; i < 10000; i++ {
40
+ batch[i] = articles.NewParagraph().
41
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
42
+ Object()
43
+ }
44
+ helper.CreateObjectsBatch(t, batch)
45
+
46
+ howManyNodes := 3
47
+ shardsPerNode := make(map[string]string, howManyNodes)
48
+
49
+ t.Run("start replication operations", func(t *testing.T) {
50
+ verbose := verbosity.OutputVerbose
51
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class).WithOutput(&verbose), nil)
52
+ require.Nil(t, err)
53
+ require.Len(t, nodes.Payload.Nodes, 3)
54
+ for i, src := range nodes.Payload.Nodes {
55
+ for j, tgt := range nodes.Payload.Nodes {
56
+ if i != (j+1)%howManyNodes {
57
+ continue
58
+ }
59
+ shard := src.Shards[0]
60
+ shardsPerNode[src.Name] = shard.Name
61
+ _, err := helper.Client(t).Replication.Replicate(
62
+ replication.NewReplicateParams().WithBody(&models.ReplicationReplicateReplicaRequest{
63
+ SourceNode: &src.Name,
64
+ TargetNode: &tgt.Name,
65
+ Shard: &shard.Name,
66
+ Collection: &paragraphClass.Class,
67
+ }),
68
+ nil,
69
+ )
70
+ require.Nil(t, err, "failed to start replication from %s to %s", src.Name, tgt.Name)
71
+ }
72
+ }
73
+ })
74
+
75
+ t.Run(fmt.Sprintf("assert that %d operations were started", howManyNodes), func(t *testing.T) {
76
+ resp, err := helper.Client(t).Replication.ListReplication(
77
+ replication.NewListReplicationParams(),
78
+ nil,
79
+ )
80
+ require.Nil(t, err, "failed to list replication details")
81
+ require.Len(t, resp.Payload, howManyNodes, "there should be %d replication operations started", howManyNodes)
82
+ })
83
+
84
+ t.Run("force delete all operations with dryRun=true", func(t *testing.T) {
85
+ dryRun := true
86
+ resp, err := helper.Client(t).Replication.ForceDeleteReplications(
87
+ replication.NewForceDeleteReplicationsParams().WithBody(&models.ReplicationReplicateForceDeleteRequest{
88
+ DryRun: &dryRun,
89
+ }),
90
+ nil,
91
+ )
92
+ require.Nil(t, err, "failed to force delete all replication operations")
93
+ // calling forceDelete with dryRun=true should return the UUIDs of the operations that would be deleted
94
+ require.Len(t, resp.Payload.Deleted, howManyNodes, "there should be %d replication operations to be deleted", howManyNodes)
95
+ require.Equal(t, resp.Payload.DryRun, true, "dry run should be false, we are not in dry run mode")
96
+ })
97
+
98
+ t.Run("force delete all operations dryRun=false", func(t *testing.T) {
99
+ resp, err := helper.Client(t).Replication.ForceDeleteReplications(
100
+ replication.NewForceDeleteReplicationsParams(),
101
+ nil,
102
+ )
103
+ require.Nil(t, err, "failed to force delete all replication operations")
104
+ // calling forceDelete with dryRun=false cannot return the UUIDs of the operations that were deleted so we expect an empty slice
105
+ require.Len(t, resp.Payload.Deleted, 0, "there should be %d replication operations deleted", 0)
106
+ require.Equal(t, resp.Payload.DryRun, false, "dry run should be false, we are not in dry run mode")
107
+ })
108
+
109
+ t.Run("assert that there are no replication operations left", func(t *testing.T) {
110
+ resp, err := helper.Client(t).Replication.ListReplication(
111
+ replication.NewListReplicationParams(),
112
+ nil,
113
+ )
114
+ require.Nil(t, err, "failed to list replication details")
115
+ require.Len(t, resp.Payload, 0, "there should be no replication operations left after force delete")
116
+ })
117
+
118
+ t.Run("assert that the sharding state is still intact", func(t *testing.T) {
119
+ verbose := verbosity.OutputVerbose
120
+ resp, err := helper.Client(t).Nodes.NodesGetClass(
121
+ nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class).WithOutput(&verbose),
122
+ nil,
123
+ )
124
+ require.Nil(t, err, "failed to get nodes for class %s", paragraphClass.Class)
125
+ require.Len(t, resp.Payload.Nodes, howManyNodes, "there should be %d nodes for class %s", howManyNodes, paragraphClass.Class)
126
+
127
+ for _, node := range resp.Payload.Nodes {
128
+ require.Len(t, node.Shards, 1, "each node should have exactly one shard")
129
+ require.Equal(t, shardsPerNode[node.Name], node.Shards[0].Name, "shard name should match the one we started with")
130
+ }
131
+ })
132
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/lazy_shards_test.go ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "math/rand"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ "github.com/weaviate/weaviate/client/nodes"
24
+ "github.com/weaviate/weaviate/client/replication"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/entities/verbosity"
27
+ "github.com/weaviate/weaviate/test/helper"
28
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
29
+ )
30
+
31
+ func (suite *ReplicationTestSuite) TestReplicationReplicateWithLazyShardLoading() {
32
+ t := suite.T()
33
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
34
+
35
+ cls := articles.ParagraphsClass()
36
+ cls.MultiTenancyConfig = &models.MultiTenancyConfig{
37
+ Enabled: true,
38
+ AutoTenantActivation: true,
39
+ AutoTenantCreation: true,
40
+ }
41
+
42
+ // Create the class
43
+ t.Log("Creating class", cls.Class)
44
+ helper.DeleteClass(t, cls.Class)
45
+ helper.CreateClass(t, cls)
46
+
47
+ // Load data
48
+ t.Log("Loading data...")
49
+ tenantNames := make([]string, 0, 100)
50
+ for i := 0; i < 100; i++ {
51
+ t.Logf("into tenant %d", i)
52
+ tenantName := fmt.Sprintf("tenant-%d", i)
53
+ tenantNames = append(tenantNames, tenantName)
54
+ batch := make([]*models.Object, 1000)
55
+ for j := 0; j < 1000; j++ {
56
+ batch[j] = (*models.Object)(articles.NewParagraph().
57
+ WithContents(fmt.Sprintf("paragraph#%d", j)).
58
+ WithTenant(tenantName).
59
+ Object())
60
+ }
61
+ helper.CreateObjectsBatch(t, batch)
62
+ }
63
+
64
+ // Get a random subset of tenants to replicate
65
+ t.Log("Selecting random tenants for replication")
66
+ randomTenants := random(tenantNames, len(tenantNames)/4)
67
+
68
+ // Find the nodes on which the tenants are located
69
+ t.Log("Finding nodes for tenants")
70
+ verbose := verbosity.OutputVerbose
71
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(
72
+ nodes.NewNodesGetClassParams().WithClassName(cls.Class).WithOutput(&verbose),
73
+ nil,
74
+ )
75
+ require.Nil(t, err)
76
+
77
+ replicaByTenant := make(map[string]string, len(randomTenants))
78
+ nodeNames := make([]string, 0, len(nodes.Payload.Nodes))
79
+ for _, node := range nodes.Payload.Nodes {
80
+ nodeNames = append(nodeNames, node.Name)
81
+ for _, shard := range node.Shards {
82
+ for _, tenantName := range randomTenants {
83
+ if shard.Name == tenantName {
84
+ replicaByTenant[tenantName] = node.Name
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ // Deactivate all the tenants
91
+ t.Log("Deactivating all tenants")
92
+ tenants := make([]*models.Tenant, 0, 1000)
93
+ for _, tenantName := range tenantNames {
94
+ tenants = append(tenants, &models.Tenant{Name: tenantName, ActivityStatus: models.TenantActivityStatusINACTIVE})
95
+ }
96
+ helper.UpdateTenants(t, cls.Class, tenants)
97
+
98
+ opIds := make([]strfmt.UUID, 0, len(replicaByTenant))
99
+ for tenantName, sourceNode := range replicaByTenant {
100
+ t.Run(fmt.Sprintf("replicate tenant %s on node %s", tenantName, sourceNode), func(t *testing.T) {
101
+ // Choose random node as the target node
102
+ var targetNode string
103
+ rand.Shuffle(len(nodeNames), func(i, j int) {
104
+ nodeNames[i], nodeNames[j] = nodeNames[j], nodeNames[i]
105
+ })
106
+ for _, tgtNode := range nodeNames {
107
+ if sourceNode != tgtNode {
108
+ targetNode = tgtNode
109
+ t.Logf("Selected target node %s for tenant %s", targetNode, tenantName)
110
+ break
111
+ }
112
+ }
113
+
114
+ // Start replication
115
+ t.Logf("Starting replication for tenant %s from node %s to target node %s", tenantName, sourceNode, targetNode)
116
+ move := "MOVE"
117
+ res, err := helper.Client(t).Replication.Replicate(
118
+ replication.NewReplicateParams().WithBody(&models.ReplicationReplicateReplicaRequest{
119
+ SourceNode: &sourceNode,
120
+ TargetNode: &targetNode,
121
+ Collection: &cls.Class,
122
+ Shard: &tenantName,
123
+ Type: &move,
124
+ }),
125
+ nil,
126
+ )
127
+ require.Nil(t, err, "failed to start replication for tenant %s on node %s", tenantName, sourceNode)
128
+ opIds = append(opIds, *res.Payload.ID)
129
+ })
130
+ }
131
+
132
+ // Wait for all replication operations to complete
133
+ t.Log("Waiting for replication operations to complete")
134
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
135
+ completed := make(map[strfmt.UUID]bool, len(opIds))
136
+ for _, opId := range opIds {
137
+ res, err := helper.Client(t).Replication.ReplicationDetails(
138
+ replication.NewReplicationDetailsParams().WithID(opId),
139
+ nil,
140
+ )
141
+ require.Nil(t, err, "failed to get replication operation %s", opId)
142
+ if res.Payload.Status.State == models.ReplicationReplicateDetailsReplicaStatusStateREADY {
143
+ completed[opId] = true
144
+ } else {
145
+ completed[opId] = false
146
+ }
147
+ }
148
+ howManyDone := 0
149
+ for _, done := range completed {
150
+ if done {
151
+ howManyDone++
152
+ }
153
+ }
154
+ t.Log("Replication operations completed:", howManyDone, "of", len(completed))
155
+ assert.True(ct, howManyDone == len(completed), "not all replication operations completed yet")
156
+ }, 300*time.Second, 5*time.Second, "replication operations did not complete in time")
157
+ }
158
+
159
+ func random[T any](s []T, k int) []T {
160
+ if k > len(s) {
161
+ k = len(s)
162
+ }
163
+ indices := rand.Perm(len(s))[:k]
164
+ result := make([]T, k)
165
+ for i, idx := range indices {
166
+ result[i] = s[idx]
167
+ }
168
+ return result
169
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/move_test.go ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "fmt"
16
+ "testing"
17
+ "time"
18
+
19
+ "github.com/stretchr/testify/assert"
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/weaviate/weaviate/client/nodes"
22
+ "github.com/weaviate/weaviate/client/replication"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/entities/verbosity"
25
+ "github.com/weaviate/weaviate/test/helper"
26
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
27
+ )
28
+
29
+ func (suite *ReplicationTestSuite) TestReplicationReplicateMOVEDeletesSourceReplica() {
30
+ t := suite.T()
31
+
32
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
33
+ paragraphClass := articles.ParagraphsClass()
34
+ helper.DeleteClass(t, paragraphClass.Class)
35
+ helper.CreateClass(t, paragraphClass)
36
+
37
+ // Create paragraphs
38
+ batch := make([]*models.Object, 10000)
39
+ for i := 0; i < 10000; i++ {
40
+ batch[i] = articles.NewParagraph().
41
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
42
+ Object()
43
+ }
44
+ helper.CreateObjectsBatch(t, batch)
45
+
46
+ req := getRequest(t, paragraphClass.Class)
47
+
48
+ move := "MOVE"
49
+ req.Type = &move
50
+ // Create MOVE replication operation and wait until the shard is in the sharding state (meaning it is uncancellable)
51
+ created, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(req), nil)
52
+ require.Nil(t, err)
53
+ id := *created.Payload.ID
54
+
55
+ // Wait until the replication operation is READY
56
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
57
+ status, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
58
+ require.Nil(t, err)
59
+ require.Equal(ct, "READY", status.Payload.Status.State)
60
+ }, 180*time.Second, 100*time.Millisecond, "Replication operation should be in READY state")
61
+
62
+ t.Run("ensure target and source replicas are there/gone respectively", func(t *testing.T) {
63
+ verbose := verbosity.OutputVerbose
64
+ nodes, err := helper.Client(t).Nodes.NodesGetClass(nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class), nil)
65
+ require.Nil(t, err)
66
+ foundSrc := false
67
+ foundDst := false
68
+ for _, node := range nodes.Payload.Nodes {
69
+ if *req.SourceNode == node.Name {
70
+ for _, shard := range node.Shards {
71
+ if shard.Name == *req.Shard {
72
+ foundSrc = true
73
+ }
74
+ }
75
+ }
76
+ if *req.TargetNode == node.Name {
77
+ for _, shard := range node.Shards {
78
+ if shard.Name == *req.Shard {
79
+ foundDst = true
80
+ }
81
+ }
82
+ }
83
+ }
84
+ require.False(t, foundSrc, "source replica should not be there")
85
+ require.True(t, foundDst, "destination replica should be there")
86
+ })
87
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/mutating_data_test.go ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "encoding/json"
17
+ "fmt"
18
+ "math/rand"
19
+ "testing"
20
+ "time"
21
+
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ "github.com/weaviate/weaviate/client"
25
+ "github.com/weaviate/weaviate/client/batch"
26
+ "github.com/weaviate/weaviate/client/graphql"
27
+ "github.com/weaviate/weaviate/client/nodes"
28
+ "github.com/weaviate/weaviate/client/objects"
29
+ "github.com/weaviate/weaviate/client/replication"
30
+ "github.com/weaviate/weaviate/entities/models"
31
+ "github.com/weaviate/weaviate/entities/verbosity"
32
+ "github.com/weaviate/weaviate/test/helper"
33
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
34
+ )
35
+
36
+ func (suite *ReplicationTestSuite) TestReplicationReplicateWhileMutatingDataWithNoAutomatedResolution() {
37
+ test(suite, models.ReplicationConfigDeletionStrategyNoAutomatedResolution)
38
+ }
39
+
40
+ func (suite *ReplicationTestSuite) TestReplicationReplicateWhileMutatingDataWithDeleteOnConflict() {
41
+ test(suite, models.ReplicationConfigDeletionStrategyDeleteOnConflict)
42
+ }
43
+
44
+ func (suite *ReplicationTestSuite) TestReplicationReplicateWhileMutatingDataWithTimeBasedResolution() {
45
+ test(suite, models.ReplicationConfigDeletionStrategyTimeBasedResolution)
46
+ }
47
+
48
+ func test(suite *ReplicationTestSuite, strategy string) {
49
+ t := suite.T()
50
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
51
+
52
+ cls := articles.ParagraphsClass()
53
+ cls.MultiTenancyConfig = &models.MultiTenancyConfig{
54
+ Enabled: true,
55
+ AutoTenantActivation: true,
56
+ AutoTenantCreation: true,
57
+ }
58
+
59
+ cls.ReplicationConfig = &models.ReplicationConfig{
60
+ Factor: int64(2),
61
+ DeletionStrategy: strategy,
62
+ }
63
+
64
+ // Create the class
65
+ t.Log("Creating class", cls.Class)
66
+ helper.DeleteClass(t, cls.Class)
67
+ helper.CreateClass(t, cls)
68
+
69
+ // Wait for all replication ops to be deleted
70
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
71
+ res, err := helper.Client(t).Replication.ListReplication(
72
+ replication.NewListReplicationParams().WithCollection(&cls.Class),
73
+ nil,
74
+ )
75
+ require.Nil(ct, err, "failed to list replication operations for class %s", cls.Class)
76
+ assert.Empty(ct, res.Payload, "there are still replication operations for class %s", cls.Class)
77
+ }, 30*time.Second, 5*time.Second, "replication operations for class %s did not finish in time", cls.Class)
78
+
79
+ // Load data
80
+ t.Log("Loading data into tenant")
81
+ tenantName := "tenant"
82
+ batch := make([]*models.Object, 1000)
83
+ for j := 0; j < 1000; j++ {
84
+ batch[j] = (*models.Object)(articles.NewParagraph().
85
+ WithContents(fmt.Sprintf("paragraph#%d", j)).
86
+ WithTenant(tenantName).
87
+ Object())
88
+ }
89
+ helper.CreateObjectsBatch(t, batch)
90
+
91
+ // Find the nodes on which the tenants are located
92
+ t.Log("Finding nodes and tenant replicas")
93
+ ns, err := helper.Client(t).Nodes.NodesGetClass(
94
+ nodes.NewNodesGetClassParams().WithClassName(cls.Class),
95
+ nil,
96
+ )
97
+ require.Nil(t, err)
98
+ nodeNames := make([]string, 0, len(ns.Payload.Nodes))
99
+ for _, node := range ns.Payload.Nodes {
100
+ nodeNames = append(nodeNames, node.Name)
101
+ }
102
+
103
+ shardingState, err := helper.Client(t).Replication.GetCollectionShardingState(
104
+ replication.NewGetCollectionShardingStateParams().WithCollection(&cls.Class),
105
+ nil,
106
+ )
107
+ require.Nil(t, err)
108
+
109
+ ctx, cancel := context.WithCancel(context.Background())
110
+ defer cancel()
111
+ t.Log("Starting data mutation in background")
112
+ go mutateData(t, ctx, helper.Client(t), cls.Class, tenantName, 100)
113
+
114
+ // Choose other node node as the target node
115
+ var targetNode string
116
+ var sourceNode string
117
+ for _, shard := range shardingState.Payload.ShardingState.Shards {
118
+ if shard.Shard != tenantName {
119
+ continue
120
+ }
121
+ sourceNode = shard.Replicas[0] // Take the first (of two) replica as the source node
122
+ targetNode = symmetricDifference(nodeNames, shard.Replicas)[0] // Choose the other node as the target
123
+ }
124
+
125
+ // Start replication
126
+ t.Logf("Starting replication for tenant %s from node %s to target node %s", tenantName, sourceNode, targetNode)
127
+ move := "MOVE"
128
+ res, err := helper.Client(t).Replication.Replicate(
129
+ replication.NewReplicateParams().WithBody(&models.ReplicationReplicateReplicaRequest{
130
+ SourceNode: &sourceNode,
131
+ TargetNode: &targetNode,
132
+ Collection: &cls.Class,
133
+ Shard: &tenantName,
134
+ Type: &move,
135
+ }),
136
+ nil,
137
+ )
138
+ require.Nil(t, err, "failed to start replication for tenant %s from node %s to node %s", tenantName, sourceNode, targetNode)
139
+ opId := *res.Payload.ID
140
+
141
+ t.Log("Waiting for replication operation to complete")
142
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
143
+ res, err := helper.Client(t).Replication.ReplicationDetails(
144
+ replication.NewReplicationDetailsParams().WithID(opId),
145
+ nil,
146
+ )
147
+ require.Nil(t, err, "failed to get replication operation %s", opId)
148
+ assert.True(ct, res.Payload.Status.State == models.ReplicationReplicateDetailsReplicaStatusStateREADY, "replication operation not completed yet")
149
+ }, 300*time.Second, 5*time.Second, "replication operations did not complete in time")
150
+
151
+ t.Log("Replication operation completed successfully, cancelling data mutation")
152
+ cancel() // stop mutating to allow the verification to proceed
153
+
154
+ t.Log("Waiting for a while to ensure all data is replicated")
155
+
156
+ // Verify that shards all have consistent data
157
+ t.Log("Verifying data consistency of tenant")
158
+
159
+ t.Log("Replication operation completed successfully, cancelling data mutation")
160
+ cancel() // stop mutating to allow the verification to proceed
161
+
162
+ t.Log("Waiting for replicas to converge on object count")
163
+
164
+ verbose := verbosity.OutputVerbose
165
+ ns, err = helper.Client(t).Nodes.NodesGetClass(
166
+ nodes.NewNodesGetClassParams().WithClassName(cls.Class).WithOutput(&verbose),
167
+ nil,
168
+ )
169
+ require.Nil(t, err)
170
+
171
+ nodeToAddress := map[string]string{}
172
+ for idx, node := range ns.Payload.Nodes {
173
+ nodeToAddress[node.Name] = suite.compose.GetWeaviateNode(idx + 1).URI()
174
+ }
175
+
176
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
177
+ consistent := true
178
+ var expected int64 = -1
179
+
180
+ for node, address := range nodeToAddress {
181
+ helper.SetupClient(address)
182
+ res, err := helper.Client(t).Graphql.GraphqlPost(graphql.NewGraphqlPostParams().WithBody(&models.GraphQLQuery{
183
+ Query: fmt.Sprintf(`{ Aggregate { %s(tenant: "%s") { meta { count } } } }`, cls.Class, tenantName),
184
+ }), nil)
185
+ require.Nil(ct, err, "failed to get object count for tenant %s on node %s", tenantName, node)
186
+ val, err := res.Payload.Data["Aggregate"].(map[string]any)["Paragraph"].([]any)[0].(map[string]any)["meta"].(map[string]any)["count"].(json.Number).Int64()
187
+ require.Nil(ct, err, "failed to parse object count for tenant %s on node %s", tenantName, node)
188
+ if expected == -1 {
189
+ expected = val
190
+ }
191
+ if val != expected {
192
+ consistent = false
193
+ }
194
+ }
195
+
196
+ require.True(ct, consistent, "replicas did not converge on object count")
197
+ }, 2*time.Minute, 5*time.Second, "replication operations for class %s did not converge in time", cls.Class)
198
+ }
199
+
200
+ func mutateData(t *testing.T, ctx context.Context, client *client.Weaviate, className string, tenantName string, wait int) {
201
+ for {
202
+ select {
203
+ case <-ctx.Done():
204
+ t.Log("Mutation context done, stopping data mutation")
205
+ return
206
+ default:
207
+ // Add some new objects
208
+ randAdd := rand.Intn(20) + 1
209
+ btch := make([]*models.Object, randAdd)
210
+ for i := 0; i < randAdd; i++ {
211
+ btch[i] = (*models.Object)(articles.NewParagraph().
212
+ WithContents(fmt.Sprintf("new-paragraph#%d", i)).
213
+ WithTenant(tenantName).
214
+ Object())
215
+ }
216
+ all := "ALL"
217
+ params := batch.NewBatchObjectsCreateParams().
218
+ WithBody(batch.BatchObjectsCreateBody{
219
+ Objects: btch,
220
+ }).WithConsistencyLevel(&all)
221
+ client.Batch.BatchObjectsCreate(params, nil)
222
+
223
+ time.Sleep(time.Duration(wait) * time.Millisecond) // Sleep to simulate some delay between mutations
224
+
225
+ // Get the existing objects
226
+ limit := int64(10000)
227
+ res, err := client.Objects.ObjectsList(
228
+ objects.NewObjectsListParams().WithClass(&className).WithTenant(&tenantName).WithLimit(&limit),
229
+ nil,
230
+ )
231
+ if err != nil {
232
+ t.Logf("Error listing objects for tenant %s: %v", tenantName, err)
233
+ continue
234
+ }
235
+ randUpdate := rand.Intn(20) + 1
236
+ toUpdate := random(res.Payload.Objects, randUpdate)
237
+ randDelete := rand.Intn(20) + 1
238
+ toDelete := random(symmetricDifference(res.Payload.Objects, toUpdate), randDelete)
239
+
240
+ time.Sleep(time.Duration(wait) * time.Millisecond) // Sleep to simulate some delay between mutations
241
+
242
+ // Update some existing objects
243
+ for _, obj := range toUpdate {
244
+ updated := (*models.Object)(articles.NewParagraph().
245
+ WithContents(fmt.Sprintf("updated-%s", obj.Properties.(map[string]any)["contents"])).
246
+ WithTenant(tenantName).
247
+ WithID(obj.ID).
248
+ Object())
249
+ client.Objects.ObjectsClassPut(
250
+ objects.NewObjectsClassPutParams().WithID(obj.ID).WithBody(updated).WithConsistencyLevel(&all),
251
+ nil,
252
+ )
253
+ }
254
+
255
+ time.Sleep(time.Duration(wait) * time.Millisecond) // Sleep to simulate some delay between mutations
256
+
257
+ // Delete some existing objects
258
+ for _, obj := range toDelete {
259
+ client.Objects.ObjectsClassDelete(
260
+ objects.NewObjectsClassDeleteParams().WithClassName(className).WithID(obj.ID).WithTenant(&tenantName).WithConsistencyLevel(&all),
261
+ nil,
262
+ )
263
+ }
264
+ }
265
+ }
266
+ }
267
+
268
+ // symmetricDifference returns the symmetric difference of two slices.
269
+ // It returns a slice containing elements that are in either a or b, but not in both
270
+ func symmetricDifference[T comparable](a, b []T) []T {
271
+ count := make(map[T]int)
272
+
273
+ for _, v := range a {
274
+ count[v]++
275
+ }
276
+ for _, v := range b {
277
+ count[v]++
278
+ }
279
+
280
+ var result []T
281
+ for k, v := range count {
282
+ if v == 1 {
283
+ result = append(result, k)
284
+ }
285
+ }
286
+ return result
287
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/not_implemented_test.go ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "github.com/go-openapi/strfmt"
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/stretchr/testify/suite"
22
+ "github.com/weaviate/weaviate/client/replication"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/test/docker"
25
+ "github.com/weaviate/weaviate/test/helper"
26
+ )
27
+
28
+ const UUID = strfmt.UUID("73f2eb5f-5abf-447a-81ca-74b1dd168242")
29
+
30
+ type ReplicationNotImplementedTestSuite struct {
31
+ suite.Suite
32
+ compose *docker.DockerCompose
33
+ down func()
34
+ }
35
+
36
+ func (suite *ReplicationNotImplementedTestSuite) SetupSuite() {
37
+ t := suite.T()
38
+ t.Setenv("TEST_WEAVIATE_IMAGE", "weaviate/test-server")
39
+
40
+ mainCtx := context.Background()
41
+
42
+ compose, err := docker.New().
43
+ WithWeaviateCluster(3).
44
+ WithWeaviateEnv("REPLICA_MOVEMENT_MINIMUM_ASYNC_WAIT", "5s").
45
+ WithWeaviateEnv("REPLICA_MOVEMENT_DISABLED", "true").
46
+ Start(mainCtx)
47
+ require.Nil(t, err)
48
+ suite.compose = compose
49
+ suite.down = func() {
50
+ if err := compose.Terminate(mainCtx); err != nil {
51
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
52
+ }
53
+ }
54
+ }
55
+
56
+ func (suite *ReplicationNotImplementedTestSuite) TearDownSuite() {
57
+ if suite.down != nil {
58
+ suite.down()
59
+ }
60
+ }
61
+
62
+ func TestReplicationNotImplementedTestSuite(t *testing.T) {
63
+ suite.Run(t, new(ReplicationNotImplementedTestSuite))
64
+ }
65
+
66
+ func (suite *ReplicationNotImplementedTestSuite) TestReplicationNotImplemented() {
67
+ t := suite.T()
68
+
69
+ helper.SetupClient(suite.compose.GetWeaviate().URI())
70
+
71
+ t.Run("POST /replication/replicate", func(t *testing.T) {
72
+ _, err := helper.Client(t).Replication.Replicate(replication.NewReplicateParams().WithBody(&models.ReplicationReplicateReplicaRequest{
73
+ Collection: string_("test-collection"),
74
+ TargetNode: string_("tgt-node"),
75
+ Shard: string_("test-shard"),
76
+ SourceNode: string_("src-node"),
77
+ }), nil)
78
+ require.IsType(t, &replication.ReplicateNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for replicate but got %v", err))
79
+ })
80
+
81
+ t.Run("DELETE /replication/replicate", func(t *testing.T) {
82
+ _, err := helper.Client(t).Replication.DeleteAllReplications(replication.NewDeleteAllReplicationsParams(), nil)
83
+ require.IsType(t, &replication.DeleteAllReplicationsNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for delete all replications but got %v", err))
84
+ })
85
+
86
+ t.Run("GET /replication/replicate/{id}", func(t *testing.T) {
87
+ _, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(UUID), nil)
88
+ require.IsType(t, &replication.ReplicationDetailsNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for replication details but got %v", err))
89
+ })
90
+
91
+ t.Run("DELETE /replication/replicate/{id}", func(t *testing.T) {
92
+ _, err := helper.Client(t).Replication.DeleteReplication(replication.NewDeleteReplicationParams().WithID(UUID), nil)
93
+ require.IsType(t, &replication.DeleteReplicationNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for delete replication but got %v", err))
94
+ })
95
+
96
+ t.Run("GET /replication/replicate/list", func(t *testing.T) {
97
+ _, err := helper.Client(t).Replication.ListReplication(replication.NewListReplicationParams(), nil)
98
+ require.IsType(t, &replication.ListReplicationNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for list replication but got %v", err))
99
+ })
100
+
101
+ t.Run("POST /replication/replicate/{id}/cancel", func(t *testing.T) {
102
+ _, err := helper.Client(t).Replication.CancelReplication(replication.NewCancelReplicationParams().WithID(UUID), nil)
103
+ require.IsType(t, &replication.CancelReplicationNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for cancel replication but got %v", err))
104
+ })
105
+
106
+ t.Run("GET /replication/sharding-state", func(t *testing.T) {
107
+ _, err := helper.Client(t).Replication.GetCollectionShardingState(replication.NewGetCollectionShardingStateParams(), nil)
108
+ require.IsType(t, &replication.GetCollectionShardingStateNotImplemented{}, err, fmt.Sprintf("Expected NotImplemented error for get collection sharding state but got %v", err))
109
+ })
110
+ }
111
+
112
+ func string_(s string) *string {
113
+ return &s
114
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/fast/replica_replication_test.go ADDED
@@ -0,0 +1,702 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package replication
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "net/http"
18
+ "testing"
19
+ "time"
20
+
21
+ "github.com/weaviate/weaviate/cluster/proto/api"
22
+
23
+ "github.com/go-openapi/strfmt"
24
+ "github.com/stretchr/testify/assert"
25
+ "github.com/stretchr/testify/require"
26
+ "github.com/stretchr/testify/suite"
27
+ "github.com/weaviate/weaviate/client/nodes"
28
+ "github.com/weaviate/weaviate/client/replication"
29
+ "github.com/weaviate/weaviate/cluster/router/types"
30
+ "github.com/weaviate/weaviate/entities/models"
31
+ "github.com/weaviate/weaviate/entities/verbosity"
32
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
33
+ "github.com/weaviate/weaviate/test/docker"
34
+ "github.com/weaviate/weaviate/test/helper"
35
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
36
+ )
37
+
38
+ var paragraphIDs = []strfmt.UUID{
39
+ strfmt.UUID("3bf331ac-8c86-4f95-b127-2f8f96bbc093"),
40
+ strfmt.UUID("47b26ba1-6bc9-41f8-a655-8b9a5b60e1a3"),
41
+ strfmt.UUID("5fef6289-28d2-4ea2-82a9-48eb501200cd"),
42
+ strfmt.UUID("34a673b4-8859-4cb4-bb30-27f5622b47e9"),
43
+ strfmt.UUID("9fa362f5-c2dc-4fb8-b5b2-11701adc5f75"),
44
+ strfmt.UUID("63735238-6723-4caf-9eaa-113120968ff4"),
45
+ strfmt.UUID("2236744d-b2d2-40e5-95d8-2574f20a7126"),
46
+ strfmt.UUID("1a54e25d-aaf9-48d2-bc3c-bef00b556297"),
47
+ strfmt.UUID("0b8a0e70-a240-44b2-ac6d-26dda97523b9"),
48
+ strfmt.UUID("50566856-5d0a-4fb1-a390-e099bc236f66"),
49
+ }
50
+
51
+ type ReplicationHappyPathTestSuite struct {
52
+ suite.Suite
53
+ }
54
+
55
+ func (suite *ReplicationHappyPathTestSuite) SetupSuite() {
56
+ t := suite.T()
57
+ t.Setenv("TEST_WEAVIATE_IMAGE", "weaviate/test-server")
58
+ }
59
+
60
+ func TestReplicationHappyPathTestSuite(t *testing.T) {
61
+ suite.Run(t, new(ReplicationHappyPathTestSuite))
62
+ }
63
+
64
+ func (suite *ReplicationHappyPathTestSuite) TestReplicaMovementHappyPath() {
65
+ t := suite.T()
66
+ mainCtx := context.Background()
67
+
68
+ compose, err := docker.New().
69
+ WithWeaviateCluster(3).
70
+ WithText2VecContextionary().
71
+ WithWeaviateEnv("REPLICA_MOVEMENT_MINIMUM_ASYNC_WAIT", "5s").
72
+ Start(mainCtx)
73
+ require.Nil(t, err)
74
+ defer func() {
75
+ if err := compose.Terminate(mainCtx); err != nil {
76
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
77
+ }
78
+ }()
79
+
80
+ ctx, cancel := context.WithTimeout(mainCtx, 20*time.Minute)
81
+ defer cancel()
82
+
83
+ helper.SetupClient(compose.GetWeaviate().URI())
84
+ paragraphClass := articles.ParagraphsClass()
85
+ articleClass := articles.ArticlesClass()
86
+
87
+ t.Run("stop node 3", func(t *testing.T) {
88
+ common.StopNodeAt(ctx, t, compose, 3)
89
+ })
90
+
91
+ t.Run("create schema", func(t *testing.T) {
92
+ paragraphClass.ShardingConfig = map[string]interface{}{"desiredCount": 1}
93
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
94
+ Factor: 1,
95
+ AsyncEnabled: false,
96
+ }
97
+ paragraphClass.Vectorizer = "text2vec-contextionary"
98
+ helper.CreateClass(t, paragraphClass)
99
+ articleClass.ShardingConfig = map[string]interface{}{"desiredCount": 1}
100
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
101
+ Factor: 1,
102
+ AsyncEnabled: false,
103
+ }
104
+ helper.CreateClass(t, articleClass)
105
+ })
106
+
107
+ t.Run("restart node 3", func(t *testing.T) {
108
+ common.StartNodeAt(ctx, t, compose, 3)
109
+ })
110
+
111
+ // Setup client again after restart to avoid HTTP error if client setup to container that now has a changed port
112
+ helper.SetupClient(compose.GetWeaviate().URI())
113
+
114
+ t.Run("insert paragraphs", func(t *testing.T) {
115
+ batch := make([]*models.Object, len(paragraphIDs))
116
+ for i, id := range paragraphIDs {
117
+ batch[i] = articles.NewParagraph().
118
+ WithID(id).
119
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
120
+ Object()
121
+ }
122
+ common.CreateObjects(t, compose.GetWeaviate().URI(), batch)
123
+ })
124
+
125
+ t.Run("verify that all nodes are running", func(t *testing.T) {
126
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
127
+ verbose := verbosity.OutputVerbose
128
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose)
129
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
130
+ require.NoError(ct, clientErr)
131
+ require.NotNil(ct, body.Payload)
132
+
133
+ resp := body.Payload
134
+ require.Len(ct, resp.Nodes, 3)
135
+ for _, n := range resp.Nodes {
136
+ require.NotNil(ct, n.Status)
137
+ assert.Equal(ct, "HEALTHY", *n.Status)
138
+ }
139
+ }, 15*time.Second, 500*time.Millisecond)
140
+ })
141
+
142
+ var uuid strfmt.UUID
143
+ sourceNode := -1
144
+ t.Run("start replica replication to node3 for paragraph", func(t *testing.T) {
145
+ verbose := verbosity.OutputVerbose
146
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class)
147
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
148
+ require.NoError(t, clientErr)
149
+ require.NotNil(t, body.Payload)
150
+ targetNode := "node3"
151
+ hasFoundNode := false
152
+ hasFoundShard := false
153
+
154
+ for i, node := range body.Payload.Nodes {
155
+ if node.Name == targetNode {
156
+ continue
157
+ }
158
+
159
+ if len(node.Shards) >= 1 {
160
+ hasFoundNode = true
161
+ } else {
162
+ continue
163
+ }
164
+
165
+ replicationType := api.COPY.String()
166
+ for _, shard := range node.Shards {
167
+ if shard.Class != paragraphClass.Class {
168
+ continue
169
+ }
170
+ hasFoundShard = true
171
+
172
+ t.Logf("Starting replica replication from %s to %s for shard %s", node.Name, targetNode, shard.Name)
173
+ // i + 1 because stop/start routine are 1 based not 0
174
+ sourceNode = i + 1
175
+ resp, err := helper.Client(t).Replication.Replicate(
176
+ replication.NewReplicateParams().WithBody(
177
+ &models.ReplicationReplicateReplicaRequest{
178
+ Collection: &paragraphClass.Class,
179
+ SourceNode: &node.Name,
180
+ TargetNode: &targetNode,
181
+ Shard: &shard.Name,
182
+ Type: &replicationType,
183
+ },
184
+ ),
185
+ nil,
186
+ )
187
+ require.NoError(t, err)
188
+ require.Equal(t, http.StatusOK, resp.Code(), "replication replicate operation didn't return 200 OK")
189
+ require.NotNil(t, resp.Payload)
190
+ require.NotNil(t, resp.Payload.ID)
191
+ require.NotEmpty(t, *resp.Payload.ID)
192
+ uuid = *resp.Payload.ID
193
+ }
194
+ }
195
+ require.True(t, hasFoundShard, "could not find shard for class %s", paragraphClass.Class)
196
+ require.True(t, hasFoundNode, "could not find node with shards for paragraph")
197
+ })
198
+
199
+ // If no node was found fail now
200
+ if sourceNode == -1 {
201
+ t.FailNow()
202
+ }
203
+
204
+ // Wait for the replication to finish
205
+ t.Run("waiting for replication to finish", func(t *testing.T) {
206
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
207
+ details, err := helper.Client(t).Replication.ReplicationDetails(
208
+ replication.NewReplicationDetailsParams().WithID(uuid), nil,
209
+ )
210
+ assert.Nil(t, err, "failed to get replication details %s", err)
211
+ assert.NotNil(t, details, "expected replication details to be not nil")
212
+ assert.NotNil(t, details.Payload, "expected replication details payload to be not nil")
213
+ assert.NotNil(t, details.Payload.Status, "expected replication status to be not nil")
214
+ assert.Equal(ct, "READY", details.Payload.Status.State, "expected replication status to be READY")
215
+ }, 360*time.Second, 3*time.Second, "replication operation %s not finished in time", uuid)
216
+ })
217
+
218
+ // Kills the original node with the data to ensure we have only one replica available (the new one)
219
+ t.Run(fmt.Sprintf("stop node %d", sourceNode), func(t *testing.T) {
220
+ common.StopNodeAt(ctx, t, compose, sourceNode)
221
+ })
222
+
223
+ t.Run("assert data is available for paragraph on node3 with consistency level one", func(t *testing.T) {
224
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
225
+ for _, objId := range paragraphIDs {
226
+ exists, err := common.ObjectExistsCL(t, compose.ContainerURI(3), paragraphClass.Class, objId, types.ConsistencyLevelOne)
227
+ assert.Nil(ct, err)
228
+ assert.True(ct, exists)
229
+
230
+ resp, err := common.GetObjectCL(t, compose.ContainerURI(3), paragraphClass.Class, objId, types.ConsistencyLevelOne)
231
+ assert.Nil(ct, err)
232
+ assert.NotNil(ct, resp)
233
+ }
234
+ }, 10*time.Second, 1*time.Second, "node3 doesn't have paragraph data")
235
+ })
236
+
237
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
238
+ nodes, err := helper.Client(t).Nodes.
239
+ NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class), nil)
240
+ require.Nil(t, err)
241
+ for _, node := range nodes.Payload.Nodes {
242
+ for _, shard := range node.Shards {
243
+ require.Len(t, shard.AsyncReplicationStatus, 0)
244
+ }
245
+ }
246
+ })
247
+ }
248
+
249
+ func (suite *ReplicationHappyPathTestSuite) TestReplicaMovementTenantHappyPath() {
250
+ t := suite.T()
251
+ mainCtx := context.Background()
252
+
253
+ compose, err := docker.New().
254
+ WithWeaviateCluster(3).
255
+ WithText2VecContextionary().
256
+ WithWeaviateEnv("REPLICA_MOVEMENT_MINIMUM_ASYNC_WAIT", "5s").
257
+ Start(mainCtx)
258
+ require.Nil(t, err)
259
+ defer func() {
260
+ if err := compose.Terminate(mainCtx); err != nil {
261
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
262
+ }
263
+ }()
264
+
265
+ ctx, cancel := context.WithTimeout(mainCtx, 20*time.Minute)
266
+ defer cancel()
267
+
268
+ helper.SetupClient(compose.GetWeaviate().URI())
269
+ paragraphClass := articles.ParagraphsClass()
270
+ articleClass := articles.ArticlesClass()
271
+
272
+ t.Run("create schema", func(t *testing.T) {
273
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
274
+ Factor: 1,
275
+ AsyncEnabled: false,
276
+ }
277
+ paragraphClass.MultiTenancyConfig = &models.MultiTenancyConfig{
278
+ Enabled: true,
279
+ AutoTenantActivation: true,
280
+ AutoTenantCreation: true,
281
+ }
282
+ paragraphClass.Vectorizer = "text2vec-contextionary"
283
+ helper.CreateClass(t, paragraphClass)
284
+ articleClass.ReplicationConfig = &models.ReplicationConfig{
285
+ Factor: 1,
286
+ AsyncEnabled: false,
287
+ }
288
+ articleClass.MultiTenancyConfig = &models.MultiTenancyConfig{
289
+ Enabled: true,
290
+ AutoTenantActivation: true,
291
+ AutoTenantCreation: true,
292
+ }
293
+ helper.CreateClass(t, articleClass)
294
+ })
295
+
296
+ t.Run("insert paragraphs", func(t *testing.T) {
297
+ batch := make([]*models.Object, len(paragraphIDs))
298
+ for i, id := range paragraphIDs {
299
+ batch[i] = articles.NewParagraph().
300
+ WithID(id).
301
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
302
+ WithTenant("tenant0").
303
+ Object()
304
+ }
305
+ common.CreateObjects(t, compose.GetWeaviate().URI(), batch)
306
+ })
307
+
308
+ // any node can be chosen as the tenant source node (even if that node is down at the time of creation)
309
+ // so we dynamically find the source and target nodes
310
+ sourceNode := -1
311
+ var targetNode string
312
+ var targetNodeURI string
313
+ var uuid strfmt.UUID
314
+ t.Run("start replica replication to node3 for paragraph", func(t *testing.T) {
315
+ verbose := verbosity.OutputVerbose
316
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class)
317
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
318
+ require.NoError(t, clientErr)
319
+ require.NotNil(t, body.Payload)
320
+
321
+ hasFoundNode := false
322
+ hasFoundShard := false
323
+
324
+ for i, node := range body.Payload.Nodes {
325
+ if len(node.Shards) >= 1 {
326
+ hasFoundNode = true
327
+ } else {
328
+ continue
329
+ }
330
+
331
+ for _, shard := range node.Shards {
332
+ if shard.Class != paragraphClass.Class {
333
+ continue
334
+ }
335
+ hasFoundShard = true
336
+
337
+ t.Logf("Starting replica replication from %s to another node for shard %s", node.Name, shard.Name)
338
+ // i + 1 because stop/start routine are 1 based not 0
339
+ sourceNode = i + 1
340
+ break
341
+ }
342
+
343
+ if hasFoundShard {
344
+ break
345
+ }
346
+ }
347
+
348
+ require.True(t, hasFoundShard, "could not find shard for class %s", paragraphClass.Class)
349
+ require.True(t, hasFoundNode, "could not find node with shards for paragraph")
350
+
351
+ // Choose a target node that is not the source node
352
+ for i, node := range body.Payload.Nodes {
353
+ if i+1 == sourceNode {
354
+ continue
355
+ }
356
+ targetNode = node.Name
357
+ targetNodeURI = compose.ContainerURI(i + 1)
358
+ break
359
+ }
360
+
361
+ require.NotEmpty(t, targetNode, "could not find a target node different from the source node")
362
+
363
+ for _, node := range body.Payload.Nodes {
364
+ if node.Name == targetNode {
365
+ continue
366
+ }
367
+
368
+ for _, shard := range node.Shards {
369
+ if shard.Class != paragraphClass.Class {
370
+ continue
371
+ }
372
+
373
+ t.Logf("Starting replica replication from %s to %s for shard %s", node.Name, targetNode, shard.Name)
374
+ resp, err := helper.Client(t).Replication.Replicate(
375
+ replication.NewReplicateParams().WithBody(
376
+ &models.ReplicationReplicateReplicaRequest{
377
+ Collection: &paragraphClass.Class,
378
+ SourceNode: &node.Name,
379
+ TargetNode: &targetNode,
380
+ Shard: &shard.Name,
381
+ },
382
+ ),
383
+ nil,
384
+ )
385
+ require.NoError(t, err)
386
+ require.Equal(t, http.StatusOK, resp.Code(), "replication replicate operation didn't return 200 OK")
387
+ require.NotNil(t, resp.Payload)
388
+ require.NotNil(t, resp.Payload.ID)
389
+ require.NotEmpty(t, *resp.Payload.ID)
390
+ uuid = *resp.Payload.ID
391
+ }
392
+ }
393
+ })
394
+
395
+ // If didn't find needed info fail now
396
+ if sourceNode == -1 || targetNode == "" || targetNodeURI == "" || uuid.String() == "" {
397
+ t.FailNow()
398
+ }
399
+
400
+ // Wait for the replication to finish
401
+ t.Run("waiting for replication to finish", func(t *testing.T) {
402
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
403
+ details, err := helper.Client(t).Replication.ReplicationDetails(
404
+ replication.NewReplicationDetailsParams().WithID(uuid), nil,
405
+ )
406
+ assert.Nil(t, err, "failed to get replication details %s", err)
407
+ assert.NotNil(t, details, "expected replication details to be not nil")
408
+ assert.NotNil(t, details.Payload, "expected replication details payload to be not nil")
409
+ assert.NotNil(t, details.Payload.Status, "expected replication status to be not nil")
410
+ assert.Equal(ct, "READY", details.Payload.Status.State, "expected replication status to be READY")
411
+ }, 240*time.Second, 1*time.Second, "replication operation %s not finished in time", uuid)
412
+ })
413
+
414
+ // Kills the original node with the data to ensure we have only one replica available (the new one)
415
+ t.Run(fmt.Sprintf("stop node %d", sourceNode), func(t *testing.T) {
416
+ common.StopNodeAt(ctx, t, compose, sourceNode)
417
+ })
418
+
419
+ t.Run("assert data is available for paragraph on node3 with consistency level one", func(t *testing.T) {
420
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
421
+ for _, objId := range paragraphIDs {
422
+ obj, err := common.GetTenantObjectFromNode(t, targetNodeURI, paragraphClass.Class, objId, targetNode, "tenant0")
423
+ assert.Nil(ct, err)
424
+ assert.NotNil(ct, obj)
425
+ }
426
+ }, 10*time.Second, 1*time.Second, "node3 doesn't have paragraph data")
427
+ })
428
+
429
+ t.Run("assert that async replication is not running in any of the nodes", func(t *testing.T) {
430
+ nodes, err := helper.Client(t).Nodes.
431
+ NodesGetClass(nodes.NewNodesGetClassParams().WithClassName(paragraphClass.Class), nil)
432
+ require.Nil(t, err)
433
+ for _, node := range nodes.Payload.Nodes {
434
+ for _, shard := range node.Shards {
435
+ require.Len(t, shard.AsyncReplicationStatus, 0)
436
+ }
437
+ }
438
+ })
439
+ }
440
+
441
+ // TODO fix flake and uncomment
442
+ // func (suite *ReplicationTestSuite) TestReplicaMovementTenantParallelWrites() {
443
+ // t := suite.T()
444
+ // mainCtx := context.Background()
445
+ // logger, _ := logrustest.NewNullLogger()
446
+
447
+ // clusterSize := 3
448
+ // compose, err := docker.New().
449
+ // WithWeaviateCluster(clusterSize).
450
+ // WithText2VecContextionary().
451
+ // WithWeaviateEnv("REPLICA_MOVEMENT_MINIMUM_ASYNC_WAIT", "10s").
452
+ // Start(mainCtx)
453
+ // require.Nil(t, err)
454
+ // defer func() {
455
+ // if err := compose.Terminate(mainCtx); err != nil {
456
+ // t.Fatalf("failed to terminate test containers: %s", err.Error())
457
+ // }
458
+ // }()
459
+
460
+ // _, cancel := context.WithTimeout(mainCtx, 5*time.Minute)
461
+ // defer cancel()
462
+
463
+ // helper.SetupClient(compose.GetWeaviate().URI())
464
+ // paragraphClass := articles.ParagraphsClass()
465
+ // articleClass := articles.ArticlesClass()
466
+
467
+ // t.Run("create schema", func(t *testing.T) {
468
+ // paragraphClass.ReplicationConfig = &models.ReplicationConfig{
469
+ // Factor: 2,
470
+ // AsyncEnabled: false,
471
+ // }
472
+ // paragraphClass.MultiTenancyConfig = &models.MultiTenancyConfig{
473
+ // Enabled: true,
474
+ // AutoTenantActivation: true,
475
+ // AutoTenantCreation: true,
476
+ // }
477
+ // paragraphClass.Vectorizer = "text2vec-contextionary"
478
+ // helper.CreateClass(t, paragraphClass)
479
+ // articleClass.ReplicationConfig = &models.ReplicationConfig{
480
+ // Factor: 2,
481
+ // AsyncEnabled: false,
482
+ // }
483
+ // articleClass.MultiTenancyConfig = &models.MultiTenancyConfig{
484
+ // Enabled: true,
485
+ // AutoTenantActivation: true,
486
+ // AutoTenantCreation: true,
487
+ // }
488
+ // helper.CreateClass(t, articleClass)
489
+ // })
490
+
491
+ // t.Run("insert initial paragraphs", func(t *testing.T) {
492
+ // batch := make([]*models.Object, len(paragraphIDs))
493
+ // for i, id := range paragraphIDs {
494
+ // batch[i] = articles.NewParagraph().
495
+ // WithID(id).
496
+ // WithContents(fmt.Sprintf("paragraph#%d", i)).
497
+ // WithTenant("tenant0").
498
+ // Object()
499
+ // }
500
+ // common.CreateObjects(t, compose.GetWeaviate().URI(), batch)
501
+ // })
502
+
503
+ // parallelWriteWg := sync.WaitGroup{}
504
+ // parallelWriteIDs := []string{}
505
+ // replicationDone := make(chan struct{})
506
+ // t.Run("start parallel writes", func(t *testing.T) {
507
+ // parallelWriteWg.Add(1)
508
+ // enterrors.GoWrapper(func() {
509
+ // defer parallelWriteWg.Done()
510
+ // containerId := 1
511
+ // for {
512
+ // select {
513
+ // case <-replicationDone:
514
+ // return
515
+ // default:
516
+ // newWriteId := uuid.New().String()
517
+ // err = createObjectThreadSafe(
518
+ // compose.ContainerURI(containerId),
519
+ // paragraphClass.Class,
520
+ // map[string]interface{}{
521
+ // "contents": fmt.Sprintf("paragraph#%d", len(paragraphIDs)+len(parallelWriteIDs)),
522
+ // },
523
+ // newWriteId,
524
+ // "tenant0",
525
+ // )
526
+ // assert.NoError(t, err, "error creating object on node with id %d", containerId)
527
+ // parallelWriteIDs = append(parallelWriteIDs, newWriteId)
528
+ // containerId++
529
+ // if containerId >= clusterSize+1 {
530
+ // containerId = 1
531
+ // }
532
+ // }
533
+ // }
534
+ // }, logger)
535
+ // })
536
+
537
+ // // any node can be chosen as the tenant source node (even if that node is down at the time of creation)
538
+ // // so we dynamically find the source and target nodes
539
+ // var opUuid strfmt.UUID
540
+ // var shardName string
541
+ // type nodeInfo struct {
542
+ // nodeContainerIndex int
543
+ // nodeURI string
544
+ // nodeName string
545
+ // }
546
+ // sourceNode := nodeInfo{}
547
+ // targetNode := nodeInfo{}
548
+ // replicaNode := nodeInfo{}
549
+ // allNodeInfos := []nodeInfo{}
550
+ // // TODO test copy as well
551
+ // transferType := api.MOVE.String()
552
+ // t.Run("start replica replication to node3 for paragraph", func(t *testing.T) {
553
+ // verbose := verbosity.OutputVerbose
554
+ // params := nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class)
555
+ // body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
556
+ // require.NoError(t, clientErr)
557
+ // require.NotNil(t, body.Payload)
558
+
559
+ // hasFoundNode := false
560
+ // hasFoundShard := false
561
+
562
+ // // Find two source nodes that have shards
563
+ // for i, node := range body.Payload.Nodes {
564
+ // containerIndex := i + 1
565
+ // allNodeInfos = append(allNodeInfos, nodeInfo{nodeURI: compose.ContainerURI(containerIndex), nodeName: node.Name, nodeContainerIndex: containerIndex})
566
+ // if len(node.Shards) >= 1 {
567
+ // hasFoundNode = true
568
+ // for _, shard := range node.Shards {
569
+ // if shard.Class != paragraphClass.Class {
570
+ // continue
571
+ // }
572
+ // hasFoundShard = true
573
+ // shardName = shard.Name
574
+ // // i + 1 because stop/start routine are 1 based not 0
575
+ // if sourceNode.nodeName == "" {
576
+ // sourceNode = nodeInfo{nodeURI: compose.ContainerURI(containerIndex), nodeName: node.Name, nodeContainerIndex: containerIndex}
577
+ // } else {
578
+ // replicaNode = nodeInfo{nodeURI: compose.ContainerURI(containerIndex), nodeName: node.Name, nodeContainerIndex: containerIndex}
579
+ // }
580
+ // }
581
+ // }
582
+ // }
583
+
584
+ // require.True(t, hasFoundShard, "could not find shard for class %s", paragraphClass.Class)
585
+ // require.True(t, hasFoundNode, "could not find node with shards for paragraph")
586
+ // require.NotEmpty(t, sourceNode.nodeName, "could not find two source nodes with shards for paragraph")
587
+ // require.NotEmpty(t, sourceNode.nodeURI, "could not find two source nodes with shards for paragraph")
588
+ // require.NotEmpty(t, replicaNode.nodeName, "could not find two source nodes with shards for paragraph")
589
+ // require.NotEmpty(t, replicaNode.nodeURI, "could not find two source nodes with shards for paragraph")
590
+ // require.NotEqual(t, sourceNode.nodeName, replicaNode.nodeName, "source and replica nodes are the same")
591
+ // require.NotEqual(t, sourceNode.nodeURI, replicaNode.nodeURI, "source and replica nodes are the same")
592
+
593
+ // // Choose a target node that is not one of the source nodes
594
+ // for i, node := range body.Payload.Nodes {
595
+ // if node.Name == sourceNode.nodeName || node.Name == replicaNode.nodeName {
596
+ // continue
597
+ // }
598
+ // targetNode = nodeInfo{nodeURI: compose.ContainerURI(i + 1), nodeName: node.Name}
599
+ // break
600
+ // }
601
+
602
+ // require.NotEmpty(t, targetNode, "could not find a target node different from the source nodes")
603
+
604
+ // t.Logf("Starting replica replication from %s to %s for shard %s", sourceNode.nodeName, targetNode.nodeName, shardName)
605
+ // resp, err := helper.Client(t).Replication.Replicate(
606
+ // replication.NewReplicateParams().WithBody(
607
+ // &models.ReplicationReplicateReplicaRequest{
608
+ // CollectionID: &paragraphClass.Class,
609
+ // SourceNodeName: &sourceNode.nodeName,
610
+ // DestinationNodeName: &targetNode.nodeName,
611
+ // ShardID: &shardName,
612
+ // TransferType: &transferType,
613
+ // },
614
+ // ),
615
+ // nil,
616
+ // )
617
+ // require.NoError(t, err)
618
+ // require.Equal(t, http.StatusOK, resp.Code(), "replication replicate operation didn't return 200 OK")
619
+ // require.NotNil(t, resp.Payload)
620
+ // require.NotNil(t, resp.Payload.ID)
621
+ // require.NotEmpty(t, *resp.Payload.ID)
622
+ // opUuid = *resp.Payload.ID
623
+ // })
624
+
625
+ // require.NotEmpty(t, opUuid, "opUuid is empty")
626
+ // require.NotEmpty(t, sourceNode.nodeName, "sourceNode is empty")
627
+ // require.NotEmpty(t, sourceNode.nodeURI, "sourceNode is empty")
628
+ // require.NotEmpty(t, targetNode.nodeName, "targetNode is empty")
629
+ // require.NotEmpty(t, targetNode.nodeURI, "targetNode is empty")
630
+ // require.NotEmpty(t, replicaNode.nodeName, "replicaNode is empty")
631
+ // require.NotEmpty(t, replicaNode.nodeURI, "replicaNode is empty")
632
+ // require.NotEqual(t, sourceNode.nodeName, replicaNode.nodeName, "source and replica nodes are the same")
633
+ // require.NotEqual(t, sourceNode.nodeURI, replicaNode.nodeURI, "source and replica nodes are the same")
634
+ // require.NotEqual(t, targetNode.nodeName, sourceNode.nodeName, "target and source nodes are the same")
635
+ // require.NotEqual(t, targetNode.nodeURI, sourceNode.nodeURI, "target and source nodes are the same")
636
+ // require.NotEqual(t, targetNode.nodeName, replicaNode.nodeName, "target and replica nodes are the same")
637
+ // require.NotEqual(t, targetNode.nodeURI, replicaNode.nodeURI, "target and replica nodes are the same")
638
+
639
+ // // Wait for the replication to finish
640
+ // t.Run("waiting for replication to finish", func(t *testing.T) {
641
+ // assert.EventuallyWithT(t, func(ct *assert.CollectT) {
642
+ // details, err := helper.Client(t).Replication.ReplicationDetails(
643
+ // replication.NewReplicationDetailsParams().WithID(opUuid), nil,
644
+ // )
645
+ // assert.Nil(t, err, "failed to get replication details %s", err)
646
+ // assert.NotNil(t, details, "expected replication details to be not nil")
647
+ // assert.NotNil(t, details.Payload, "expected replication details payload to be not nil")
648
+ // assert.NotNil(t, details.Payload.Status, "expected replication status to be not nil")
649
+ // assert.Equal(ct, "READY", details.Payload.Status.State, "expected replication status to be READY")
650
+ // }, 240*time.Second, 1*time.Second, "replication operation %s not finished in time", opUuid)
651
+ // // let some writes keep going for a few seconds after the op is ready
652
+ // time.Sleep(5 * time.Second)
653
+ // // now stop the writes
654
+ // close(replicationDone)
655
+ // parallelWriteWg.Wait()
656
+ // })
657
+
658
+ // t.Run("all parallel writes are available", func(t *testing.T) {
659
+ // numParallelWrites := len(parallelWriteIDs)
660
+ // assert.True(t, numParallelWrites > 1000, "expected at least 1000 parallel writes")
661
+ // for _, nodeInfo := range allNodeInfos {
662
+ // // in a move, sourceNode no longer has the shard replica, so we skip it
663
+ // if transferType == api.MOVE.String() && nodeInfo.nodeName == sourceNode.nodeName {
664
+ // continue
665
+ // }
666
+
667
+ // assert.Equal(t, int64(numParallelWrites+len(paragraphIDs)), common.CountTenantObjects(t, nodeInfo.nodeURI, paragraphClass.Class, "tenant0"), fmt.Sprintf("expected %d objects on node %s", numParallelWrites+len(paragraphIDs), nodeInfo.nodeName))
668
+ // }
669
+ // for _, nodeInfo := range allNodeInfos {
670
+ // firstMissingObjectForNode := ""
671
+ // numMissingObjectsForNode := 0
672
+ // for _, id := range parallelWriteIDs {
673
+ // // in a move, sourceNode no longer has the shard replica, so we skip it
674
+ // if transferType == api.MOVE.String() && nodeInfo.nodeName == sourceNode.nodeName {
675
+ // continue
676
+ // }
677
+
678
+ // obj, err := common.GetTenantObjectFromNode(t, nodeInfo.nodeURI, paragraphClass.Class, strfmt.UUID(id), nodeInfo.nodeName, "tenant0")
679
+ // if err != nil || obj == nil {
680
+ // numMissingObjectsForNode++
681
+ // if firstMissingObjectForNode == "" {
682
+ // assert.Nil(t, err, "error getting object from node %s", nodeInfo.nodeName, id, err)
683
+ // assert.NotNil(t, obj, "object not found on node", nodeInfo.nodeName, id)
684
+ // firstMissingObjectForNode = id
685
+ // }
686
+ // }
687
+ // }
688
+ // assert.Equal(t, 0, numMissingObjectsForNode, "expected no missing objects on node %s", nodeInfo.nodeName)
689
+ // assert.Empty(t, firstMissingObjectForNode, "expected no missing objects on node %s", nodeInfo.nodeName)
690
+ // }
691
+ // })
692
+
693
+ // t.Run("assert data is available for paragraph on node3 with consistency level one", func(t *testing.T) {
694
+ // assert.EventuallyWithT(t, func(ct *assert.CollectT) {
695
+ // for _, objId := range paragraphIDs {
696
+ // obj, err := common.GetTenantObjectFromNode(t, targetNode.nodeURI, paragraphClass.Class, objId, targetNode.nodeName, "tenant0")
697
+ // assert.Nil(ct, err)
698
+ // assert.NotNil(ct, obj)
699
+ // }
700
+ // }, 10*time.Second, 1*time.Second, "node3 doesn't have paragraph data")
701
+ // })
702
+ // }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/large_shard_test.go ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package slow
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "time"
18
+
19
+ "github.com/stretchr/testify/assert"
20
+ "github.com/stretchr/testify/require"
21
+ "github.com/weaviate/weaviate/client/replication"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+ "github.com/weaviate/weaviate/test/docker"
24
+ "github.com/weaviate/weaviate/test/helper"
25
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
26
+ )
27
+
28
+ func (suite *ReplicationTestSuite) TestReplicationReplicateOfLargeShard() {
29
+ t := suite.T()
30
+ mainCtx := context.Background()
31
+
32
+ compose, err := docker.New().
33
+ WithWeaviateCluster(3).
34
+ Start(mainCtx)
35
+ require.Nil(t, err)
36
+ defer func() {
37
+ if err := compose.Terminate(mainCtx); err != nil {
38
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
39
+ }
40
+ }()
41
+
42
+ helper.SetupClient(compose.GetWeaviate().URI())
43
+
44
+ cls := articles.ParagraphsClass()
45
+ cls.ReplicationConfig = &models.ReplicationConfig{
46
+ Factor: 1,
47
+ }
48
+ cls.MultiTenancyConfig = &models.MultiTenancyConfig{
49
+ Enabled: true,
50
+ AutoTenantActivation: true,
51
+ AutoTenantCreation: true,
52
+ }
53
+
54
+ // Create the class
55
+ t.Log("Creating class", cls.Class)
56
+ helper.DeleteClass(t, cls.Class)
57
+ helper.CreateClass(t, cls)
58
+
59
+ // Load data
60
+ t.Log("Loading data into tenant...")
61
+ tenantName := "tenant"
62
+ batch := make([]*models.Object, 0, 100000)
63
+ start := time.Now()
64
+ for j := 0; j < 1000000; j++ {
65
+ batch = append(batch, (*models.Object)(articles.NewParagraph().
66
+ WithContents(fmt.Sprintf("paragraph#%d", j)).
67
+ WithTenant(tenantName).
68
+ Object()))
69
+ if len(batch) == 50000 {
70
+ helper.CreateObjectsBatch(t, batch)
71
+ t.Logf("Loaded %d objects", len(batch))
72
+ batch = batch[:0]
73
+ }
74
+ }
75
+ if len(batch) > 0 {
76
+ helper.CreateObjectsBatch(t, batch)
77
+ t.Logf("Loaded remaining %d objects", len(batch))
78
+ }
79
+ t.Logf("Data loading took %s", time.Since(start))
80
+
81
+ nodes, err := helper.Client(t).Nodes.NodesGet(nil, nil)
82
+ require.Nil(t, err)
83
+
84
+ nodeNames := make([]string, len(nodes.GetPayload().Nodes))
85
+ for i, node := range nodes.GetPayload().Nodes {
86
+ nodeNames[i] = node.Name
87
+ }
88
+
89
+ // Find node with shard
90
+ shardingState, err := helper.Client(t).Replication.GetCollectionShardingState(
91
+ replication.NewGetCollectionShardingStateParams().WithCollection(&cls.Class), nil,
92
+ )
93
+ require.Nil(t, err)
94
+ require.Len(t, shardingState.GetPayload().ShardingState.Shards, 1)
95
+
96
+ sourceNode := shardingState.GetPayload().ShardingState.Shards[0].Replicas[0]
97
+
98
+ targetNode := ""
99
+ for _, node := range nodeNames {
100
+ if node != sourceNode {
101
+ targetNode = node
102
+ break
103
+ }
104
+ }
105
+
106
+ move := models.ReplicationReplicateReplicaRequestTypeMOVE
107
+ t.Logf("Replicating from %s to %s", sourceNode, targetNode)
108
+ // Replicate the shard
109
+ res, err := helper.Client(t).Replication.Replicate(
110
+ replication.NewReplicateParams().
111
+ WithBody(&models.ReplicationReplicateReplicaRequest{
112
+ SourceNode: &sourceNode,
113
+ TargetNode: &targetNode,
114
+ Collection: &cls.Class,
115
+ Shard: &shardingState.GetPayload().ShardingState.Shards[0].Shard,
116
+ Type: &move,
117
+ }), nil,
118
+ )
119
+ require.Nil(t, err)
120
+ id := *res.GetPayload().ID
121
+
122
+ t.Logf("Replication started with ID: %s", id)
123
+ // Wait for replication to finish
124
+ t.Log("Waiting for replication to finish...")
125
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
126
+ status, err := helper.Client(t).Replication.ReplicationDetails(replication.NewReplicationDetailsParams().WithID(id), nil)
127
+ require.Nil(t, err)
128
+ require.Equal(ct, "READY", status.Payload.Status.State)
129
+ }, 180*time.Second, 100*time.Millisecond, "Replication operation should be in READY state")
130
+
131
+ t.Log("Replication completed successfully")
132
+ // Verify that the target node has the shard
133
+ shardingState, err = helper.Client(t).Replication.GetCollectionShardingState(
134
+ replication.NewGetCollectionShardingStateParams().WithCollection(&cls.Class), nil,
135
+ )
136
+ require.Nil(t, err)
137
+ require.Len(t, shardingState.GetPayload().ShardingState.Shards, 1)
138
+ require.Equal(t, targetNode, shardingState.GetPayload().ShardingState.Shards[0].Replicas[0])
139
+ }
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/scale_out_test.go ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package slow
13
+
14
+ import (
15
+ "context"
16
+ "encoding/json"
17
+ "fmt"
18
+ "time"
19
+
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ "github.com/weaviate/weaviate/client/graphql"
23
+ "github.com/weaviate/weaviate/client/nodes"
24
+ "github.com/weaviate/weaviate/client/replication"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/test/docker"
27
+ "github.com/weaviate/weaviate/test/helper"
28
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
29
+ )
30
+
31
+ type movement struct {
32
+ source string
33
+ target string
34
+ shard string
35
+ }
36
+
37
+ func (suite *ReplicationTestSuite) TestReplicationReplicateScaleOut() {
38
+ t := suite.T()
39
+ mainCtx := context.Background()
40
+
41
+ compose, err := docker.New().
42
+ WithWeaviateCluster(3).
43
+ WithWeaviateEnv("REPLICATION_ENGINE_MAX_WORKERS", "10").
44
+ Start(mainCtx)
45
+ require.Nil(t, err)
46
+ defer func() {
47
+ if err := compose.Terminate(mainCtx); err != nil {
48
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
49
+ }
50
+ }()
51
+
52
+ helper.SetupClient(compose.GetWeaviate().URI())
53
+
54
+ cls := articles.ParagraphsClass()
55
+ cls.MultiTenancyConfig = &models.MultiTenancyConfig{
56
+ Enabled: true,
57
+ AutoTenantActivation: true,
58
+ AutoTenantCreation: true,
59
+ }
60
+ cls.ReplicationConfig = &models.ReplicationConfig{
61
+ Factor: 1,
62
+ }
63
+
64
+ // Create the class
65
+ helper.DeleteClass(t, cls.Class)
66
+ helper.CreateClass(t, cls)
67
+
68
+ // Load data
69
+ batch := make([]*models.Object, 0, 10000)
70
+ tenantNames := make([]string, 0, 100)
71
+ t.Log("Loading data into tenants...")
72
+ for i := 0; i < 100; i++ {
73
+ tenantName := fmt.Sprintf("tenant-%d", i)
74
+ tenantNames = append(tenantNames, tenantName)
75
+ for j := 0; j < 1000; j++ {
76
+ batch = append(batch, (*models.Object)(articles.NewParagraph().
77
+ WithContents(fmt.Sprintf("paragraph#%d", j)).
78
+ WithTenant(tenantName).
79
+ Object()))
80
+ }
81
+ if len(batch) == 10000 {
82
+ helper.CreateObjectsBatch(t, batch)
83
+ batch = batch[:0] // reset batch for next iteration
84
+ }
85
+ }
86
+ if len(batch) > 0 {
87
+ helper.CreateObjectsBatch(t, batch)
88
+ }
89
+
90
+ ns, err := helper.Client(t).Nodes.NodesGet(
91
+ nodes.NewNodesGetParams(), nil,
92
+ )
93
+ require.Nil(t, err)
94
+ nodeNames := make([]string, 0, len(ns.Payload.Nodes))
95
+ for _, node := range ns.Payload.Nodes {
96
+ nodeNames = append(nodeNames, node.Name)
97
+ }
98
+ require.Len(t, nodeNames, 3)
99
+
100
+ shardingState, err := helper.Client(t).Replication.GetCollectionShardingState(
101
+ replication.NewGetCollectionShardingStateParams().WithCollection(&cls.Class), nil,
102
+ )
103
+ require.Nil(t, err)
104
+ require.Len(t, shardingState.Payload.ShardingState.Shards, 100)
105
+
106
+ movements := []movement{}
107
+ for _, state := range shardingState.Payload.ShardingState.Shards {
108
+ replica := state.Replicas[0]
109
+ for _, node := range nodeNames {
110
+ if node == replica {
111
+ continue
112
+ }
113
+ movements = append(movements, movement{
114
+ source: replica,
115
+ target: node,
116
+ shard: state.Shard,
117
+ })
118
+ }
119
+ }
120
+
121
+ t.Logf("Running %d scale out operations", len(movements))
122
+
123
+ for _, movement := range movements {
124
+ _, err = helper.Client(t).Replication.Replicate(
125
+ replication.NewReplicateParams().WithBody(&models.ReplicationReplicateReplicaRequest{
126
+ SourceNode: &movement.source,
127
+ TargetNode: &movement.target,
128
+ Shard: &movement.shard,
129
+ Collection: &cls.Class,
130
+ }),
131
+ nil,
132
+ )
133
+ require.Nil(t, err, "failed to start replication from %s to %s for shard %s", movement.source, movement.target, movement.shard)
134
+ time.Sleep(10 * time.Millisecond) // Give some time to avoid overwhelming the server with requests
135
+ }
136
+ require.Nil(t, err, "failed to start batch replications")
137
+
138
+ // Wait until all ops are in the READY state
139
+ t.Log("Waiting for all replication operations to be in READY state...")
140
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
141
+ t.Log("Not all ops are in READY state, checking again...")
142
+ ops, err := helper.Client(t).Replication.ListReplication(
143
+ replication.NewListReplicationParams().WithCollection(&cls.Class), nil,
144
+ )
145
+ require.Nil(ct, err, "failed to list replication operations")
146
+ for _, op := range ops.Payload {
147
+ assert.Equal(ct, "READY", op.Status.State, "replication operation should be in READY state")
148
+ }
149
+ }, 10*time.Minute, 1*time.Second, "not all replication operations are in READY state")
150
+
151
+ // Assert that data is the same on each node
152
+ nodeToAddress := map[string]string{}
153
+ for idx, node := range ns.Payload.Nodes {
154
+ nodeToAddress[node.Name] = compose.GetWeaviateNode(idx + 1).URI()
155
+ }
156
+
157
+ objectCountByReplica := map[string]map[string]int64{}
158
+ for _, node := range nodeNames {
159
+ objectCountByReplica[node] = make(map[string]int64)
160
+ }
161
+ for _, tenantName := range tenantNames {
162
+ for node, address := range nodeToAddress {
163
+ helper.SetupClient(address)
164
+ res, err := helper.Client(t).Graphql.GraphqlPost(graphql.NewGraphqlPostParams().WithBody(&models.GraphQLQuery{
165
+ Query: fmt.Sprintf(`{ Aggregate { %s(tenant: "%s") { meta { count } } } }`, cls.Class, tenantName),
166
+ }), nil)
167
+ require.Nil(t, err, "failed to get object count for tenant %s on node %s", tenantName, node)
168
+ val, err := res.Payload.Data["Aggregate"].(map[string]any)["Paragraph"].([]any)[0].(map[string]any)["meta"].(map[string]any)["count"].(json.Number).Int64()
169
+ require.Nil(t, err, "failed to parse object count for tenant %s on node %s", tenantName, node)
170
+ objectCountByReplica[node][tenantName] = val
171
+ }
172
+ }
173
+
174
+ // Verify that all replicas have the same number of objects
175
+ t.Log("Verifying object counts across replicas")
176
+ var expectedCount int64
177
+ var comparisonReplica string
178
+ for _, tenantName := range tenantNames {
179
+ for replica, count := range objectCountByReplica {
180
+ actualCount, ok := count[tenantName]
181
+ require.True(t, ok, "object count for tenant %s not found on replica %s", tenantName, replica)
182
+ if expectedCount == 0 {
183
+ expectedCount = actualCount
184
+ comparisonReplica = replica
185
+ } else {
186
+ require.Equal(t, expectedCount, actualCount, "object counts across replicas do not match. Expected %d as on %s but got %d for replica %s instead", expectedCount, comparisonReplica, actualCount, replica)
187
+ }
188
+ }
189
+ }
190
+ }