aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java
blob: 36fde656dfa14321190da3d7cc391c738c1d7dcf (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content;

import com.yahoo.vespa.config.content.core.StorIntegritycheckerConfig;
import com.yahoo.vespa.config.content.core.StorVisitorConfig;
import com.yahoo.vespa.config.content.StorFilestorConfig;
import com.yahoo.vespa.config.content.core.StorServerConfig;
import com.yahoo.vespa.config.content.PersistenceConfig;
import com.yahoo.vespa.config.storage.StorDevicesConfig;
import com.yahoo.config.model.test.MockRoot;
import com.yahoo.documentmodel.NewDocumentType;
import com.yahoo.text.XML;
import com.yahoo.vespa.defaults.Defaults;
import com.yahoo.vespa.model.content.cluster.ContentCluster;
import com.yahoo.vespa.model.content.storagecluster.StorageCluster;
import com.yahoo.vespa.model.content.utils.ContentClusterUtils;
import org.junit.Test;
import org.w3c.dom.Document;

import java.util.Collections;

import static org.junit.Assert.*;

public class StorageClusterTest {

    StorageCluster parse(String xml) throws Exception {
        MockRoot root = new MockRoot();
        root.getDeployState().getDocumentModel().getDocumentManager().add(
                new NewDocumentType(new NewDocumentType.Name("music"))
        );
        root.getDeployState().getDocumentModel().getDocumentManager().add(
                new NewDocumentType(new NewDocumentType.Name("movies"))
        );
        ContentCluster cluster = ContentClusterUtils.createCluster(xml, root);

        root.freezeModelTopology();
        return cluster.getStorageNodes();
    }

    @Test
    public void testBasics() throws Exception {
        StorServerConfig.Builder builder = new StorServerConfig.Builder();
        parse("<content id=\"foofighters\"><documents/>\n" +
              "  <group>" +
              "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
              "  </group>" +
              "</content>\n").
              getConfig(builder);

        StorServerConfig config = new StorServerConfig(builder);
        assertEquals(false, config.is_distributor());
        assertEquals("foofighters", config.cluster_name());
    }

    @Test
    public void testMerges() throws Exception {
        StorServerConfig.Builder builder = new StorServerConfig.Builder();
        parse("" +
                "<content id=\"foofighters\">\n" +
                "  <documents/>" +
                "  <tuning>" +
                "    <merges max-per-node=\"1K\" max-queue-size=\"10K\"/>\n" +
                "  </tuning>" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</content>"
        ).getConfig(builder);

        StorServerConfig config = new StorServerConfig(builder);
        assertEquals(1024, config.max_merges_per_node());
        assertEquals(1024*10, config.max_merge_queue_size());
    }

    @Test
    public void testVisitors() throws Exception {
        StorVisitorConfig.Builder builder = new StorVisitorConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                "  <documents/>" +
                "  <tuning>\n" +
                "    <visitors thread-count=\"7\" max-queue-size=\"1000\">\n" +
                "      <max-concurrent fixed=\"42\" variable=\"100\"/>\n" +
                "    </visitors>\n" +
                "  </tuning>\n" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>"
        ).getConfig(builder);

        StorVisitorConfig config = new StorVisitorConfig(builder);
        assertEquals(42, config.maxconcurrentvisitors_fixed());
        assertEquals(100, config.maxconcurrentvisitors_variable());
        assertEquals(7, config.visitorthreads());
        assertEquals(1000, config.maxvisitorqueuesize());
    }

    @Test
    public void testPersistenceThreads() throws Exception {
        StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                "    <documents/>" +
                "    <engine>" +
                 "     <vds/>" +
                "    </engine>" +
                "    <tuning>\n" +
                "        <persistence-threads>\n" +
                "            <thread lowest-priority=\"VERY_LOW\" count=\"2\"/>\n" +
                "            <thread lowest-priority=\"VERY_HIGH\" count=\"1\"/>\n" +
                "            <thread count=\"1\"/>\n" +
                "        </persistence-threads>\n" +
                "    </tuning>\n" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>"
        ).getConfig(builder);

        StorFilestorConfig config = new StorFilestorConfig(builder);

        assertEquals(4, config.threads().size());
        assertEquals(190, config.threads().get(0).lowestpri());
        assertEquals(190, config.threads().get(1).lowestpri());
        assertEquals(60, config.threads().get(2).lowestpri());
        assertEquals(255, config.threads().get(3).lowestpri());

        assertEquals(true, config.enable_multibit_split_optimalization());
    }

    @Test
    public void testNoPersistenceThreads() throws Exception {
        StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                        "    <documents/>" +
                        "    <tuning>\n" +
                        "    </tuning>\n" +
                        "  <group>" +
                        "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                        "  </group>" +
                        "</cluster>"
        ).getConfig(builder);

        StorFilestorConfig config = new StorFilestorConfig(builder);

        assertEquals(0, config.threads().size());
    }

    @Test
    public void maintenance_tuning_is_honored_for_vds_provider() throws Exception {
        StorIntegritycheckerConfig.Builder builder = new StorIntegritycheckerConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                "  <documents/>" +
                "  <engine>\n" +
                "    <vds/>\n" +
                "  </engine>\n" +
                "  <tuning>" +
                "    <maintenance start=\"01:00\" stop=\"02:00\" high=\"tuesday\"/>\n" +
                "  </tuning>" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>"
             ).getConfig(builder);
        StorIntegritycheckerConfig config = new StorIntegritycheckerConfig(builder);

        assertEquals(60, config.dailycyclestart());
        assertEquals(120, config.dailycyclestop());
        assertEquals("rrRrrrr", config.weeklycycle());
    }

    @Test
    public void integrity_checker_explicitly_disabled_when_not_running_with_vds_provider() throws Exception {
        StorIntegritycheckerConfig.Builder builder = new StorIntegritycheckerConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                "  <documents/>" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>"
        ).getConfig(builder);
        StorIntegritycheckerConfig config = new StorIntegritycheckerConfig(builder);
        // '-' --> don't run on the given week day
        assertEquals("-------", config.weeklycycle());
    }

    @Test
    public void integrity_checker_not_explicitly_disabled_when_running_with_vds_provider() throws Exception {
        StorIntegritycheckerConfig.Builder builder = new StorIntegritycheckerConfig.Builder();
        parse(
                "<cluster id=\"bees\">\n" +
                "  <documents/>" +
                "  <engine>\n" +
                "    <vds/>\n" +
                "  </engine>\n" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>"
        ).getConfig(builder);
        StorIntegritycheckerConfig config = new StorIntegritycheckerConfig(builder);
        // No tuning element has been provided, but we should still get a default weeklycycle
        // config generated since we're on VDS.
        assertEquals("Rrrrrrr", config.weeklycycle());
    }

    @Test
    public void testCapacity() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                        "  <documents/>" +
                        "  <group>\n" +
                        "    <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                        "    <node distribution-key=\"1\" hostalias=\"mockhost\" capacity=\"1.5\"/>\n" +
                        "    <node distribution-key=\"2\" hostalias=\"mockhost\" capacity=\"2.0\"/>\n" +
                        "  </group>\n" +
                        "</cluster>";

        ContentCluster cluster = ContentClusterUtils.createCluster(xml, new MockRoot());

        for (int i = 0; i < 3; ++i) {
            StorageNode node = cluster.getStorageNodes().getChildren().get("" + i);
            StorServerConfig.Builder builder = new StorServerConfig.Builder();
            cluster.getStorageNodes().getConfig(builder);
            node.getConfig(builder);
            StorServerConfig config = new StorServerConfig(builder);
            assertEquals(1.0 + (double)i * 0.5, config.node_capacity(), 0.001);
        }
    }

    @Test
    public void testRootFolder() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                        "  <documents/>" +
                        "  <group>\n" +
                        "    <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                        "  </group>\n" +
                        "</cluster>";

        ContentCluster cluster = ContentClusterUtils.createCluster(xml, new MockRoot());

        StorageNode node = cluster.getStorageNodes().getChildren().get("0");

        {
            StorDevicesConfig.Builder builder = new StorDevicesConfig.Builder();
            node.getConfig(builder);
            StorDevicesConfig config = new StorDevicesConfig(builder);
            assertEquals(Defaults.getDefaults().vespaHome() + "var/db/vespa/vds/storage/storage/0", config.root_folder());
        }

        {
            StorServerConfig.Builder builder = new StorServerConfig.Builder();
            cluster.getStorageNodes().getConfig(builder);
            node.getConfig(builder);
            StorServerConfig config = new StorServerConfig(builder);
            assertEquals(Defaults.getDefaults().vespaHome() + "var/db/vespa/vds/storage/storage/0", config.root_folder());
        }

        {
            StorServerConfig.Builder builder = new StorServerConfig.Builder();
            cluster.getDistributorNodes().getConfig(builder);
            cluster.getDistributorNodes().getChildren().get("0").getConfig(builder);
            StorServerConfig config = new StorServerConfig(builder);
            assertEquals(Defaults.getDefaults().vespaHome() + "var/db/vespa/vds/storage/distributor/0", config.root_folder());
        }
    }

    @Test
    public void testGenericPersistenceTuning() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                        "<documents/>" +
                        "<engine>\n" +
                        "    <fail-partition-on-error>true</fail-partition-on-error>\n" +
                        "    <revert-time>34m</revert-time>\n" +
                        "    <recovery-time>5d</recovery-time>\n" +
                        "</engine>" +
                        "  <group>\n" +
                        "    <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                        "  </group>\n" +
                        "</cluster>";

        ContentCluster cluster = ContentClusterUtils.createCluster(xml, new MockRoot());

        PersistenceConfig.Builder builder = new PersistenceConfig.Builder();
        cluster.getStorageNodes().getConfig(builder);

        PersistenceConfig config = new PersistenceConfig(builder);
        assertEquals(true, config.fail_partition_on_error());
        assertEquals(34 * 60, config.revert_time_period());
        assertEquals(5 * 24 * 60 * 60, config.keep_remove_time_period());
    }

    @Test
    public void requireThatUserDoesNotSpecifyBothGroupAndNodes() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                        "<documents/>\n" +
                        "<engine>\n" +
                        "    <fail-partition-on-error>true</fail-partition-on-error>\n" +
                        "    <revert-time>34m</revert-time>\n" +
                        "    <recovery-time>5d</recovery-time>\n" +
                        "</engine>" +
                        "  <group>\n" +
                        "    <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                        "  </group>\n" +
                        "  <nodes>\n" +
                        "    <node distribution-key=\"1\" hostalias=\"mockhost\"/>\n" +
                        "  </nodes>\n" +
                        "</cluster>";

        try {
            final MockRoot root = new MockRoot();
            root.getDeployState().getDocumentModel().getDocumentManager().add(
                    new NewDocumentType(new NewDocumentType.Name("music"))
            );
            ContentClusterUtils.createCluster(xml, root);
            fail("Did not fail when having both group and nodes");
        } catch (RuntimeException e) {
            e.printStackTrace();
            assertEquals("Both group and nodes exists, only one of these tags is legal", e.getMessage());
        }
    }

    @Test
    public void requireThatGroupNamesMustBeUniqueAmongstSiblings() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                "<documents/>\n" +
                "  <group>\n" +
                "    <distribution partitions=\"*\"/>\n" +
                "    <group distribution-key=\"0\" name=\"bar\">\n" +
                "      <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                "    </group>\n" +
                "    <group distribution-key=\"0\" name=\"bar\">\n" +
                "      <node distribution-key=\"1\" hostalias=\"mockhost\"/>\n" +
                "    </group>\n" +
                "  </group>\n" +
                "</cluster>";

        try {
            ContentClusterUtils.createCluster(xml, new MockRoot());
            fail("Did not get exception with duplicate group names");
        } catch (RuntimeException e) {
            assertEquals("Cluster 'storage' has multiple groups with name 'bar' in the same subgroup. " +
                         "Group sibling names must be unique.", e.getMessage());
        }
    }

    @Test
    public void requireThatGroupNamesCanBeDuplicatedAcrossLevels() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                "<documents/>\n" +
                "  <group>\n" +
                "    <distribution partitions=\"*\"/>\n" +
                "    <group distribution-key=\"0\" name=\"bar\">\n" +
                "      <group distribution-key=\"0\" name=\"foo\">\n" +
                "        <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                "      </group>\n" +
                "    </group>\n" +
                "    <group distribution-key=\"0\" name=\"foo\">\n" +
                "      <group distribution-key=\"0\" name=\"bar\">\n" +
                "        <node distribution-key=\"1\" hostalias=\"mockhost\"/>\n" +
                "      </group>\n" +
                "    </group>\n" +
                "  </group>\n" +
                "</cluster>";

        // Should not throw.
        ContentClusterUtils.createCluster(xml, new MockRoot());
    }

    @Test
    public void requireThatNestedGroupsRequireDistribution() throws Exception {
        String xml =
                "<cluster id=\"storage\">\n" +
                        "<documents/>\n" +
                        "  <group>\n" +
                        "    <group distribution-key=\"0\" name=\"bar\">\n" +
                        "      <node distribution-key=\"0\" hostalias=\"mockhost\"/>\n" +
                        "    </group>\n" +
                        "    <group distribution-key=\"0\" name=\"baz\">\n" +
                        "      <node distribution-key=\"1\" hostalias=\"mockhost\"/>\n" +
                        "    </group>\n" +
                        "  </group>\n" +
                        "</cluster>";

        try {
            ContentClusterUtils.createCluster(xml, new MockRoot());
            fail("Did not get exception with missing distribution element");
        } catch (RuntimeException e) {
            assertEquals("'distribution' attribute is required with multiple subgroups", e.getMessage());
        }
    }
}