qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r619200 - in /incubator/qpid/trunk/qpid/cpp: qpidc.spec.in src/Makefile.am src/qpid/DataDir.cpp src/qpid/DataDir.h src/qpid/broker/Broker.cpp src/qpid/broker/Broker.h src/tests/BrokerFixture.h src/tests/Makefile.am
Date Wed, 06 Feb 2008 22:49:12 GMT
Author: aconway
Date: Wed Feb  6 14:49:10 2008
New Revision: 619200

URL: http://svn.apache.org/viewvc?rev=619200&view=rev
Log:
>From Ted Ross, https://issues.apache.org/jira/browse/QPID-780
Implementation of --data-dir for qpidd.

Additions by myself:
 - set QPID_DATA_DIR= in test env so existing tests can run with no data dir.
 - src/Makefile.am and qpidc.spec.in install /var/lib/qpidd directory.

NOTE: qpidd with no optoins will now FAIL if it cannot write /var/lib/qpidd.
Start it with --data-dir= or set QPID_DATA_DIR= in your environement to
run with no data directory.


Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/qpidc.spec.in
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
    incubator/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am

Modified: incubator/qpid/trunk/qpid/cpp/qpidc.spec.in
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/qpidc.spec.in?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/qpidc.spec.in (original)
+++ incubator/qpid/trunk/qpid/cpp/qpidc.spec.in Wed Feb  6 14:49:10 2008
@@ -98,6 +98,7 @@
 %_libdir/libqpidcommon.so.0.1.0
 %_libdir/libqpidclient.so.0
 %_libdir/libqpidclient.so.0.1.0
+%_localstatedir/qpidd
 %config(noreplace) %_sysconfdir/qpidd.conf
 
 %files devel

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Wed Feb  6 14:49:10 2008
@@ -140,6 +140,7 @@
   qpid/sys/SystemInfo.cpp \
   qpid/sys/Serializer.cpp \
   qpid/sys/Shlib.cpp \
+  qpid/DataDir.cpp \
   qpid/Options.cpp \
   qpid/log/Options.cpp \
   qpid/log/Selector.cpp \
@@ -236,6 +237,7 @@
 nobase_include_HEADERS = \
   $(platform_hdr) \
   qpid/assert.h \
+  qpid/DataDir.h \
   qpid/Exception.h \
   qpid/Msg.h \
   qpid/Options.h \
@@ -437,4 +439,8 @@
 # Force build of qpidd during dist phase so help2man will work.
 dist-hook: $(BUILT_SOURCES)
 	$(MAKE) qpidd
+
+# Create the default data directory
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)/$(localstatedir)/lib/qpidd
 

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp?rev=619200&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp Wed Feb  6 14:49:10 2008
@@ -0,0 +1,69 @@
+/*
+ * 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 "Exception.h"
+#include "DataDir.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <cerrno>
+
+namespace qpid {
+
+DataDir::DataDir (std::string path) :
+    enabled (!path.empty ()),
+    dirPath (path)
+{
+    if (!enabled)
+        return;
+
+    const  char *cpath = dirPath.c_str ();
+    struct stat  s;
+
+    if (::stat (cpath, &s))
+        throw Exception ("Data directory not found: " + path);
+
+    std::string lockFile (path);
+    lockFile = lockFile + "/lock";
+    int fd = ::open (lockFile.c_str (), O_CREAT | O_EXCL,
+                     S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+    if (fd == -1)
+    {
+        if (errno == EEXIST)
+            throw Exception ("Data directory is locked by another process");
+        if (errno == EACCES)
+            throw Exception ("Insufficient privileges for data directory");
+
+        std::ostringstream oss;
+        oss << "Error locking data directory: errno=" << errno;
+        throw Exception (oss.str ());
+    }
+}
+
+DataDir::~DataDir ()
+{
+    std::string lockFile (dirPath);
+    lockFile = lockFile + "/lock";
+
+    ::unlink (lockFile.c_str ());
+}
+
+} // namespace qpid
+

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h?rev=619200&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h Wed Feb  6 14:49:10 2008
@@ -0,0 +1,47 @@
+#ifndef QPID_DATADIR_H
+#define QPID_DATADIR_H
+
+/*
+ * 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 <string>
+
+namespace qpid {
+
+/**
+ * DataDir class.
+ */
+class DataDir
+{
+    const bool        enabled;
+    const std::string dirPath;
+
+  public:
+
+    DataDir (std::string path);
+    ~DataDir ();
+
+    bool        isEnabled () { return enabled; }
+    std::string getPath   () { return dirPath; }
+};
+ 
+} // namespace qpid
+
+#endif  /*!QPID_DATADIR_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/DataDir.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Wed Feb  6 14:49:10 2008
@@ -60,6 +60,7 @@
 
 Broker::Options::Options(const std::string& name) :
     qpid::Options(name),
