summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/persistence/filestorage/deactivatebucketstest.cpp
blob: 5e65f38e5b51f0e979d69df1777b9f4ce379452f (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storageapi/message/state.h>
#include <tests/persistence/common/persistenceproviderwrapper.h>
#include <vespa/persistence/dummyimpl/dummypersistence.h>
#include <tests/persistence/common/filestortestfixture.h>

namespace storage {

class DeactivateBucketsTest : public FileStorTestFixture
{
    bool isActive(const document::BucketId&) const;
public:
    void bucketsInDatabaseDeactivatedWhenNodeDownInClusterState(); 

    CPPUNIT_TEST_SUITE(DeactivateBucketsTest);
    CPPUNIT_TEST(bucketsInDatabaseDeactivatedWhenNodeDownInClusterState);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(DeactivateBucketsTest);

bool
DeactivateBucketsTest::isActive(const document::BucketId& bucket) const
{
    StorBucketDatabase::WrappedEntry entry(
            _node->getStorageBucketDatabase().get(bucket, "foo"));
    CPPUNIT_ASSERT(entry.exist());
    return entry->info.isActive();
}

void
DeactivateBucketsTest::bucketsInDatabaseDeactivatedWhenNodeDownInClusterState()
{
    TestFileStorComponents c(*this, "bucketsInDatabaseDeactivatedWhenNodeDownInClusterState");
    // Must set state to up first, or down-edge case won't trigger.
    std::string upState("storage:2 distributor:2");
    _node->getStateUpdater().setClusterState(
            lib::ClusterState::CSP(new lib::ClusterState(upState)));

    document::BucketId bucket(8, 123);
    spi::Bucket spiBucket(bucket, spi::PartitionId(0));

    createBucket(bucket);
    api::BucketInfo serviceLayerInfo(1, 2, 3, 4, 5, true, true);
    {
        StorBucketDatabase::WrappedEntry entry(
                _node->getStorageBucketDatabase().get(bucket, "foo",
                        StorBucketDatabase::CREATE_IF_NONEXISTING));
        entry->disk = 0;
        entry->info = serviceLayerInfo;
        entry.write();
    }
    CPPUNIT_ASSERT(isActive(bucket));
    std::string downState("storage:2 .1.s:d distributor:2");
    _node->getStateUpdater().setClusterState(
            lib::ClusterState::CSP(new lib::ClusterState(downState)));

    // Buckets should have been deactivated in content layer
    CPPUNIT_ASSERT(!isActive(bucket));
}

} // namespace storage