Skip to content

Commit

Permalink
sql-sink-backfill: add database scripts and rework dsn variable
Browse files Browse the repository at this point in the history
  • Loading branch information
coutug committed Jul 30, 2024
1 parent e343b79 commit 6dcdd16
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 24 deletions.
2 changes: 1 addition & 1 deletion charts/substreams-sink-sql-backfill/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.6
version: 0.0.7

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
10 changes: 0 additions & 10 deletions charts/substreams-sink-sql-backfill/create-table.sql

This file was deleted.

1 change: 0 additions & 1 deletion charts/substreams-sink-sql-backfill/drop-table.sql

This file was deleted.

74 changes: 67 additions & 7 deletions charts/substreams-sink-sql-backfill/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,47 @@ spec:
labels:
{{- include "substreams-sink-sql-backfill.labels" $ | nindent 8 }}
spec:
containers:
- name: {{ include "substreams-sink-sql-backfill.fullname" $ }}
initContainers:
# Container to create cursor tables
- name: {{ include "substreams-sink-sql-backfill.fullname" $ }}-create-tables
image: curlimages/curl:latest
command:
- "/bin/sh"
- "-c"
- |
cat <<EOF > /tmp/create-tables.sql
CREATE TABLE IF NOT EXISTS {{ $values.database }}.{{ $values.tablePrefix }}_{{ $currentBlock }}
(
id String,
cursor String,
block_num Int64,
block_id String
)
ENGINE = ReplacingMergeTree()
PRIMARY KEY (id)
ORDER BY (id);
EOF
curl -X POST 'http://{{ $values.host }}:8123/?user=$(USERNAME)&password=$(PASSWORD)' --data-binary @/tmp/create-tables.sql
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyUsername }}
- name: PASSWORD
valueFrom:
secretKeyRef:
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyPassword }}
# Container to backfill data
- name: {{ include "substreams-sink-sql-backfill.fullname" $ }}-backfill
image: "{{ $values.image.repository }}:{{ $values.image.tag }}"
{{- if $values.command }}
command:
{{- range $values.command }}
- {{ . | quote }}
{{- end }}
- "$(DSN)"
- "clickhouse://$(USERNAME):$(PASSWORD)@{{ $values.host }}:9000/{{ $values.database }}"
- "{{ $values.manifest }}"
- "{{ $currentBlock }}:{{ add $currentBlock $blockIncrement }}"
{{- end }}
Expand All @@ -45,15 +77,43 @@ spec:
{{- end }}
env:
- name: SINK_SQL_RUN_CURSORS_TABLE
value: backprocess_{{ $currentBlock }}
- name: DSN
value: {{ $values.tablePrefix }}_{{ $currentBlock }}
- name: USERNAME
valueFrom:
secretKeyRef:
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyUsername }}
- name: PASSWORD
valueFrom:
secretKeyRef:
key: {{ $values.dsn.key }}
name: {{ $values.dsn.secretName }}
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyPassword }}
envFrom:
- configMapRef:
name: env-{{ $.Release.Name }}
# Container to drop cursor tables
containers:
- name: {{ include "substreams-sink-sql-backfill.fullname" $ }}-drop-tables
image: curlimages/curl:latest
command:
- "/bin/sh"
- "-c"
- |
cat <<EOF > /tmp/drop-tables.sql
DROP TABLE {{ $values.database }}.{{ $values.tablePrefix }}_{{ $currentBlock }}
EOF
curl -X POST 'http://{{ $values.host }}:8123/?user=$(USERNAME)&password=$(PASSWORD)' --data-binary @/tmp/drop-tables.sql
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyUsername }}
- name: PASSWORD
valueFrom:
secretKeyRef:
name: {{ $values.clickhouseAuth.secretName }}
key: {{ $values.clickhouseAuth.keyPassword }}
restartPolicy: OnFailure
imagePullSecrets:
- name: {{ $values.imagePullSecret }}
Expand Down
20 changes: 15 additions & 5 deletions charts/substreams-sink-sql-backfill/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ jobAmount: 1
startBlock: 0
endBlock: -1
# spkg file to use
manifest: https://github.com/file.spkg
dsn:
secretName: sql-sink-dsn
key: dsn
manifest: myFile.spkg

# Clickhouse host name
host: myClickhouseDB
# Clickhouse database to use
database:
# Prefix to add to cursor tables being created and deleted by the backfill jobs
# By default: backprocess-<startBlock>
tablePrefix: backprocess
# Username/Password to connect to database from an existing secret
clickhouseAuth:
secretName: ch-auth
keyUsername: username
keyPassword: password
# environment variables to be use by the applications <key>: <value>
env:
substreams_endpoints_config_mainnet: substreams:9000
substreams_endpoints_config_mainnet: mySubstreams:9000
sink_sql_run_undo_buffer_size: 100
sink_sql_run_batch_row_flush_interval: 100000
sink_sql_run_batch_block_flush_interval: 20000
Expand Down

0 comments on commit 6dcdd16

Please sign in to comment.