Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions plugin/storage/cassandra/schema/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ if [[ $keyspace =~ [^a-zA-Z0-9_] ]]; then
usage "invalid characters in KEYSPACE=$keyspace parameter, please use letters, digits or underscores"
fi

if [ ! -z "$COMPACTION_WINDOW" ]; then
if echo "$COMPACTION_WINDOW" | grep -E -q '^[0-9]+[mhd]$'; then
compaction_window_size="$(echo "$COMPACTION_WINDOW" | sed 's/[mhd]//')"
compaction_window_unit="$(echo "$COMPACTION_WINDOW" | sed 's/[0-9]//g')"
else
usage "Invalid compaction window size format. Please use numeric value followed by 'm' for minutes, 'h' for hours, or 'd' for days."
fi
else
trace_ttl_minutes=$(( $trace_ttl / 60 ))
# Taking the ceiling of the result
compaction_window_size=$(( ($trace_ttl_minutes + 30 - 1) / 30 ))
compaction_window_unit="m"
fi

case "$compaction_window_unit" in
m) compaction_window_unit="MINUTES" ;;
h) compaction_window_unit="HOURS" ;;
d) compaction_window_unit="DAYS" ;;
esac

>&2 cat <<EOF
Using template file $template with parameters:
mode = $MODE
Expand All @@ -67,13 +87,17 @@ Using template file $template with parameters:
replication = ${replication}
trace_ttl = ${trace_ttl}
dependencies_ttl = ${dependencies_ttl}
compaction_window_size = ${compaction_window_size}
compaction_window_unit = ${compaction_window_unit}
EOF

# strip out comments, collapse multiple adjacent empty lines (cat -s), substitute variables
cat $template | sed \
-e 's/--.*$//g' \
-e 's/^\s*$//g' \
-e "s/\${keyspace}/${keyspace}/g" \
-e "s/\${replication}/${replication}/g" \
-e "s/\${trace_ttl}/${trace_ttl}/g" \
-e "s/\${dependencies_ttl}/${dependencies_ttl}/g" | cat -s
-e 's/--.*$//g' \
-e 's/^\s*$//g' \
-e "s/\${keyspace}/${keyspace}/g" \
-e "s/\${replication}/${replication}/g" \
-e "s/\${trace_ttl}/${trace_ttl}/g" \
-e "s/\${dependencies_ttl}/${dependencies_ttl}/g" \
-e "s/\${compaction_window_size}/${compaction_window_size}/g" \
-e "s/\${compaction_window_unit}/${compaction_window_unit}/g" | cat -s
4 changes: 2 additions & 2 deletions plugin/storage/cassandra/schema/v004.cql.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ CREATE TABLE IF NOT EXISTS ${keyspace}.traces (
PRIMARY KEY (trace_id, span_id, span_hash)
)
WITH compaction = {
'compaction_window_size': '1',
'compaction_window_unit': 'HOURS',
'compaction_window_size': '${compaction_window_size}',
'compaction_window_unit': '${compaction_window_unit}',
'class': 'org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy'
}
AND default_time_to_live = ${trace_ttl}
Expand Down