+    dataDir("/var/lib/qpidd"),
     port(DEFAULT_PORT),
     workerThreads(5),
     maxConnections(500),
@@ -72,6 +73,8 @@
     int c = sys::SystemInfo::concurrency();
     workerThreads=std::max(2,c);
     addOptions()
+        ("data-dir", optValue(dataDir,"DIR"),
+         "Directory to contain persistent data generated by the broker")
         ("port,p", optValue(port,"PORT"),
          "Tells the broker to listen on PORT")
         ("worker-threads", optValue(workerThreads, "N"),
@@ -82,7 +85,7 @@
          "Sets the connection backlog limit for the server socket")
         ("staging-threshold", optValue(stagingThreshold, "N"),
          "Stages messages over N bytes to disk")
-        ("mgmt,m", optValue(enableMgmt,"yes|no"),
+        ("mgmt-enable,m", optValue(enableMgmt,"yes|no"),
          "Enable Management")
         ("mgmt-pub-interval", optValue(mgmtPubInterval, "SECONDS"),
          "Management Publish Interval")
@@ -100,6 +103,7 @@
 Broker::Broker(const Broker::Options& conf) :
     config(conf),
     store(0),
+    dataDir(conf.dataDir),
     factory(*this),
     sessionManager(conf.ack)
 {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Wed Feb  6 14:49:10 2008
@@ -37,6 +37,7 @@
 #include "qpid/management/ArgsBrokerConnect.h"
 #include "qpid/Options.h"
 #include "qpid/Plugin.h"
+#include "qpid/DataDir.h"
 #include "qpid/framing/FrameHandler.h"
 #include "qpid/framing/OutputHandler.h"
 #include "qpid/framing/ProtocolInitiation.h"
@@ -59,7 +60,8 @@
 
     struct Options : public qpid::Options {
         Options(const std::string& name="Broker Options");
-        
+
+        std::string dataDir;
         uint16_t port;
         int workerThreads;
         int maxConnections;
@@ -99,6 +101,7 @@
     ExchangeRegistry& getExchanges() { return exchanges; }
     uint64_t getStagingThreshold() { return config.stagingThreshold; }
     DtxManager& getDtxManager() { return dtxManager; }
+    DataDir& getDataDir() { return dataDir; }
 
     SessionManager& getSessionManager() { return sessionManager; }
 
@@ -113,6 +116,7 @@
     Options config;
     sys::Acceptor::shared_ptr acceptor;
     MessageStore* store;
+    DataDir dataDir;
 
     QueueRegistry queues;
     ExchangeRegistry exchanges;

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h Wed Feb  6 14:49:10 2008
@@ -46,6 +46,7 @@
         // Management doesn't play well with multiple in-process brokers.
         opts.enableMgmt=false;  
         opts.workerThreads=1;
+        opts.dataDir="";
         broker = Broker::create(opts);
         // TODO aconway 2007-12-05: At one point BrokerFixture
         // tests could hang in Connection ctor if the following

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=619200&r1=619199&r2=619200&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Wed Feb  6 14:49:10 2008
@@ -109,7 +109,7 @@
 
 check_PROGRAMS += $(testprogs) interop_runner
 
-TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) $(srcdir)/run_test
+TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) QPID_DATA_DIR= $(srcdir)/run_test

 
 system_tests = client_test quick_perftest quick_topictest
 TESTS += run-unit-tests start_broker $(system_tests) python_tests stop_broker 



Mime
View raw message