Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexer-alt: Alternative indexer architecture POC #19868

Merged
merged 33 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8aac2a6
indexer-alt: initial commit
amnn Oct 12, 2024
9535f9c
indexer-alt: argument parsing
amnn Oct 12, 2024
4de178b
indexer-alt: Fetch checkpoints from remote store
amnn Oct 12, 2024
12c37e6
indexer-alt: detect transient errors and retry
amnn Oct 12, 2024
879ae95
indexer-alt: tracing and telemetry
amnn Oct 12, 2024
7405f90
indexer-alt: ingestion service
amnn Oct 13, 2024
dc9a6dc
indexer: dummy backfill, printing digests
amnn Oct 13, 2024
b24162a
chore(indexer-alt): factor out ingestion clients and errors
amnn Oct 16, 2024
7c51fa0
indexer-alt: testing ingestion service
amnn Oct 14, 2024
d71278d
indexer-alt: treat bcs deserialization errors as transient
amnn Oct 14, 2024
e457e4c
indexer-alt: tag retries with reason
amnn Oct 14, 2024
145b7e4
refactor(indexer-alt): helper to log retries
amnn Oct 14, 2024
8a1f145
indexer-alt: retry on request errors
amnn Oct 14, 2024
36d6efe
indexer-alt: cancel fetch retry
amnn Oct 14, 2024
c31deb2
indexer-alt: integration diesel
amnn Oct 14, 2024
b9784da
indexer-alt: graceful shutdown on panic
amnn Oct 14, 2024
b18512f
indexer-alt: indexing pipelines + checkpoint indexing
amnn Oct 15, 2024
9ae168b
indexer-alt: kv objects pipeline
amnn Oct 15, 2024
2336c91
indexer-alt: kv transactions pipeline
amnn Oct 16, 2024
42a37b4
indexer-alt: tx affected objects pipeline
amnn Oct 16, 2024
9bbb7e4
indexer-alt: split out tx balance changes
amnn Oct 16, 2024
0215f22
chore(indexer-alt): unpluralize StoredTxAffectedObjects
amnn Oct 16, 2024
e46025c
indexer-alt: Make tx_digest the key for kv_transactions
amnn Oct 16, 2024
fa62a00
refactor(indexer-alt): Introduce Indexer abstraction
amnn Oct 16, 2024
e54e47f
chore(indexer-alt): Fix typos
amnn Oct 16, 2024
8510766
indexer-alt: committer watermarks
amnn Oct 17, 2024
baa0f2e
chore(indexer-alt): Mention patch file in `diesel.toml`
amnn Oct 17, 2024
d27a727
easy(indexer-alt): Process checkpoint message mentions sequence number
amnn Oct 17, 2024
555bd24
indexer-alt: support checkpoint upperbound for graceful shutdown
amnn Oct 17, 2024
4441e40
indexer-alt: support only running some pipelines
amnn Oct 17, 2024
a998c2a
fix(indexer-alt): Flush pending rows before shutdown
amnn Oct 17, 2024
396fdc8
indexer-alt: --skip-watermark
amnn Oct 17, 2024
9693b7a
chore(indexer-alt): note potential experiments
amnn Oct 18, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ jobs:
- name: Indexer schema
run: |
./scripts/generate_indexer_schema.sh
- name: Indexer Alt schema
run: |
./crates/sui-indexer-alt/generate_schema.sh
# Ensure there are no uncommitted changes in the repo after running tests
- run: scripts/changed-files.sh
shell: bash
Expand Down
146 changes: 146 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ members = [
"crates/sui-graphql-rpc-client",
"crates/sui-graphql-rpc-headers",
"crates/sui-indexer",
"crates/sui-indexer-alt",
"crates/sui-indexer-builder",
"crates/sui-json",
"crates/sui-json-rpc",
Expand Down Expand Up @@ -540,6 +541,7 @@ webpki = { version = "0.102", package = "rustls-webpki", features = [
"alloc",
"std",
] }
wiremock = "0.5"
x509-parser = "0.14.0"
zstd = "0.12.3"
zeroize = "1.6.0"
Expand Down
43 changes: 43 additions & 0 deletions crates/sui-indexer-alt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "sui-indexer-alt"
version.workspace = true
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[[bin]]
name = "sui-indexer-alt"
path = "src/main.rs"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
axum.workspace = true
backoff.workspace = true
bb8 = "0.8.5"
bcs.workspace = true
clap.workspace = true
diesel = { workspace = true, features = ["chrono"] }
diesel-async = { workspace = true, features = ["bb8", "postgres", "async-connection-wrapper"] }
futures.workspace = true
prometheus.workspace = true
reqwest.workspace = true
serde.workspace = true
telemetry-subscribers.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tokio-util.workspace = true
tracing.workspace = true
url.workspace = true

mysten-metrics.workspace = true
sui-storage.workspace = true
sui-types.workspace = true

[dev-dependencies]
rand.workspace = true
wiremock.workspace = true

sui-types = { workspace = true, features = ["test-utils"] }
6 changes: 6 additions & 0 deletions crates/sui-indexer-alt/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[print_schema]
file = "src/schema.rs"
patch_file = "schema.patch"

[migrations_directory]
dir = "migrations"
77 changes: 77 additions & 0 deletions crates/sui-indexer-alt/generate_schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
# Copyright (c) Mysten Labs, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Update sui-indexer's generated src/schema.rs based on the schema after
# running all its migrations on a clean database. Expects the first argument to
# be a port to run the temporary database on (defaults to 5433).

set -x
set -e

if ! command -v git &> /dev/null; then
echo "Please install git: e.g. brew install git" >&2
exit 1
fi

for PG in psql initdb postgres pg_isready pg_ctl; do
if ! command -v $PG &> /dev/null; then
echo "Could not find $PG. Please install postgres: e.g. brew install postgresql@15" >&2
exit 1
fi
done

if ! command -v diesel &> /dev/null; then
echo "Please install diesel: e.g. cargo install diesel_cli --features postgres" >&2
exit 1
fi

REPO=$(git rev-parse --show-toplevel)

# Create a temporary directory to store the ephemeral DB.
TMP=$(mktemp -d)

# Set-up a trap to clean everything up on EXIT (stop DB, delete temp directory)
function cleanup {
pg_ctl stop -D "$TMP" -mfast
set +x
echo "Postgres STDOUT:"
cat "$TMP/db.stdout"
echo "Postgres STDERR:"
cat "$TMP/db.stderr"
set -x
rm -rf "$TMP"
}
trap cleanup EXIT

# Create a new database in the temporary directory
initdb -D "$TMP" --user postgres

# Run the DB in the background, on the port provided and capture its output
PORT=${1:-5433}
postgres -D "$TMP" -p "$PORT" -c unix_socket_directories= \
> "$TMP/db.stdout" \
2> "$TMP/db.stderr" &

# Wait for postgres to report as ready
RETRIES=0
while ! pg_isready -p "$PORT" --host "localhost" --username "postgres"; do
if [ $RETRIES -gt 5 ]; then
echo "Postgres failed to start" >&2
exit 1
fi
sleep 1
RETRIES=$((RETRIES + 1))
done

# Run all migrations on the new database
diesel migration run \
--database-url "postgres://postgres:postgrespw@localhost:$PORT" \
--migration-dir "$REPO/crates/sui-indexer-alt/migrations"

# Generate the schema.rs file, excluding partition tables and including the
# copyright notice.
diesel print-schema \
--database-url "postgres://postgres:postgrespw@localhost:$PORT" \
--patch-file "$REPO/crates/sui-indexer-alt/schema.patch" \
> "$REPO/crates/sui-indexer-alt/src/schema.rs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.

DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();
Loading
Loading