Repository: jena
Updated Branches:
  refs/heads/master bf238fe0a -> 23feb82a3


Fix some bugs in tdbloader2 script refactoring (JENA-977)

- Don't check database directory until after we will have created it and
  validated that it is a directory
- If getDriveInfo fails return empty information
- Don't try and calculate anything or print anything about drive
  information if it cannot be retrieved correctly


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/23feb82a
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/23feb82a
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/23feb82a

Branch: refs/heads/master
Commit: 23feb82a337bd88c89a60ca5ec9711bb53098a05
Parents: bf238fe
Author: Rob Vesse <[email protected]>
Authored: Thu Jul 23 15:36:25 2015 +0100
Committer: Rob Vesse <[email protected]>
Committed: Thu Jul 23 15:38:23 2015 +0100

----------------------------------------------------------------------
 apache-jena/bin/tdbloader2common |  3 +++
 apache-jena/bin/tdbloader2data   | 15 ++++++++-------
 apache-jena/bin/tdbloader2index  | 36 ++++++++++++++++++++---------------
 3 files changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/23feb82a/apache-jena/bin/tdbloader2common
----------------------------------------------------------------------
diff --git a/apache-jena/bin/tdbloader2common b/apache-jena/bin/tdbloader2common
index 2c73f7f..c6076b7 100644
--- a/apache-jena/bin/tdbloader2common
+++ b/apache-jena/bin/tdbloader2common
@@ -64,6 +64,9 @@ function getDriveInfo() {
   local DIR=$1
 
   local DRIVE_INFO=$(df "$DIR" | tail -n +2)
+  if [ -z "${DRIVE_INFO}" ]; then
+    abort 1 "Failed to get drive information for $DIR"
+  fi
   local DISK=$(echo $DRIVE_INFO | awk '{print $1}')
   local FREE_BYTES=$(echo $DRIVE_INFO | awk '{print $4}')
   local USED_PERCENT=$(echo $DRIVE_INFO | awk '{print $5}')

http://git-wip-us.apache.org/repos/asf/jena/blob/23feb82a/apache-jena/bin/tdbloader2data
----------------------------------------------------------------------
diff --git a/apache-jena/bin/tdbloader2data b/apache-jena/bin/tdbloader2data
index d0dde29..16a761f 100755
--- a/apache-jena/bin/tdbloader2data
+++ b/apache-jena/bin/tdbloader2data
@@ -217,13 +217,7 @@ if [ "$ABS_LOC" != "$LOC" ]; then
   debug "Absolute database location is $LOC"
 fi
 
-# Look for any index and data files in the directory.
-# Skip a possible configuration file
-if test -n "$(find "$LOC" -maxdepth 1 -type f ! -name 'this.*' -print -quit)"
-then 
-    abort 1 "Database location is not empty: $LOC"
-fi
-
+# Make sure LOC is a valid directory
 if [ ! -e "$LOC" ] ; then
   # If non-existent try to create
   debug "Trying to create new database directory: $LOC"
@@ -237,6 +231,13 @@ if [ ! -d "$LOC" ]; then
   abort 1 "Database location is not a directory: $LOC"
 fi
 
+# Look for any index and data files in the directory.
+# Skip a possible configuration file
+if test -n "$(find "$LOC" -maxdepth 1 -type f ! -name 'this.*' -print -quit)"
+then 
+    abort 1 "Database location is not empty: $LOC"
+fi
+
 # Prepare JVM Arguments
 JVM_ARGS=${JVM_ARGS:--Xmx1200M}
 debug "JVM Arguments are $JVM_ARGS"

http://git-wip-us.apache.org/repos/asf/jena/blob/23feb82a/apache-jena/bin/tdbloader2index
----------------------------------------------------------------------
diff --git a/apache-jena/bin/tdbloader2index b/apache-jena/bin/tdbloader2index
index 458698c..d2b6ed8 100755
--- a/apache-jena/bin/tdbloader2index
+++ b/apache-jena/bin/tdbloader2index
@@ -297,13 +297,15 @@ fi
 SORT_TEMP_DIR=$(makeAbsolute "$SORT_TEMP_DIR")
 debug "Sort Temp Directory: $SORT_TEMP_DIR"
 SORT_DRIVE_INFO=($(getDriveInfo "${SORT_TEMP_DIR}"))
-debug "Sort Temp Directory is on disk ${SORT_DRIVE_INFO[0]} which has 
${SORT_DRIVE_INFO[2]}% free space (${SORT_DRIVE_INFO[3]} bytes)"
-
-if [ "${SORT_DRIVE_INFO[2]}" -le 10 ]; then
-  warn "-----"
-  warn "Sort Temp Directory ${SORT_TEMP_DIR} is on disk ${SORT_DRIVE_INFO[0]} 
which only has ${SORT_DRIVE_INFO[2]}% free space (${SORT_DRIVE_INFO[3]} bytes) 
available"
-  warn "This may result in sort failures if the data to be indexed is large"
-  warn "-----"
+if [ "${#SORT_DRIVE_INFO[@]}" -gt 0 ]; then
+  debug "Sort Temp Directory is on disk ${SORT_DRIVE_INFO[0]} which has 
${SORT_DRIVE_INFO[2]}% free space (${SORT_DRIVE_INFO[3]} bytes)"
+
+  if [ "${SORT_DRIVE_INFO[2]}" -le 10 ]; then
+    warn "-----"
+    warn "Sort Temp Directory ${SORT_TEMP_DIR} is on disk 
${SORT_DRIVE_INFO[0]} which only has ${SORT_DRIVE_INFO[2]}% free space 
(${SORT_DRIVE_INFO[3]} bytes) available"
+    warn "This may result in sort failures if the data to be indexed is large"
+    warn "-----"
+  fi
 fi
 
 generate_index()
@@ -327,12 +329,14 @@ generate_index()
     # Verify that we have enough space to sort the data
 
     # Firstly check that the output disk has sufficient space
-    local WORK_DRIVE_INFO=($(getDriveInfo "${WORK}"))
-    if [ "${SIZE}" -ge "${WORK_DRIVE_INFO[3]}" ]; then
-      # If there is insufficient disk space then we can abort now
-      abort 1 "Insufficient free space on database drive 
${WORK_DRIVE_INFO[0]}, there are ${WORK_DRIVE_INFO[3]} bytes free but ${SIZE} 
bytes are required"
-    else
-      debug "Sufficient free space on database drive ${WORK_DRIVE_INFO[0]} to 
attempt sorting data file ${DATA} (${SIZE} bytes required from 
${WORK_DRIVE_INFO[3]} bytes free)"
+    local WORK_DRIVE_INFO=($(getDriveInfo "$LOC"))
+    if [ "${#WORK_DRIVE_INFO[@]}" -gt 0 ]; then
+      if [ "${SIZE}" -ge "${WORK_DRIVE_INFO[3]}" ]; then
+        # If there is insufficient disk space then we can abort now
+        abort 1 "Insufficient free space on database drive 
${WORK_DRIVE_INFO[0]}, there are ${WORK_DRIVE_INFO[3]} bytes free but ${SIZE} 
bytes are required"
+      else
+        debug "Sufficient free space on database drive ${WORK_DRIVE_INFO[0]} 
to attempt sorting data file ${DATA} (${SIZE} bytes required from 
${WORK_DRIVE_INFO[3]} bytes free)"
+      fi
     fi
 
     # Secondly check if there is enough space to sort in-memory or if sort may 
need to do an external sort
@@ -345,8 +349,10 @@ generate_index()
 
         # Check for disk space on temporary disk
         SORT_DRIVE_INFO=($(getDriveInfo "${SORT_TEMP_DIR}"))
-        if [ "$SIZE" -ge "${SORT_DRIVE_INFO[3]}" ]; then
-          warn "There may be insufficient for sort to perform an external sort 
using Tempo Directory ${SORT_TEMP_DIR} (${SIZE} bytes required but only 
${SORT_DRIVE_INFO[3]} bytes free)"
+        if [ "${#SORT_DRIVE_INFO[@]}" -gt 0 ]; then
+          if [ "$SIZE" -ge "${SORT_DRIVE_INFO[3]}" ]; then
+            warn "There may be insufficient for sort to perform an external 
sort using Tempo Directory ${SORT_TEMP_DIR} (${SIZE} bytes required but only 
${SORT_DRIVE_INFO[3]} bytes free)"
+          fi
         fi
       else
         debug "Should be sufficient free memory ($FREE_MEM bytes) for sort to 
be fully in-memory"

Reply via email to