From ed0d321d0ad56b9ea3d370d8b6b34fce2c8ef892 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 12 Jun 2012 21:20:07 +0000 Subject: QPID-3603: Introduced RemoteBackup to track backup status. The primary creates RemoteBackup object for each connected or expected backup. On first being promoted, the new primary has a RemoteBackup for each of the known backups at the time of the failure. The RemoteBackup manages queue guards for its backup and tracks it's readiness. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1349540 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/ha/RemoteBackup.cpp | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 cpp/src/qpid/ha/RemoteBackup.cpp (limited to 'cpp/src/qpid/ha/RemoteBackup.cpp') diff --git a/cpp/src/qpid/ha/RemoteBackup.cpp b/cpp/src/qpid/ha/RemoteBackup.cpp new file mode 100644 index 0000000000..94e60d7ed8 --- /dev/null +++ b/cpp/src/qpid/ha/RemoteBackup.cpp @@ -0,0 +1,81 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "RemoteBackup.h" +#include "QueueGuard.h" +#include "qpid/broker/Broker.h" +#include "qpid/broker/Queue.h" +#include "qpid/broker/QueueRegistry.h" +#include + +namespace qpid { +namespace ha { + +using sys::Mutex; + +RemoteBackup::RemoteBackup( + const BrokerInfo& info, broker::Broker& broker, ReplicationTest rt) : + logPrefix("HA backup "+info.getLogId()+": "), brokerInfo(info), replicationTest(rt) +{ + QPID_LOG(debug, logPrefix << "Guarding queues for backup broker. "); + broker.getQueues().eachQueue(boost::bind(&RemoteBackup::initialQueue, this, _1)); +} + +bool RemoteBackup::isReady() { + return initialQueues.empty(); +} + +void RemoteBackup::initialQueue(const QueuePtr& q) { + initialQueues.insert(q); + queueCreate(q); +} + +RemoteBackup::GuardPtr RemoteBackup::guard(const QueuePtr& q) { + GuardMap::iterator i = guards.find(q); + if (i == guards.end()) { + assert(0); + throw Exception(logPrefix+": Guard cannot find queue guard: "+q->getName()); + } + GuardPtr guard = i->second; + guards.erase(i); + return guard; +} + +void RemoteBackup::ready(const QueuePtr& q) { + initialQueues.erase(q); +} + +void RemoteBackup::queueCreate(const QueuePtr& q) { + if (replicationTest.isReplicated(ALL, *q)) { + QPID_LOG(debug, logPrefix << "Setting guard on " << q->getName()); + guards[q].reset(new QueueGuard(*q, brokerInfo)); + } +} + +void RemoteBackup::queueDestroy(const QueuePtr& q) { + initialQueues.erase(q); + GuardMap::iterator i = guards.find(q); + if (i != guards.end()) { + i->second->cancel(); + guards.erase(i); + } +} + +}} // namespace qpid::ha -- cgit v1.2.1