aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/common/messagebucket.cpp
blob: 202c4a29facdcf4d351d05d0742f125b6e7e2802 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "messagebucket.h"
#include "statusmessages.h"
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storageapi/message/bucketsplitting.h>
#include <vespa/storageapi/message/persistence.h>
#include <vespa/storageapi/message/removelocation.h>
#include <vespa/storage/persistence/messages.h>
#include <vespa/storageapi/message/stat.h>

#include <vespa/vespalib/util/exceptions.h>

namespace storage {

document::Bucket
getStorageMessageBucket(const api::StorageMessage& msg)
{
    switch (msg.getType().getId()) {
    case api::MessageType::GET_ID:
        return static_cast<const api::GetCommand&>(msg).getBucket();
    case api::MessageType::PUT_ID:
        return static_cast<const api::PutCommand&>(msg).getBucket();
    case api::MessageType::UPDATE_ID:
        return static_cast<const api::UpdateCommand&>(msg).getBucket();
    case api::MessageType::REMOVE_ID:
        return static_cast<const api::RemoveCommand&>(msg).getBucket();
    case api::MessageType::STATBUCKET_ID:
        return static_cast<const api::StatBucketCommand&>(msg).getBucket();
    case api::MessageType::REMOVELOCATION_ID:
        return static_cast<const api::RemoveLocationCommand&>(msg).getBucket();
    case api::MessageType::CREATEBUCKET_ID:
        return static_cast<const api::CreateBucketCommand&>(msg).getBucket();
    case api::MessageType::DELETEBUCKET_ID:
        return static_cast<const api::DeleteBucketCommand&>(msg).getBucket();
    case api::MessageType::MERGEBUCKET_ID:
        return static_cast<const api::MergeBucketCommand&>(msg).getBucket();
    case api::MessageType::GETBUCKETDIFF_ID:
        return static_cast<const api::GetBucketDiffCommand&>(msg).getBucket();
    case api::MessageType::GETBUCKETDIFF_REPLY_ID:
        return static_cast<const api::GetBucketDiffReply&>(msg).getBucket();
    case api::MessageType::APPLYBUCKETDIFF_ID:
        return static_cast<const api::ApplyBucketDiffCommand&>(msg).getBucket();
    case api::MessageType::APPLYBUCKETDIFF_REPLY_ID:
        return static_cast<const api::ApplyBucketDiffReply&>(msg).getBucket();
    case api::MessageType::JOINBUCKETS_ID:
        return static_cast<const api::JoinBucketsCommand&>(msg).getBucket();
    case api::MessageType::SPLITBUCKET_ID:
        return static_cast<const api::SplitBucketCommand&>(msg).getBucket();
    case api::MessageType::SETBUCKETSTATE_ID:
        return static_cast<const api::SetBucketStateCommand&>(msg).getBucket();
    case api::MessageType::INTERNAL_ID:
        switch(static_cast<const api::InternalCommand&>(msg).getType()) {
        case RequestStatusPage::ID:
            return document::Bucket();
        case GetIterCommand::ID:
            return static_cast<const GetIterCommand&>(msg).getBucket();
        case CreateIteratorCommand::ID:
            return static_cast<const CreateIteratorCommand&>(msg).getBucket();
        case RecheckBucketInfoCommand::ID:
            return static_cast<const RecheckBucketInfoCommand&>(msg).getBucket();
        case RunTaskCommand::ID:
            return static_cast<const RunTaskCommand&>(msg).getBucket();
        default:
            break;
        }
    default:
        break;
    }
    throw vespalib::IllegalArgumentException(
            "Message of type " + msg.toString() + " was not expected. Don't "
            "know how to calculate bucket this message operates on.",
            VESPA_STRLOC);
}

}