summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/cluster/StoreStatus.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2009-11-24 20:07:24 +0000
committerAlan Conway <aconway@apache.org>2009-11-24 20:07:24 +0000
commit0fb7ff9cfbfd01e9093c2c6021a5915696d2a089 (patch)
tree1d2db335592be80a9aa9f8f404d2c1682afeb485 /cpp/src/qpid/cluster/StoreStatus.cpp
parent1ee447563d208b39e962537a47f14aea741777b0 (diff)
downloadqpid-python-0fb7ff9cfbfd01e9093c2c6021a5915696d2a089.tar.gz
Support for restarting a persistent cluster.
Option --cluster-size=N: members wait for N members before recovering store. Stores marked as clean/dirty. Automatically recover from clean store on restart. Stores marked with UUID to detect errors. Not yet implemented: consistency checks, manual recovery from all dirty stores. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@883842 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/cluster/StoreStatus.cpp')
-rw-r--r--cpp/src/qpid/cluster/StoreStatus.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/cpp/src/qpid/cluster/StoreStatus.cpp b/cpp/src/qpid/cluster/StoreStatus.cpp
new file mode 100644
index 0000000000..1c5f581ea1
--- /dev/null
+++ b/cpp/src/qpid/cluster/StoreStatus.cpp
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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 "StoreStatus.h"
+#include "qpid/Exception.h"
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <fstream>
+
+namespace qpid {
+namespace cluster {
+
+using framing::Uuid;
+using namespace framing::cluster;
+using namespace boost::filesystem;
+
+StoreStatus::StoreStatus(const std::string& d)
+ : state(STORE_STATE_NO_STORE), dataDir(d)
+{}
+
+namespace {
+
+const char* SUBDIR="cluster";
+const char* START_FILE="start";
+const char* STOP_FILE="stop";
+
+Uuid loadUuid(const path& path) {
+ Uuid ret;
+ if (exists(path)) {
+ ifstream i(path);
+ i >> ret;
+ }
+ return ret;
+}
+
+void saveUuid(const path& path, const Uuid& uuid) {
+ ofstream o(path);
+ o << uuid;
+}
+
+} // namespace
+
+
+void StoreStatus::load() {
+ path dir = path(dataDir)/SUBDIR;
+ create_directory(dir);
+ start = loadUuid(dir/START_FILE);
+ stop = loadUuid(dir/STOP_FILE);
+
+ if (start && stop) state = STORE_STATE_CLEAN_STORE;
+ else if (start) state = STORE_STATE_DIRTY_STORE;
+ else state = STORE_STATE_EMPTY_STORE;
+}
+
+void StoreStatus::save() {
+ path dir = path(dataDir)/SUBDIR;
+ create_directory(dir);
+ saveUuid(dir/START_FILE, start);
+ saveUuid(dir/STOP_FILE, stop);
+}
+
+void StoreStatus::dirty(const Uuid& start_) {
+ start = start_;
+ stop = Uuid();
+ state = STORE_STATE_DIRTY_STORE;
+ save();
+}
+
+void StoreStatus::clean(const Uuid& stop_) {
+ assert(start); // FIXME aconway 2009-11-20: exception?
+ assert(stop_);
+ state = STORE_STATE_CLEAN_STORE;
+ stop = stop_;
+ save();
+}
+
+}} // namespace qpid::cluster
+