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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <cppunit/extensions/HelperMacros.h>
#include <vespa/storageapi/message/bucketsplitting.h>
#include <vespa/storage/distributor/operations/idealstate/joinoperation.h>
#include <vespa/storage/distributor/distributor.h>
#include <tests/distributor/distributortestutil.h>
#include <vespa/document/test/make_document_bucket.h>
using document::test::makeDocumentBucket;
namespace storage {
namespace distributor {
class JoinOperationTest : public CppUnit::TestFixture, public DistributorTestUtil
{
CPPUNIT_TEST_SUITE(JoinOperationTest);
CPPUNIT_TEST(testSimple);
CPPUNIT_TEST(sendSparseJoinsToNodesWithoutBothSourceBuckets);
CPPUNIT_TEST_SUITE_END();
void checkSourceBucketsAndSendReply(
JoinOperation& op,
size_t msgIndex,
const std::vector<document::BucketId>& wantedIds);
protected:
void testSimple();
void sendSparseJoinsToNodesWithoutBothSourceBuckets();
public:
void setUp() override {
createLinks();
};
void tearDown() override {
close();
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(JoinOperationTest);
void
JoinOperationTest::testSimple()
{
getConfig().setJoinCount(100);
getConfig().setJoinSize(1000);
addNodesToBucketDB(document::BucketId(33, 1), "0=250/50/300");
addNodesToBucketDB(document::BucketId(33, 0x100000001), "0=300/40/200");
enableDistributorClusterState("distributor:1 storage:1");
JoinOperation op("storage",
BucketAndNodes(makeDocumentBucket(document::BucketId(32, 0)),
toVector<uint16_t>(0)),
toVector(document::BucketId(33, 1),
document::BucketId(33, 0x100000001)));
op.setIdealStateManager(&getIdealStateManager());
op.start(_sender, framework::MilliSecTime(0));
checkSourceBucketsAndSendReply(op, 0, {{33, 1}, {33, 0x100000001}});
CPPUNIT_ASSERT(!getBucket(document::BucketId(33, 0x100000001)).valid());
CPPUNIT_ASSERT(!getBucket(document::BucketId(33, 1)).valid());
BucketDatabase::Entry entry = getBucket(document::BucketId(32, 0));
CPPUNIT_ASSERT(entry.valid());
CPPUNIT_ASSERT_EQUAL((uint16_t)0, entry->getNodeRef(0).getNode());
CPPUNIT_ASSERT_EQUAL(api::BucketInfo(666, 90, 500),
entry->getNodeRef(0).getBucketInfo());
}
void
JoinOperationTest::checkSourceBucketsAndSendReply(
JoinOperation& op,
size_t msgIndex,
const std::vector<document::BucketId>& wantedIds)
{
CPPUNIT_ASSERT(_sender.commands.size() > msgIndex);
std::shared_ptr<api::StorageCommand> msg(_sender.commands[msgIndex]);
CPPUNIT_ASSERT_EQUAL(api::MessageType::JOINBUCKETS, msg->getType());
api::JoinBucketsCommand& joinCmd(
dynamic_cast<api::JoinBucketsCommand&>(*msg));
CPPUNIT_ASSERT_EQUAL(wantedIds, joinCmd.getSourceBuckets());
std::shared_ptr<api::StorageReply> reply(joinCmd.makeReply());
api::JoinBucketsReply& sreply(
dynamic_cast<api::JoinBucketsReply&>(*reply));
sreply.setBucketInfo(api::BucketInfo(666, 90, 500));
op.receive(_sender, reply);
}
/**
* If the set of buckets kept on nodes is disjoint, send sparse joins (same
* bucket id used as both source buckets) for those nodes having only one of
* the buckets.
*/
void
JoinOperationTest::sendSparseJoinsToNodesWithoutBothSourceBuckets()
{
getConfig().setJoinCount(100);
getConfig().setJoinSize(1000);
addNodesToBucketDB(document::BucketId(33, 1), "0=250/50/300,1=250/50/300");
addNodesToBucketDB(document::BucketId(33, 0x100000001), "0=300/40/200");
enableDistributorClusterState("distributor:1 storage:2");
JoinOperation op("storage",
BucketAndNodes(makeDocumentBucket(document::BucketId(32, 0)),
toVector<uint16_t>(0, 1)),
toVector(document::BucketId(33, 1),
document::BucketId(33, 0x100000001)));
op.setIdealStateManager(&getIdealStateManager());
op.start(_sender, framework::MilliSecTime(0));
checkSourceBucketsAndSendReply(op, 0, {{33, 1}, {33, 0x100000001}});
checkSourceBucketsAndSendReply(op, 1, {{33, 1}, {33, 1}});
}
}
}
|