diff --git a/CMakeLists.txt b/CMakeLists.txt index 0efb1b76..1b853bc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,19 @@ install( COMPONENT Runtime ) + +set(SCRIPT_DIR "${CMAKE_SOURCE_DIR}/scripts") +set(SCRIPTS + "${SCRIPT_DIR}/tgcmpct_logs.sh" + "${SCRIPT_DIR}/tgdel_logs.sh" +) + +install( + FILES ${SCRIPTS} + DESTINATION ${CMAKE_INSTALL_BINDIR} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ +) + install( DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${export_name}" diff --git a/scripts/tgcmpct_logs.sh b/scripts/tgcmpct_logs.sh new file mode 100755 index 00000000..cf841833 --- /dev/null +++ b/scripts/tgcmpct_logs.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Usage function +usage() { + echo "usage: tgcmpct_logs.sh " + exit 1 +} + +# Check arguments +if [ "$#" -ne 1 ]; then + usage +fi + +DBLOGDIR=$1 + +# Validate dblogdir +if [ ! -d "$DBLOGDIR" ] || [ ! -f "$DBLOGDIR/compaction_catalog" ] || [ ! -d "$DBLOGDIR/ctrl" ]; then + echo "Error: '$DBLOGDIR' is not a valid dblogdir." + usage +fi + +# Request to start compaction +if /usr/bin/touch "$DBLOGDIR/ctrl/start_compaction"; then + echo "Compaction request has been made." +else + echo "Error: Failed to request compaction." + exit 1 +fi + +exit 0 + diff --git a/scripts/tgdel_logs.sh b/scripts/tgdel_logs.sh new file mode 100755 index 00000000..b301d553 --- /dev/null +++ b/scripts/tgdel_logs.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Usage function +usage() { + echo "usage: tgdel_logs.sh " + exit 1 +} + +# Check arguments +if [ "$#" -ne 1 ]; then + usage +fi + +DBLOGDIR=$1 +COMPACTION_CATALOG="$DBLOGDIR/compaction_catalog" +FILES_DELETED=0 + +# Validate dblogdir and compaction_catalog +if [ ! -d "$DBLOGDIR" ] || [ ! -d "$DBLOGDIR/ctrl" ] || [ ! -f "$COMPACTION_CATALOG" ]; then + echo "Error: '$DBLOGDIR' is not a valid dblogdir." + usage +fi + +# Delete detached pwal files +while read -r line; do + if [[ $line == DETACHED_PWAL* ]]; then + FILENAME=$(echo "$line" | /usr/bin/awk '{print $2}') + FILE_TO_DELETE="$DBLOGDIR/$FILENAME" + if [ -f "$FILE_TO_DELETE" ]; then + echo "Deleting: $FILE_TO_DELETE" + /usr/bin/rm "$FILE_TO_DELETE" + FILES_DELETED=$((FILES_DELETED + 1)) + fi + fi +done < "$COMPACTION_CATALOG" + +# Check if no files were deleted +if [ "$FILES_DELETED" -eq 0 ]; then + echo "No files could be deleted." +fi + +exit 0 +