install(clickhouse): Ensure we have the newest transactions table (#594)
See getsentry/sentry#19882 and getsentry/sentry/#19883. Fixes #587.
This commit is contained in:
		
							
								
								
									
										37
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								install.sh
									
									
									
									
									
								
							@@ -23,7 +23,7 @@ SENTRY_EXTRA_REQUIREMENTS='sentry/requirements.txt'
 | 
				
			|||||||
trap_with_arg() {
 | 
					trap_with_arg() {
 | 
				
			||||||
  func="$1" ; shift
 | 
					  func="$1" ; shift
 | 
				
			||||||
  for sig ; do
 | 
					  for sig ; do
 | 
				
			||||||
        trap "$func $sig" "$sig"
 | 
					      trap "$func $sig "'$LINENO' "$sig"
 | 
				
			||||||
  done
 | 
					  done
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -36,7 +36,7 @@ cleanup () {
 | 
				
			|||||||
  DID_CLEAN_UP=1
 | 
					  DID_CLEAN_UP=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ "$1" != "EXIT" ]; then
 | 
					  if [ "$1" != "EXIT" ]; then
 | 
				
			||||||
    echo "An error occurred, caught SIG$1";
 | 
					    echo "An error occurred, caught SIG$1 on line $2";
 | 
				
			||||||
    echo "Cleaning up..."
 | 
					    echo "Cleaning up..."
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -131,8 +131,8 @@ replace_tsdb() {
 | 
				
			|||||||
  ); then
 | 
					  ); then
 | 
				
			||||||
    tsdb_settings="SENTRY_TSDB = \"sentry.tsdb.redissnuba.RedisSnubaTSDB\"
 | 
					    tsdb_settings="SENTRY_TSDB = \"sentry.tsdb.redissnuba.RedisSnubaTSDB\"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Automatic switchover 90 days after $(date). Can be removed afterwards.
 | 
					    # Automatic switchover 90 days after $(date). Can be removed afterwards.
 | 
				
			||||||
SENTRY_TSDB_OPTIONS = {\"switchover_timestamp\": $(date +%s) + (90 * 24 * 3600)}"
 | 
					    SENTRY_TSDB_OPTIONS = {\"switchover_timestamp\": $(date +%s) + (90 * 24 * 3600)}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if grep -q 'SENTRY_TSDB_OPTIONS = ' "$SENTRY_CONFIG_PY"; then
 | 
					    if grep -q 'SENTRY_TSDB_OPTIONS = ' "$SENTRY_CONFIG_PY"; then
 | 
				
			||||||
      echo "Not attempting automatic TSDB migration due to presence of SENTRY_TSDB_OPTIONS"
 | 
					      echo "Not attempting automatic TSDB migration due to presence of SENTRY_TSDB_OPTIONS"
 | 
				
			||||||
@@ -198,6 +198,35 @@ if [ "$ZOOKEEPER_SNAPSHOT_FOLDER_EXISTS" -eq "1" ]; then
 | 
				
			|||||||
  fi
 | 
					  fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# [begin] Snuba/Clickhouse transactions table rebuild
 | 
				
			||||||
 | 
					clickhouse_query () { $dcr clickhouse clickhouse-client --host clickhouse -q "$1"; }
 | 
				
			||||||
 | 
					$dc up -d clickhouse
 | 
				
			||||||
 | 
					set +e
 | 
				
			||||||
 | 
					CLICKHOUSE_CLIENT_MAX_RETRY=5
 | 
				
			||||||
 | 
					# Wait until clickhouse server is up
 | 
				
			||||||
 | 
					until clickhouse_query 'SELECT 1' > /dev/null; do
 | 
				
			||||||
 | 
					  ((CLICKHOUSE_CLIENT_MAX_RETRY--))
 | 
				
			||||||
 | 
					  [[ CLICKHOUSE_CLIENT_MAX_RETRY -eq 0 ]] && echo "Clickhouse server failed to come up in 5 tries." && exit 1;
 | 
				
			||||||
 | 
					   echo "Trying again. Remaining tries #$CLICKHOUSE_CLIENT_MAX_RETRY"
 | 
				
			||||||
 | 
					  sleep 0.5;
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SNUBA_HAS_TRANSACTIONS_TABLE=$(clickhouse_query 'EXISTS TABLE transactions_local' | tr -d '\n\r')
 | 
				
			||||||
 | 
					SNUBA_TRANSACTIONS_NEEDS_UPDATE=$([ "$SNUBA_HAS_TRANSACTIONS_TABLE" == "1" ] && clickhouse_query 'SHOW CREATE TABLE transactions_local' | grep -v 'SAMPLE BY' || echo '')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ "$SNUBA_TRANSACTIONS_NEEDS_UPDATE" ]; then
 | 
				
			||||||
 | 
					  SNUBA_TRANSACTIONS_TABLE_CONTENTS=$(clickhouse_query "SELECT * FROM transactions_local LIMIT 1")
 | 
				
			||||||
 | 
					  if [ -z $SNUBA_TRANSACTIONS_TABLE_CONTENTS ]; then
 | 
				
			||||||
 | 
					    echo "Dropping the old transactions table from Clickhouse...";
 | 
				
			||||||
 | 
					    clickhouse_query 'DROP TABLE transactions_local'
 | 
				
			||||||
 | 
					    echo "Done."
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    echo "Seems like your Clickhouse transactions table is old and non-empty. You may experience issues if/when you have more than 10000 records in this table. See https://github.com/getsentry/sentry/pull/19882 for more information and consider disabling the 'discover2.tags_facet_enable_sampling' feature flag.";
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					# [end] Snuba/Clickhouse transactions table rebuild
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "Bootstrapping and migrating Snuba..."
 | 
					echo "Bootstrapping and migrating Snuba..."
 | 
				
			||||||
$dcr snuba-api bootstrap --force
 | 
					$dcr snuba-api bootstrap --force
 | 
				
			||||||
echo ""
 | 
					echo ""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user