From 60be74230e48bb7f3aba132e247d054a8b8b8a0d Mon Sep 17 00:00:00 2001 From: Tyler Hobbs Date: Thu, 5 Jun 2014 15:38:41 -0500 Subject: [PATCH] Use $CASSANDRA_HOME for default paths instead of /var Patch by Tyler Hobbs; reviewed by Brandon Williams and Joshua McKenzie for CASSANDRA-7136 --- CHANGES.txt | 1 + NEWS.txt | 10 ++++ bin/cassandra | 1 + bin/cassandra.bat | 1 + bin/cassandra.ps1 | 4 ++ conf/cassandra.yaml | 11 ++-- conf/logback.xml | 4 +- debian/control | 2 +- debian/patches/001cassandra_yaml_dirs.dpatch | 36 +++++++++++ debian/patches/00list | 1 + debian/rules | 6 +- .../cassandra/config/DatabaseDescriptor.java | 60 +++++++++++-------- 12 files changed, 104 insertions(+), 33 deletions(-) create mode 100644 debian/patches/001cassandra_yaml_dirs.dpatch create mode 100644 debian/patches/00list diff --git a/CHANGES.txt b/CHANGES.txt index 3cea1e742e..fd593e7c4b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,7 @@ * Reduce run time for CQL tests (CASSANDRA-7327) * Fix heap size calculation on Windows (CASSANDRA-7352) * RefCount native frames from netty (CASSANDRA-7245) + * Use tarball dir instead of /var for default paths (CASSANDRA-7136) Merged from 2.0: * Add per-CF range read request latency metrics (CASSANDRA-7338) * Fix NPE in StreamTransferTask.createMessageForRetry() (CASSANDRA-7323) diff --git a/NEWS.txt b/NEWS.txt index c1b2b440fd..4eed9de720 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -18,6 +18,16 @@ using the provided 'sstableupgrade' tool. New features ------------ + - Default data and log locations have changed. If not set in + cassandra.yaml, the data file directory, commitlog directory, + and saved caches directory will default to $CASSANDRA_HOME/data/data, + $CASSANDRA_HOME/data/commitlog, and $CASSANDRA_HOME/data/saved_caches, + respectively. The log directory now defaults to $CASSANDRA_HOME/logs. + If not set, $CASSANDRA_HOME, defaults to the top-level directory of + the installation. + Note that this should only affect source checkouts and tarballs. + Deb and RPM packages will continue to use /var/lib/cassandra and + /var/log/cassandra in cassandra.yaml. - SSTable data directory name is slightly changed. Each directory will have hex string appended after CF name, e.g. ks/cf-5be396077b811e3a3ab9dc4b9ac088d/ diff --git a/bin/cassandra b/bin/cassandra index f34ca8cc40..797d36be6e 100755 --- a/bin/cassandra +++ b/bin/cassandra @@ -134,6 +134,7 @@ launch_service() props="$3" class="$4" cassandra_parms="-Dlogback.configurationFile=logback.xml" + cassandra_parms="$cassandra_parms -Dcassandra.logdir=$CASSANDRA_HOME/logs -Dcassandra.storagedir=$CASSANDRA_HOME/data" if [ "x$pidpath" != "x" ]; then cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath" diff --git a/bin/cassandra.bat b/bin/cassandra.bat index 172ca8e172..629e58bc41 100644 --- a/bin/cassandra.bat +++ b/bin/cassandra.bat @@ -86,6 +86,7 @@ goto :eof REM Include the build\classes\main directory so it works in development set CASSANDRA_CLASSPATH=%CLASSPATH%;"%CASSANDRA_HOME%\build\classes\main";"%CASSANDRA_HOME%\build\classes\thrift" set CASSANDRA_PARAMS=-Dcassandra -Dcassandra-foreground=yes +set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% "-Dcassandra.logdir=%CASSANDRA_HOME%\logs" "-Dcassandra.storagedir=%CASSANDRA_HOME%\data" if /i "%ARG%" == "INSTALL" goto doInstallOperation if /i "%ARG%" == "UNINSTALL" goto doInstallOperation goto runDaemon diff --git a/bin/cassandra.ps1 b/bin/cassandra.ps1 index 19d831a0b6..ac8d89c53c 100644 --- a/bin/cassandra.ps1 +++ b/bin/cassandra.ps1 @@ -77,6 +77,10 @@ Function Main SetCassandraEnvironment $pidfile = "$env:CASSANDRA_HOME/$pidfile" + $logdir = "$env:CASSANDRA_HOME/logs" + $storagedir = "$env:CASSANDRA_HOME/data" + $env:CASSANDRA_PARAMS = $env:CASSANDRA_PARAMS + " -Dcassandra.logdir=$logdir -Dcassandra.storagedir=$storagedir" + # Other command line params if ($H) { diff --git a/conf/cassandra.yaml b/conf/cassandra.yaml index 561c7fff36..e6c34e04df 100644 --- a/conf/cassandra.yaml +++ b/conf/cassandra.yaml @@ -93,12 +93,14 @@ partitioner: org.apache.cassandra.dht.Murmur3Partitioner # Directories where Cassandra should store data on disk. Cassandra # will spread data evenly across them, subject to the granularity of # the configured compaction strategy. -data_file_directories: - - /var/lib/cassandra/data +# If not set, the default directory is $CASSANDRA_HOME/data/data. +# data_file_directories: +# - /var/lib/cassandra/data # commit log. when running on magnetic HDD, this should be a # separate spindle than the data directories. -commitlog_directory: /var/lib/cassandra/commitlog +# If not set, the default directory is $CASSANDRA_HOME/data/commitlog. +# commitlog_directory: /var/lib/cassandra/commitlog # policy for data disk failures: # stop_paranoid: shut down gossip and Thrift even for single-sstable errors. @@ -200,7 +202,8 @@ counter_cache_save_period: 7200 # memory_allocator: NativeAllocator # saved caches -saved_caches_directory: /var/lib/cassandra/saved_caches +# If not set, the default directory is $CASSANDRA_HOME/data/saved_caches. +# saved_caches_directory: /var/lib/cassandra/saved_caches # commitlog_sync may be either "periodic" or "batch." # When in batch mode, Cassandra won't ack writes until the commit log diff --git a/conf/logback.xml b/conf/logback.xml index 61e5a1341e..e170d41886 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -20,9 +20,9 @@ - /var/log/cassandra/system.log + ${cassandra.logdir}/system.log - /var/log/cassandra/system.log.%i.zip + ${cassandra.logdir}/system.log.%i.zip 1 20 diff --git a/debian/control b/debian/control index cc0c49ba66..f1167c33ab 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: misc Priority: extra Maintainer: Eric Evans Uploaders: Sylvain Lebresne -Build-Depends: debhelper (>= 5), openjdk-7-jdk | java7-jdk, ant (>= 1.7), ant-optional (>= 1.7), python-support +Build-Depends: debhelper (>= 5), openjdk-7-jdk | java7-jdk, ant (>= 1.7), ant-optional (>= 1.7), python-support, dpatch Homepage: http://cassandra.apache.org Vcs-Git: http://git-wip-us.apache.org/repos/asf/cassandra.git Vcs-Browser: https://git-wip-us.apache.org/repos/asf?p=cassandra.git diff --git a/debian/patches/001cassandra_yaml_dirs.dpatch b/debian/patches/001cassandra_yaml_dirs.dpatch new file mode 100644 index 0000000000..3d545e5290 --- /dev/null +++ b/debian/patches/001cassandra_yaml_dirs.dpatch @@ -0,0 +1,36 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 001cassandra_yaml_dirs.dpatch by Tyler Hobbs +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: No description. + +@DPATCH@ +diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' cassandra~/conf/cassandra.yaml cassandra/conf/cassandra.yaml +--- cassandra~/conf/cassandra.yaml 2014-06-05 13:36:22.000000000 -0500 ++++ cassandra/conf/cassandra.yaml 2014-06-05 13:39:20.569034040 -0500 +@@ -94,13 +94,13 @@ + # will spread data evenly across them, subject to the granularity of + # the configured compaction strategy. + # If not set, the default directory is $CASSANDRA_HOME/data/data. +-# data_file_directories: +-# - /var/lib/cassandra/data ++data_file_directories: ++ - /var/lib/cassandra/data + + # commit log. when running on magnetic HDD, this should be a + # separate spindle than the data directories. + # If not set, the default directory is $CASSANDRA_HOME/data/commitlog. +-# commitlog_directory: /var/lib/cassandra/commitlog ++commitlog_directory: /var/lib/cassandra/commitlog + + # policy for data disk failures: + # stop_paranoid: shut down gossip and Thrift even for single-sstable errors. +@@ -203,7 +203,7 @@ + + # saved caches + # If not set, the default directory is $CASSANDRA_HOME/data/saved_caches. +-# saved_caches_directory: /var/lib/cassandra/saved_caches ++saved_caches_directory: /var/lib/cassandra/saved_caches + + # commitlog_sync may be either "periodic" or "batch." + # When in batch mode, Cassandra won't ack writes until the commit log diff --git a/debian/patches/00list b/debian/patches/00list new file mode 100644 index 0000000000..508c180ef7 --- /dev/null +++ b/debian/patches/00list @@ -0,0 +1 @@ +001cassandra_yaml_dirs.dpatch diff --git a/debian/rules b/debian/rules index 717bbf2745..602cfde6c3 100755 --- a/debian/rules +++ b/debian/rules @@ -3,6 +3,8 @@ # Uncomment to enable verbose mode. #export DH_VERBOSE=1 +include /usr/share/dpatch/dpatch.make + ANT = /usr/bin/ant VERSION = $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(.*\)/\1/p') @@ -10,7 +12,7 @@ test: dh_testdir $(ANT) test -clean: +clean: unpatch dh_testdir dh_testroot $(ANT) realclean @@ -22,7 +24,7 @@ clean: dh_clean build: build-stamp -build-stamp: +build-stamp: patch-stamp dh_testdir printf "version=%s" $(VERSION) > build.properties diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 5b227ae02e..3cc53ded8b 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -452,36 +452,48 @@ public class DatabaseDescriptor throw new ConfigurationException("in_memory_compaction_limit_in_mb must be a positive integer"); } + // if data dirs, commitlog dir, or saved caches dir are set in cassandra.yaml, use that. Otherwise, + // use -Dcassandra.storagedir (set in cassandra-env.sh) as the parent dir for data/, commitlog/, and saved_caches/ + if (conf.commitlog_directory == null) + { + conf.commitlog_directory = System.getProperty("cassandra.storagedir", null); + if (conf.commitlog_directory == null) + throw new ConfigurationException("commitlog_directory is missing and -Dcassandra.storagedir is not set"); + conf.commitlog_directory += File.separator + "commitlog"; + } + if (conf.saved_caches_directory == null) + { + conf.saved_caches_directory = System.getProperty("cassandra.storagedir", null); + if (conf.saved_caches_directory == null) + throw new ConfigurationException("saved_caches_directory is missing and -Dcassandra.storagedir is not set"); + conf.saved_caches_directory += File.separator + "saved_caches"; + } + if (conf.data_file_directories == null) + { + String defaultDataDir = System.getProperty("cassandra.storagedir", null); + if (defaultDataDir == null) + throw new ConfigurationException("data_file_directories is not missing and -Dcassandra.storagedir is not set"); + conf.data_file_directories = new String[]{ defaultDataDir + File.separator + "data" }; + } + + /* data file and commit log directories. they get created later, when they're needed. */ + for (String datadir : conf.data_file_directories) + { + if (datadir.equals(conf.commitlog_directory)) + throw new ConfigurationException("commitlog_directory must not be the same as any data_file_directories"); + if (datadir.equals(conf.saved_caches_directory)) + throw new ConfigurationException("saved_caches_directory must not be the same as any data_file_directories"); + } + + if (conf.commitlog_directory.equals(conf.saved_caches_directory)) + throw new ConfigurationException("saved_caches_directory must not be the same as the commitlog_directory"); + if (conf.concurrent_compactors == null) conf.concurrent_compactors = Math.min(8, Math.max(2, Math.min(FBUtilities.getAvailableProcessors(), conf.data_file_directories.length))); if (conf.concurrent_compactors <= 0) throw new ConfigurationException("concurrent_compactors should be strictly greater than 0"); - /* data file and commit log directories. they get created later, when they're needed. */ - if (conf.commitlog_directory != null && conf.data_file_directories != null && conf.saved_caches_directory != null) - { - for (String datadir : conf.data_file_directories) - { - if (datadir.equals(conf.commitlog_directory)) - throw new ConfigurationException("commitlog_directory must not be the same as any data_file_directories"); - if (datadir.equals(conf.saved_caches_directory)) - throw new ConfigurationException("saved_caches_directory must not be the same as any data_file_directories"); - } - - if (conf.commitlog_directory.equals(conf.saved_caches_directory)) - throw new ConfigurationException("saved_caches_directory must not be the same as the commitlog_directory"); - } - else - { - if (conf.commitlog_directory == null) - throw new ConfigurationException("commitlog_directory missing"); - if (conf.data_file_directories == null) - throw new ConfigurationException("data_file_directories missing; at least one data directory must be specified"); - if (conf.saved_caches_directory == null) - throw new ConfigurationException("saved_caches_directory missing"); - } - if (conf.initial_token != null) for (String token : tokensFromString(conf.initial_token)) partitioner.getTokenFactory().validate(token);