aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java
blob: 1ac33c4a7e51e830d371d01b8f1317c91bd5ac72 (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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
// Copyright 2017 Yahoo Holdings. 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.config.model.deploy.DeployState;
import com.yahoo.config.model.provision.SingleNodeProvisioner;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.provision.Flavor;
import com.yahoo.config.provisioning.FlavorsConfig;
import com.yahoo.vespa.config.content.core.StorCommunicationmanagerConfig;
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.config.model.test.MockRoot;
import com.yahoo.documentmodel.NewDocumentType;
import static com.yahoo.vespa.defaults.Defaults.getDefaults;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class StorageClusterTest {

    StorageCluster parse(String xml, Flavor flavor) {
        MockRoot root = new MockRoot("", new DeployState.Builder()
                .applicationPackage(new MockApplicationPackage.Builder().build())
                .modelHostProvisioner(new SingleNodeProvisioner(flavor)).build());
        return parse(xml, root);
    }

    StorageCluster parse(String xml) {
        MockRoot root = new MockRoot();
        return parse(xml, root);
    }
    StorageCluster parse(String xml, MockRoot root) {
        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() {
        StorageCluster storage = parse("<content id=\"foofighters\"><documents/>\n" +
              "  <group>" +
              "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
              "  </group>" +
              "</content>\n");

        assertEquals(1, storage.getChildren().size());
        StorServerConfig.Builder builder = new StorServerConfig.Builder();
        storage.getConfig(builder);
        StorServerConfig config = new StorServerConfig(builder);
        assertFalse(config.is_distributor());
        assertEquals("foofighters", config.cluster_name());
    }
    @Test
    public void testCommunicationManagerDefaults() {
        StorageCluster storage = parse("<content id=\"foofighters\"><documents/>\n" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</content>\n");
        StorCommunicationmanagerConfig.Builder builder = new StorCommunicationmanagerConfig.Builder();
        storage.getChildren().get("0").getConfig(builder);
        StorCommunicationmanagerConfig config = new StorCommunicationmanagerConfig(builder);
        assertFalse(config.mbus().dispatch_on_encode());
        assertFalse(config.mbus().dispatch_on_decode());
        assertEquals(4, config.mbus().num_threads());
        assertEquals(StorCommunicationmanagerConfig.Mbus.Optimize_for.LATENCY, config.mbus().optimize_for());
    }

    @Test
    public void testMerges() {
        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() {
        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() {

        StorageCluster stc = parse(
                "<cluster id=\"bees\">\n" +
                "    <documents/>" +
                "    <tuning>\n" +
                "        <persistence-threads count=\"7\"/>\n" +
                "    </tuning>\n" +
                "  <group>" +
                "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                "  </group>" +
                "</cluster>",
                new Flavor(new FlavorsConfig.Flavor.Builder().name("test-flavor").minCpuCores(9).build())
        );

        {
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            stc.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);

            assertEquals(7, config.num_threads());
            assertFalse(config.enable_multibit_split_optimalization());
            assertEquals(1, config.num_response_threads());
        }
        {
            assertEquals(1, stc.getChildren().size());
            StorageNode sn = stc.getChildren().values().iterator().next();
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            sn.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);
            assertEquals(7, config.num_threads());
        }
    }

    @Test
    public void testResponseThreads() {

        StorageCluster stc = parse(
                "<cluster id=\"bees\">\n" +
                        "    <documents/>" +
                        "    <tuning>\n" +
                        "        <persistence-threads count=\"7\"/>\n" +
                        "    </tuning>\n" +
                        "  <group>" +
                        "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                        "  </group>" +
                        "</cluster>",
                new Flavor(new FlavorsConfig.Flavor.Builder().name("test-flavor").minCpuCores(9).build())
        );
        StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
        stc.getConfig(builder);
        StorFilestorConfig config = new StorFilestorConfig(builder);
        assertEquals(1, config.num_response_threads());
        assertEquals(7, config.num_threads());
    }

    @Test
    public void testPersistenceThreadsOld() {

        StorageCluster stc = parse(
                "<cluster id=\"bees\">\n" +
                        "    <documents/>" +
                        "    <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>",
                new Flavor(new FlavorsConfig.Flavor.Builder().name("test-flavor").minCpuCores(9).build())
        );

        {
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            stc.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);

            assertEquals(4, config.num_threads());
            assertFalse(config.enable_multibit_split_optimalization());
        }
        {
            assertEquals(1, stc.getChildren().size());
            StorageNode sn = stc.getChildren().values().iterator().next();
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            sn.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);
            assertEquals(4, config.num_threads());
        }
    }

    @Test
    public void testNoPersistenceThreads() {
        StorageCluster stc = parse(
                "<cluster id=\"bees\">\n" +
                        "    <documents/>" +
                        "    <tuning>\n" +
                        "    </tuning>\n" +
                        "  <group>" +
                        "     <node distribution-key=\"0\" hostalias=\"mockhost\"/>" +
                        "  </group>" +
                        "</cluster>",
                new Flavor(new FlavorsConfig.Flavor.Builder().name("test-flavor").minCpuCores(9).build())
        );

        {
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            stc.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);
            assertEquals(8, config.num_threads());
        }
        {
            assertEquals(1, stc.getChildren().size());
            StorageNode sn = stc.getChildren().values().iterator().next();
            StorFilestorConfig.Builder builder = new StorFilestorConfig.Builder();
            sn.getConfig(builder);
            StorFilestorConfig config = new StorFilestorConfig(builder);
            assertEquals(9, config.num_threads());
        }
    }

    @Test
    public void integrity_checker_explicitly_disabled_when_not_running_with_vds_provider() {
        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 testCapacity() {
        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() {
        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");

        {
            StorServerConfig.Builder builder = new StorServerConfig.Builder();
            cluster.getStorageNodes().getConfig(builder);
            node.getConfig(builder);
            StorServerConfig config = new StorServerConfig(builder);
            assertEquals(getDefaults().underVespaHome("var/db/vespa/search/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(getDefaults().underVespaHome("var/db/vespa/search/storage/distributor/0"), config.root_folder());
        }
    }

    @Test
    public void testGenericPersistenceTuning() {
        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);
        assertTrue(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() {
        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() {
        String xml =
                "<cluster id=\"storage\">\n" +
                 "  <redundancy>2</redundancy>" +
                "  <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() {
        String xml =
                "<cluster id=\"storage\">\n" +
                "  <redundancy>2</redundancy>" +
                "<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() {
        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());
        }
    }
}