1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright 2011 Couchbase, Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef SRC_VBUCKETMAP_H_
19 #define SRC_VBUCKETMAP_H_ 1
30 * A map of known vbuckets.
33 friend class EventuallyPersistentStore;
36 class VBucketConfigChangeListener : public ValueChangedListener {
38 VBucketConfigChangeListener(VBucketMap& vbucketMap)
41 void sizeValueChanged(const std::string &key, size_t value) override;
49 // This class uses the same id_type as VBucket
50 typedef VBucket::id_type id_type;
52 VBucketMap(Configuration &config, EventuallyPersistentStore &store);
55 ENGINE_ERROR_CODE addBucket(const RCPtr<VBucket> &b);
56 void removeBucket(id_type id);
57 void addBuckets(const std::vector<VBucket*> &newBuckets);
58 RCPtr<VBucket> getBucket(id_type id) const;
60 // Returns the size of the map, i.e. the total number of VBuckets it can
62 id_type getSize() const;
63 std::vector<id_type> getBuckets(void) const;
64 std::vector<id_type> getBucketsSortedByState(void) const;
65 std::vector<std::pair<id_type, size_t> > getActiveVBucketsSortedByChkMgrMem(void) const;
66 bool isBucketDeletion(id_type id) const;
67 bool setBucketDeletion(id_type id, bool delBucket);
68 bool isBucketCreation(id_type id) const;
69 bool setBucketCreation(id_type id, bool rv);
70 uint64_t getPersistenceCheckpointId(id_type id) const;
71 void setPersistenceCheckpointId(id_type id, uint64_t checkpointId);
72 uint64_t getPersistenceSeqno(id_type id) const;
73 void setPersistenceSeqno(id_type id, uint64_t seqno);
74 KVShard* getShardByVbId(id_type id) const;
75 KVShard* getShard(KVShard::id_type shardId) const;
76 size_t getNumShards() const;
77 void setHLCDriftAheadThreshold(std::chrono::microseconds threshold);
78 void setHLCDriftBehindThreshold(std::chrono::microseconds threshold);
80 // Returns the current state of the given vBucket.
81 vbucket_state getVBucketState(VBucket::id_type id) const;
85 std::vector<KVShard*> shards;
86 AtomicValue<bool> *bucketDeletion;
87 AtomicValue<bool> *bucketCreation;
88 AtomicValue<uint64_t> *persistenceSeqnos;
91 DISALLOW_COPY_AND_ASSIGN(VBucketMap);
94 #endif // SRC_VBUCKETMAP_H_