Kea: lease_update_backlog.cc Source File

| Kea 3.0.3-git

lease_update_backlog.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <lease_update_backlog.h>
10#include <util/multi_threading_mgr.h>
11
12using namespace isc::dhcp;
13
14namespace isc {
15namespace ha {
16
17LeaseUpdateBacklog::LeaseUpdateBacklog(const size_t limit)
18 : limit_(limit), overflown_(false), outstanding_updates_() {
19}
20
21bool
22LeaseUpdateBacklog::push(const LeaseUpdateBacklog::OpType op_type, const LeasePtr& lease) {
23 if (util::MultiThreadingMgr::instance().getMode()) {
24 std::lock_guard<std::mutex> lock(mutex_);
25 return (pushInternal(op_type, lease));
26 }
27 return (pushInternal(op_type, lease));
28}
29
30 LeasePtr
31LeaseUpdateBacklog::pop(LeaseUpdateBacklog::OpType& op_type) {
32 if (util::MultiThreadingMgr::instance().getMode()) {
33 std::lock_guard<std::mutex> lock(mutex_);
34 return (popInternal(op_type));
35 }
36 return (popInternal(op_type));
37}
38
39bool
40LeaseUpdateBacklog::wasOverflown() {
41 if (util::MultiThreadingMgr::instance().getMode()) {
42 std::lock_guard<std::mutex> lock(mutex_);
43 return (overflown_);
44 }
45 return (overflown_);
46}
47
48void
49LeaseUpdateBacklog::clear() {
50 if (util::MultiThreadingMgr::instance().getMode()) {
51 std::lock_guard<std::mutex> lock(mutex_);
52 outstanding_updates_.clear();
53 overflown_ = false;
54 }
55 outstanding_updates_.clear();
56 overflown_ = false;
57}
58
59size_t
60LeaseUpdateBacklog::size() {
61 if (util::MultiThreadingMgr::instance().getMode()) {
62 std::lock_guard<std::mutex> lock(mutex_);
63 return (outstanding_updates_.size());
64 }
65 return (outstanding_updates_.size());
66}
67
68bool
69LeaseUpdateBacklog::pushInternal(const LeaseUpdateBacklog::OpType op_type, const LeasePtr& lease) {
70 if (outstanding_updates_.size() >= limit_) {
71 overflown_ = true;
72 return (false);
73 }
74 outstanding_updates_.push_back(std::make_pair(op_type, lease));
75 return (true);
76}
77
78 LeasePtr
79LeaseUpdateBacklog::popInternal(LeaseUpdateBacklog::OpType& op_type) {
80 if (outstanding_updates_.empty()) {
81 return (LeasePtr());
82 }
83 auto item = outstanding_updates_.front();
84 outstanding_updates_.pop_front();
85 op_type = item.first;
86 return (item.second);
87}
88
89} // end of namespace isc::ha
90} // end of namespace isc
isc::ha::LeaseUpdateBacklog::pop
dhcp::LeasePtr pop(OpType &op_type)
Returns the next lease update and removes it from the queue.
Definition lease_update_backlog.cc:31
isc::ha::LeaseUpdateBacklog::size
size_t size()
Returns the current size of the queue.
Definition lease_update_backlog.cc:60
isc::ha::LeaseUpdateBacklog::push
bool push(const OpType op_type, const dhcp::LeasePtr &lease)
Appends lease update to the queue.
Definition lease_update_backlog.cc:22
isc::ha::LeaseUpdateBacklog::OpType
OpType
Type of the lease update (operation type).
Definition lease_update_backlog.h:49
isc::ha::LeaseUpdateBacklog::clear
void clear()
Removes all lease updates from the queue.
Definition lease_update_backlog.cc:49
isc::ha::LeaseUpdateBacklog::wasOverflown
bool wasOverflown()
Checks if the queue was overflown.
Definition lease_update_backlog.cc:40
isc::ha::LeaseUpdateBacklog::LeaseUpdateBacklog
LeaseUpdateBacklog(const size_t limit)
Constructor.
Definition lease_update_backlog.cc:17
isc::util::MultiThreadingMgr::instance
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
Definition multi_threading_mgr.cc:25
lease_update_backlog.h
multi_threading_mgr.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::LeasePtr
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition lease.h:25
isc::ha
Definition command_creator.cc:20
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148