aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/AttributeChangeValidatorTest.java
blob: f3d8eedf90bc2640a8e57e2a29415cf2bedfab99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change.search;

import com.yahoo.config.application.api.ValidationId;
import com.yahoo.config.application.api.ValidationOverrides;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction;
import org.junit.jupiter.api.Test;

import java.util.List;

import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRestartAction;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class AttributeChangeValidatorTest {

    private static class Fixture extends ContentClusterFixture {
        AttributeChangeValidator validator;

        public Fixture(String currentSd, String nextSd) throws Exception {
            super(currentSd, nextSd);
            validator = new AttributeChangeValidator(ClusterSpec.Id.from("test"),
                                                     currentDb().getDerivedConfiguration().getAttributeFields(),
                                                     currentDb().getDerivedConfiguration().getIndexSchema(),
                                                     currentDocType(),
                                                     nextDb().getDerivedConfiguration().getAttributeFields(),
                                                     nextDb().getDerivedConfiguration().getIndexSchema(),
                                                     nextDocType(),
                                                     new DeployState.Builder().build());
        }

        @Override
        public List<VespaConfigChangeAction> validate() {
            return validator.validate();
        }

    }

    @Test
    void adding_attribute_aspect_require_restart() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: summary }",
                "field f1 type string { indexing: attribute | summary }");
        f.assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: add attribute aspect"));
    }

    @Test
    void removing_attribute_aspect_require_restart() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: attribute | summary }",
                "field f1 type string { indexing: summary }");
        f.assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: remove attribute aspect"));
    }

    @Test
    void adding_attribute_field_is_ok() throws Exception {
        Fixture f = new Fixture("", "field f1 type string { indexing: attribute | summary \n attribute: fast-search }");
        f.assertValidation();
    }

    @Test
    void removing_attribute_field_is_ok() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: attribute | summary }", "");
        f.assertValidation();
    }

    @Test
    void changing_fast_search_require_restart() throws Exception {
        new Fixture("field f1 type string { indexing: attribute }",
                "field f1 type string { indexing: attribute \n attribute: fast-search }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: add attribute 'fast-search'"));
    }

    @Test
    void changing_fast_rank_require_restart() throws Exception {
        new Fixture("field f1 type tensor(x{}) { indexing: attribute }",
                "field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-rank }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: add attribute 'fast-rank'"));
    }

    @Test
    void changing_btree2hash_require_restart() throws Exception {
        new Fixture("field f1 type long { indexing: attribute\n attribute: fast-search\n dictionary: btree}",
                "field f1 type long { indexing: attribute\n attribute: fast-search\n dictionary: hash }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property 'dictionary: btree/hash' from 'BTREE' to 'HASH'"));
    }

    @Test
    void changing_hash2btree_require_restart() throws Exception {
        new Fixture("field f1 type long { indexing: attribute\n attribute: fast-search\n dictionary: hash}",
                "field f1 type long { indexing: attribute\n attribute: fast-search\n dictionary: btree }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property 'dictionary: btree/hash' from 'HASH' to 'BTREE'"));
    }

    @Test
    void changing_fast_access_require_restart() throws Exception {
        new Fixture("field f1 type string { indexing: attribute \n attribute: fast-access }",
                "field f1 type string { indexing: attribute }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: remove attribute 'fast-access'"));
    }

    @Test
    void changing_uncased2cased_require_restart() throws Exception {
        new Fixture("field f1 type string { indexing: attribute\n attribute: fast-search\n dictionary { btree\ncased}\nmatch:cased}",
                "field f1 type string { indexing: attribute\n attribute: fast-search\n dictionary{ btree\nuncased}\nmatch:uncased }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property 'dictionary: cased/uncased' from 'CASED' to 'UNCASED'"));
    }

    @Test
    void changing_dense_posting_list_threshold_require_restart() throws Exception {
        new Fixture(
                "field f1 type predicate { indexing: attribute \n index { arity: 8 \n dense-posting-list-threshold: 0.2 } }",
                "field f1 type predicate { indexing: attribute \n index { arity: 8 \n dense-posting-list-threshold: 0.4 } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property 'dense-posting-list-threshold' from '0.2' to '0.4'"));
    }

    @Test
    void removing_attribute_aspect_from_index_field_is_ok() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: index | attribute }",
                "field f1 type string { indexing: index }");
        f.assertValidation();
    }

    @Test
    void removing_attribute_aspect_from_index_and_summary_field_is_ok() throws Exception {
        Fixture f = new Fixture("field f1 type string { indexing: index | attribute | summary }",
                "field f1 type string { indexing: index | summary }");
        f.assertValidation();
    }

    @Test
    void adding_rank_filter_requires_restart() throws Exception {
        new Fixture("field f1 type string { indexing: attribute }",
                "field f1 type string { indexing: attribute \n rank: filter }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: add attribute 'rank: filter'"));
    }

    @Test
    void removing_rank_filter_requires_restart() throws Exception {
        new Fixture("field f1 type string { indexing: attribute \n rank: filter }",
                "field f1 type string { indexing: attribute }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: remove attribute 'rank: filter'"));
    }

    @Test
    void adding_hnsw_index_requires_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute }",
                "field f1 type tensor(x[2]) { indexing: attribute | index \n index { hnsw } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: add attribute 'indexing: index'"));
    }

    @Test
    void removing_hnsw_index_requres_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute | index \n index { hnsw } }",
                "field f1 type tensor(x[2]) { indexing: attribute }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: remove attribute 'indexing: index'"));
    }

    @Test
    void changing_distance_metric_without_hnsw_index_enabled_requires_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute }",
                "field f1 type tensor(x[2]) { indexing: attribute \n attribute { " +
                        "distance-metric: geodegrees \n } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property " +
                        "'distance-metric' from 'EUCLIDEAN' to 'GEODEGREES'"));
    }

    @Test
    void changing_distance_metric_with_hnsw_index_enabled_requires_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute | index \n index { hnsw } }",
                "field f1 type tensor(x[2]) { indexing: attribute | index \n attribute { " +
                        "distance-metric: geodegrees \n } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change property " +
                        "'distance-metric' from 'EUCLIDEAN' to 'GEODEGREES'"));
    }

    @Test
    void changing_hnsw_index_property_max_links_per_node_requires_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute | index \n index { hnsw } }",
                "field f1 type tensor(x[2]) { indexing: attribute | index \n index { " +
                        "hnsw { max-links-per-node: 4 } } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change hnsw index property " +
                        "'max-links-per-node' from '16' to '4'"));
    }

    @Test
    void changing_hnsw_index_property_neighbors_to_explore_at_insert_requires_restart() throws Exception {
        new Fixture("field f1 type tensor(x[2]) { indexing: attribute | index \n index { hnsw } }",
                "field f1 type tensor(x[2]) { indexing: attribute | index \n index { " +
                        "hnsw { neighbors-to-explore-at-insert: 100 } } }").
                assertValidation(newRestartAction(ClusterSpec.Id.from("test"),
                "Field 'f1' changed: change hnsw index property " +
                        "'neighbors-to-explore-at-insert' from '200' to '100'"));
    }

    @Test
    void removing_paged_requires_override() throws Exception {
        try {
            new Fixture("field f1 type tensor(x[10]) { indexing: attribute \n attribute: paged }",
                    "field f1 type tensor(x[10]) { indexing: attribute  }").
                    assertValidation();
            fail("Expected exception on removal of 'paged'");
        }
        catch (ValidationOverrides.ValidationException e) {
            assertTrue(e.getMessage().contains(ValidationId.pagedSettingRemoval.toString()));
        }
    }


}