aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/bucket_ownership_flags.h
blob: f8016d0c5b31f40be54df187ad09168da41baaa4 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <cstdint>

namespace storage::distributor {

/*
 * Compact bucket ownership representation. Default value is not owned
 * by current state or pending state.  Bucket is always considered
 * owned in pending state if there is no pending state.
 */
class BucketOwnershipFlags {
    uint8_t _flags;
    
    static constexpr uint8_t owned_in_current_state_flag = 0x1;
    static constexpr uint8_t owned_in_pending_state_flag = 0x2;
    
public:
    constexpr BucketOwnershipFlags() noexcept
        : _flags(0)
    { }

    constexpr bool owned_in_current_state() const noexcept { return ((_flags & owned_in_current_state_flag) != 0); }
    constexpr bool owned_in_pending_state() const noexcept {  return ((_flags & owned_in_pending_state_flag) != 0); }
    constexpr void set_owned_in_current_state() noexcept { _flags |= owned_in_current_state_flag; }
    constexpr void set_owned_in_pending_state() noexcept { _flags |= owned_in_pending_state_flag; }
};

}