sh sweep.sh
sh sweep.sh
sh sweep.sh
#!/bin/bash
# author: Bryan zhao
# date: 2025-07-29 user="gbase"
passwd="******"
threads_num=2 # Concurrency
suffix="n1" # Typically scan one shard only
avg_sum=2 # Mark table if avg extents exceed this > tb.list
if [ ! -d "`pwd`/log" ]; then mkdir -p "`pwd`/log"
else rm -rf "`pwd`/log" mkdir -p "`pwd`/log"
fi cli="${GCLUSTER_HOME}/bin/gbase -u${user} -p${passwd} -N"
$cli -e "SELECT dbname,tbname FROM gbase.table_distribution where dbname not in ('information_schema','performance_schema','gbase','gctmpdb','gclusterdb')" > tb.list child() { local dbname=$1 tbname=$2 suffix=$3 avg_sum=$4 local mulu="${GBASE_BASE}/userdata/gbase/${dbname}/sys_tablespace/${tbname}_${suffix}" [ ! -d "$mulu" ] && { echo "Error: Directory $mulu not found"; return 1; } local avg_extents=$(find "$mulu" -type f -exec filefrag -v {} \; 2>/dev/null | grep "extent" | awk '{sum+=$2} END {print (NR>0)? sum/NR : 0}') if (( $(echo "$avg_extents > $avg_sum" | bc -l) )); then touch "`pwd`/log/${dbname}.${tbname}" fi
} tmp_fifofile="/tmp/$$_`date +%N`.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm -rf $tmp_fifofile for i in `seq 1 ${threads_num}`
do echo >&6
done while read -r db table
do read -u6 { child ${db} ${table} ${suffix} ${avg_sum} echo >&6 }&
done < tb.list wait
exec 6>&-
#!/bin/bash
# author: Bryan zhao
# date: 2025-07-29 user="gbase"
passwd="******"
threads_num=2 # Concurrency
suffix="n1" # Typically scan one shard only
avg_sum=2 # Mark table if avg extents exceed this > tb.list
if [ ! -d "`pwd`/log" ]; then mkdir -p "`pwd`/log"
else rm -rf "`pwd`/log" mkdir -p "`pwd`/log"
fi cli="${GCLUSTER_HOME}/bin/gbase -u${user} -p${passwd} -N"
$cli -e "SELECT dbname,tbname FROM gbase.table_distribution where dbname not in ('information_schema','performance_schema','gbase','gctmpdb','gclusterdb')" > tb.list child() { local dbname=$1 tbname=$2 suffix=$3 avg_sum=$4 local mulu="${GBASE_BASE}/userdata/gbase/${dbname}/sys_tablespace/${tbname}_${suffix}" [ ! -d "$mulu" ] && { echo "Error: Directory $mulu not found"; return 1; } local avg_extents=$(find "$mulu" -type f -exec filefrag -v {} \; 2>/dev/null | grep "extent" | awk '{sum+=$2} END {print (NR>0)? sum/NR : 0}') if (( $(echo "$avg_extents > $avg_sum" | bc -l) )); then touch "`pwd`/log/${dbname}.${tbname}" fi
} tmp_fifofile="/tmp/$$_`date +%N`.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm -rf $tmp_fifofile for i in `seq 1 ${threads_num}`
do echo >&6
done while read -r db table
do read -u6 { child ${db} ${table} ${suffix} ${avg_sum} echo >&6 }&
done < tb.list wait
exec 6>&-
#!/bin/bash
# author: Bryan zhao
# date: 2025-07-29 user="gbase"
passwd="******"
threads_num=2 # Concurrency
suffix="n1" # Typically scan one shard only
avg_sum=2 # Mark table if avg extents exceed this > tb.list
if [ ! -d "`pwd`/log" ]; then mkdir -p "`pwd`/log"
else rm -rf "`pwd`/log" mkdir -p "`pwd`/log"
fi cli="${GCLUSTER_HOME}/bin/gbase -u${user} -p${passwd} -N"
$cli -e "SELECT dbname,tbname FROM gbase.table_distribution where dbname not in ('information_schema','performance_schema','gbase','gctmpdb','gclusterdb')" > tb.list child() { local dbname=$1 tbname=$2 suffix=$3 avg_sum=$4 local mulu="${GBASE_BASE}/userdata/gbase/${dbname}/sys_tablespace/${tbname}_${suffix}" [ ! -d "$mulu" ] && { echo "Error: Directory $mulu not found"; return 1; } local avg_extents=$(find "$mulu" -type f -exec filefrag -v {} \; 2>/dev/null | grep "extent" | awk '{sum+=$2} END {print (NR>0)? sum/NR : 0}') if (( $(echo "$avg_extents > $avg_sum" | bc -l) )); then touch "`pwd`/log/${dbname}.${tbname}" fi
} tmp_fifofile="/tmp/$$_`date +%N`.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm -rf $tmp_fifofile for i in `seq 1 ${threads_num}`
do echo >&6
done while read -r db table
do read -u6 { child ${db} ${table} ${suffix} ${avg_sum} echo >&6 }&
done < tb.list wait
exec 6>&- - user — database user (typically gbase)
- passwd — corresponding password
- threads_num — number of parallel scanning threads (default: 2)
- suffix — shard suffix to scan (usually n1)
- avg_sum — average extent threshold to trigger a flag (default: 2)