mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
### Does this PR have any customer impact? ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) ### Are you introducing any new config? If yes, do you have tests with and without them being set? ### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md)) ### Description [OSS] Fix TTL indexes in documentdb This moves the function to C and instead of querying the indexes and then getting the collection shards from pg_dist_shard table, it uses the C hook to get the table shards where for non-distributed it returns the base table and then uses that information to drop the expired records. ---- #### AI description (iteration 1) #### PR Classification Bug fix #### PR Summary This pull request addresses issues with TTL indexes in DocumentDB by refactoring and optimizing the deletion of expired rows. - `ttl_index.c`: Refactored the function to delete expired rows, added a new function `delete_expired_rows`, and optimized the deletion process. - `ttl_support_functions--latest.sql` and `delete_expired_rows--latest.sql`: Replaced PL/pgSQL procedures with C language implementations for better performance. - `collection.c`: Moved the function `GetMongoCollectionShardOidsAndNames` from `coll_stats.c` to `collection.c` for better organization.
85 lines
3.3 KiB
Bash
Executable File
85 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e -u
|
|
|
|
|
|
source="${BASH_SOURCE[0]}"
|
|
while [[ -h $source ]]; do
|
|
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
|
|
source="$(readlink "$source")"
|
|
|
|
# if $source was a relative symlink, we need to resolve it relative to the path where the
|
|
# symlink file was located
|
|
[[ $source != /* ]] && source="$scriptroot/$source"
|
|
done
|
|
|
|
repoScriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
|
|
|
|
function ValidateNoCitusReferences()
|
|
{
|
|
local _dir_to_check=$1
|
|
|
|
# TODO: Clean these up
|
|
validationExceptions="documentdb--0.24-0.sql create_index_background--0.23-0.sql create_index_background--latest.sql drop_indexes.c create_indexes_background.c"
|
|
validationExceptions="$validationExceptions current_op.c index.c ttl_support_functions--0.24-0.sql"
|
|
validationExceptions="$validationExceptions diagnostic_commands_common.c"
|
|
|
|
foundInvalid="";
|
|
for queryStr in "citus_" "pg_dist" "run_command_on_all_nodes" "run_command_on_coordinator"; do
|
|
for f in `grep -r -l -i -E $queryStr --include "*.h" --include "*.c" --include "*.sql" $_dir_to_check`; do
|
|
fileName=$(basename $f)
|
|
if [[ $validationExceptions =~ $fileName ]]; then
|
|
echo "Allowing $f as an exception for $queryStr"
|
|
continue;
|
|
fi;
|
|
|
|
echo "Remove references to $queryStr in $f - Please introduce a distributed hook to manage citus function execution"
|
|
foundInvalid="true"
|
|
done
|
|
done
|
|
|
|
if [ "$foundInvalid" != "" ]; then
|
|
echo "Found invalid citus references"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
|
|
function CheckSqlLatestVersionMatchesLatestFile()
|
|
{
|
|
local _script_dir_prefix=$1
|
|
# check if the latest snapshot matches the latest 'version'
|
|
for script_dir in $repoScriptDir/../$_script_dir_prefix/sql/udfs/*; do
|
|
# Get the "latest" sql files:
|
|
for script_file in $( find "$script_dir" -iname "*--latest.sql" ); do
|
|
latest_file=$( basename $script_file );
|
|
file_base=${latest_file%--*};
|
|
|
|
# We want to find the last snapshotted sql file, to make sure it's the same
|
|
# as "latest.sql". This is done by:
|
|
# 1. Getting the filenames in the UDF directory (using find instead of ls, to keep shellcheck happy)
|
|
# 2. Filter out latest.sql
|
|
# 3. Sort using "version sort"
|
|
# 4. Get the last one using tail
|
|
latest_snapshot=$(\
|
|
find "$script_dir" -iname "$file_base--*.sql" -exec basename {} \; \
|
|
| { grep --invert-match latest.sql || true; } \
|
|
| sort --version-sort \
|
|
| tail --lines 1);
|
|
echo "Checking $latest_file against $latest_snapshot"
|
|
|
|
diff --unified "$script_dir/$latest_file" "$script_dir/$latest_snapshot";
|
|
done
|
|
done
|
|
}
|
|
|
|
# Ensure that citus references are done via hooks and not in the SQL/C files
|
|
ValidateNoCitusReferences $repoScriptDir/../pg_documentdb_core
|
|
ValidateNoCitusReferences $repoScriptDir/../pg_documentdb
|
|
|
|
# Validate sql files for the purposes of review and sanity.
|
|
CheckSqlLatestVersionMatchesLatestFile pg_documentdb_core
|
|
CheckSqlLatestVersionMatchesLatestFile pg_documentdb
|
|
CheckSqlLatestVersionMatchesLatestFile internal/pg_documentdb_distributed
|
|
|
|
# Ensure no header collisions
|
|
$repoScriptDir/validate_headers.sh |