summaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-07-14 13:58:20 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-07-14 14:44:26 -0700
commit654a720eed0bc5faaeeaa4eb34f1cfc10df76230 (patch)
treeb84419d192c46e39a40b7a3133666ddde453aba2 /extras
parente73a856e926465068f6f6cf5a0cace501589957c (diff)
proper way to do defrag of a mountpoint
Usage: "glusterfs-defrag <MOUNTPOINT>" there are new features added to distribute with this patch: * bash# getfattr -n trusted.distribute.linkinfo <file> Gives output in the format "<hostname>:<directory>", if there is a linkfile present, where hostname is server, directory is backend directory where the actual linkfile is present. * bash# getfattr -n trusted.glusterfs.pathinfo <path> Gives layout information if directory, and info about actual location of file in backend servers, in the form of 'hostname:directory'. (TODO: should extend it to all xlators) * bash# getfattr -n trusted.distribute.fix.layout <path> scales out the directory layout in distribute, so when new servers are added, layouts are fixed to include them. * removed 'scale-n-defrag.sh' as its no more required. * changed 'defrag.sh' to have a feature to specify target bricks, so defrag happens to only those nodes. moved the file to 'glusterfs-defrag', which now gets installed to '${prefix}/bin' * storage/posix: takes new option 'hostname' so it can resolve to same hostname given during 'gluster volume create'. with 'trusted.glusterfs.pathinfo' posix returns the value in 'hostname:real_path' format. Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1073 ('gluster defrag <VOLNAME>' fails in mainline) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1073
Diffstat (limited to 'extras')
-rw-r--r--extras/Makefile.am2
-rw-r--r--extras/defrag.sh60
-rw-r--r--extras/glusterfs-defrag.in109
-rw-r--r--extras/scale-n-defrag.sh37
-rw-r--r--extras/volgen/CreateVolfile.py1
5 files changed, 112 insertions, 97 deletions
diff --git a/extras/Makefile.am b/extras/Makefile.am
index c11137143..6ea4744c9 100644
--- a/extras/Makefile.am
+++ b/extras/Makefile.am
@@ -3,6 +3,8 @@ docdir = $(datadir)/doc/glusterfs/
EditorModedir = $(docdir)/
EditorMode_DATA = glusterfs-mode.el glusterfs.vim
+dist_bin_SCRIPTS = glusterfs-defrag
+
SUBDIRS = init.d benchmarking volgen
EXTRA_DIST = specgen.scm MacOSX/Portfile glusterfs-mode.el glusterfs.vim migrate-unify-to-distribute.sh backend-xattr-sanitize.sh backend-cleanup.sh defrag.sh scale-n-defrag.sh disk_usage_sync.sh
diff --git a/extras/defrag.sh b/extras/defrag.sh
deleted file mode 100644
index 465b09794..000000000
--- a/extras/defrag.sh
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/sh
-
-# This script gets called from 'scale-n-defrag.sh' script.
-# Don't run this stand alone.
-#
-#
-
-set -e
-
-CP="cp"
-MV="mv"
-
-scan_dir()
-{
- path=$1;
- find "$path" -type f -perm +01000 -exec $0 '{}' \;
-}
-
-rsync_filename()
-{
- path=$1
- dir=$(dirname "$path");
- file=$(basename "$path");
-
- echo "$dir/.$file.zr$$";
-}
-
-relocate_file()
-{
- path=$1;
- tmp_path=$(rsync_filename "$path");
-
- pre_mtime=$(stat -c '%Y' "$path");
- $CP -a "$path" "$tmp_path";
- post_mtime=$(stat -c '%Y' "$path");
-
- if [ $pre_mtime = $post_mtime ]; then
- chmod -t "$tmp_path";
- $MV "$tmp_path" "$path";
- echo "file '$path' relocated"
- else
- echo "file '$path' modified during defrag. skipping"
- rm -f "$tmp_path";
- fi
-}
-
-main()
-{
- path="$1";
-
- if [ -d "$path" ]; then
- scan_dir "$path";
- else
- relocate_file "$@";
- fi
-
- usleep 500000 # 500ms
-}
-
-main "$1"
diff --git a/extras/glusterfs-defrag.in b/extras/glusterfs-defrag.in
new file mode 100644
index 000000000..982878bdb
--- /dev/null
+++ b/extras/glusterfs-defrag.in
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+# Please leave 'added_bricks' as empty if you want 100% defrag.
+# If you want to move data to newly added bricks, properly give
+# brick info as "<hostname>:<export-dir>" form (which was given
+# in 'gluster volume create' command)
+# More than one brick can be given with space inbetween.
+
+#
+# (c) 2010 Gluster Inc <http://www.gluster.com/>
+#
+
+set -e;
+
+added_bricks="node1:/gfs/export1"
+
+CP="cp"
+MV="mv"
+
+scan_dir()
+{
+ path=$1;
+ # run defrag on files first #
+ find "$path" -maxdepth 1 -type f -perm +01000 -exec $0 '{}' \;
+
+ for subdir in $(find "$path" -maxdepth 1 -type d | sed 1d); do
+ $0 "$subdir";
+ done
+}
+
+fix_xattr()
+{
+ path=$1;
+ getfattr -n trusted.distribute.fix.layout "$path" 2>/dev/null;
+}
+
+rsync_filename()
+{
+ path=$1
+ dir=$(dirname "$path");
+ file=$(basename "$path");
+
+ echo "$dir/.$file.zr$$";
+}
+
+relocate_file()
+{
+ path=$1;
+ stat_info=$(stat -c '%a' "$path");
+ if [ $stat_info -lt 1000 ] ; then
+ return;
+ fi
+
+ flag=0;
+ linknode=$(getfattr --only-values -n trusted.distribute.linkinfo $path 2>/dev/null);
+ if [ -z $linknode ] ; then
+ return;
+ fi
+
+ for bricks in ${added_bricks}; do
+ current_brick=${linknode:0:${#bricks}};
+ if [ "${bricks}" == "${current_brick}" ]; then
+ flag=1;
+ fi
+ done
+
+ if [ $flag -ne 1 ]; then
+ return;
+ fi
+
+ tmp_path=$(rsync_filename "$path");
+
+ pre_mtime=$(stat -c '%Y' "$path");
+ $CP -a "$path" "$tmp_path";
+ post_mtime=$(stat -c '%Y' "$path");
+
+ if [ $pre_mtime = $post_mtime ]; then
+ chmod -t "$tmp_path";
+ $MV "$tmp_path" "$path";
+ echo "file '$path' relocated"
+ else
+ echo "file '$path' modified during defrag. skipping"
+ rm -f "$tmp_path";
+ fi
+}
+
+defrag_usage()
+{
+ echo "Usage: $0 <directory>"
+}
+
+main()
+{
+ path="$1";
+
+ if [ -z "$path" ]; then
+ defrag_usage;
+ return;
+ fi
+
+ if [ -d "$path" ]; then
+ fix_xattr "$path";
+ scan_dir "$path";
+ else
+ relocate_file "$@";
+ fi
+}
+
+main "$1"
diff --git a/extras/scale-n-defrag.sh b/extras/scale-n-defrag.sh
deleted file mode 100644
index 1031b3931..000000000
--- a/extras/scale-n-defrag.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-# This script runs over the GlusterFS mountpoint (from just one client)
-# to handle the distribution of 'data', after the distribute translator's
-# subvolumes count changes.
-#
-# (c) 2009 Gluster Inc, <http://www.gluster.com/>
-#
-#
-# Make sure the following variables are properly initialized
-
-MOUNTPOINT=/tmp/testdir
-directory_to_be_scaled="${MOUNTPOINT}/"
-
-logdir=$(dirname $0)
-cd $logdir
-LOGDIR=$(pwd)
-cd -
-
-# The below command is enough to make sure the new layout will be scaled across new
-# nodes.
-find ${directory_to_be_scaled} -type d -exec setfattr -x "trusted.glusterfs.dht" {} \;
-
-# Now do a lookup on files so the scaling/re-hashing is done
-find ${directory_to_be_scaled} > /dev/null
-
-
-# copy the defrag (to copy data across for new nodes (for linkfiles))
-#
-
-
-cd ${directory_to_be_scaled};
-for dir in *; do
- echo "Defragmenting directory ${directory_to_be_scaled}/$dir ($LOGDIR/defrag-store-$dir.log)"
- $LOGDIR/defrag.sh $dir >> $LOGDIR/defrag-store-$dir.log 2>&1
- echo Completed directory ${directory_to_be_scaled}/$dir
-done
diff --git a/extras/volgen/CreateVolfile.py b/extras/volgen/CreateVolfile.py
index ca5043a8d..378766cf7 100644
--- a/extras/volgen/CreateVolfile.py
+++ b/extras/volgen/CreateVolfile.py
@@ -270,6 +270,7 @@ class CreateVolfile:
exp_fd.write ("# option background-unlink yes # (default: no) boolean type\n")
exp_fd.write (" option directory %s\n" % export)
+ exp_fd.write (" option hostname %s\n" % host)
exp_fd.write ("end-volume\n\n")
if self.nfs: