Skip to content

Commit

Permalink
Add scripts: tgcmpct_logs.sh and tgdel_logs.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
umegane committed Aug 27, 2024
1 parent 5054cb0 commit 3531182
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
31 changes: 31 additions & 0 deletions scripts/tgcmpct_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Usage function
usage() {
echo "usage: tgcmpct_logs.sh <dblogdir>"
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

43 changes: 43 additions & 0 deletions scripts/tgdel_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Usage function
usage() {
echo "usage: tgdel_logs.sh <dblogdir>"
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

0 comments on commit 3531182

Please sign in to comment.