Skip to content

Commit 4838973

Browse files
authored
exp/lighthorizon/build/index-batch: carry over map/reduce updates to latest docker layout on feature branch (#4543)
1 parent adadbcc commit 4838973

File tree

10 files changed

+129
-8
lines changed

10 files changed

+129
-8
lines changed

.github/workflows/horizon.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,27 @@ jobs:
134134
# Any range should do for basic testing, this range was chosen pretty early in history so that it only takes a few mins to run
135135
run: |
136136
chmod 755 ./exp/lighthorizon/build/build.sh
137-
./exp/lighthorizon/build/build.sh ledgerexporter stellar latest false
138-
docker run -e ARCHIVE_TARGET=file:///ledgerexport-test\
137+
mkdir $PWD/ledgerexport
138+
mkdir $PWD/index
139+
140+
./exp/lighthorizon/build/build.sh all stellar latest false
141+
docker run -e ARCHIVE_TARGET=file:///ledgerexport\
139142
-e START=5\
140-
-e END=50\
143+
-e END=150\
141144
-e NETWORK_PASSPHRASE="Test SDF Network ; September 2015"\
142145
-e CAPTIVE_CORE_CONFIG="/captive-core-testnet.cfg"\
143146
-e HISTORY_ARCHIVE_URLS="https://history.stellar.org/prd/core-testnet/core_testnet_001,https://history.stellar.org/prd/core-testnet/core_testnet_002"\
147+
-v $PWD/ledgerexport:/ledgerexport\
144148
stellar/lighthorizon-ledgerexporter
149+
150+
# run map job
151+
docker run -e NETWORK_PASSPHRASE='testnet' -e JOB_INDEX_ENV=AWS_BATCH_JOB_ARRAY_INDEX -e AWS_BATCH_JOB_ARRAY_INDEX=0 -e BATCH_SIZE=64 -e FIRST_CHECKPOINT=64 \
152+
-e WORKER_COUNT=1 -e RUN_MODE=map -v $PWD/ledgerexport:/ledgermeta -e TXMETA_SOURCE=file:///ledgermeta -v $PWD/index:/index -e INDEX_TARGET=file:///index stellar/lighthorizon-index-batch
153+
154+
# run reduce job
155+
docker run -e NETWORK_PASSPHRASE='testnet' -e JOB_INDEX_ENV=AWS_BATCH_JOB_ARRAY_INDEX -e AWS_BATCH_JOB_ARRAY_INDEX=0 -e MAP_JOB_COUNT=1 -e REDUCE_JOB_COUNT=1 \
156+
-e WORKER_COUNT=1 -e RUN_MODE=reduce -v $PWD/index:/index -e INDEX_SOURCE_ROOT=file:///index -e INDEX_TARGET=file:///index stellar/lighthorizon-index-batch
157+
145158
# Push images
146159
- if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/lighthorizon'
147160
name: Login to DockerHub
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `stellar/horizon-indexer`
2+
3+
This docker image contains the ledger/checkpoint indexing executables. It allows running multiple instances of `map`/`reduce` on a single machine or running it in [AWS Batch](https://aws.amazon.com/batch/).
4+
5+
## Env variables
6+
7+
See the [package documentation](../../index/cmd/batch/doc.go) for more details

exp/lighthorizon/build/index-batch/start

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -e
55

66
export TRACY_NO_INVARIANT_CHECK=1
77
NETWORK_PASSPHRASE="${NETWORK_PASSPHRASE:=Public Global Stellar Network ; September 2015}"
8-
98
if [ "$RUN_MODE" == "reduce" ]; then
109
echo "Running Reduce, REDUCE JOBS: $REDUCE_JOB_COUNT MAP JOBS: $MAP_JOB_COUNT TARGET INDEX: $INDEX_TARGET"
1110
/reduce
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: 'batch-map-job'
5+
spec:
6+
completions: 52
7+
parallelism: 10
8+
completionMode: Indexed
9+
template:
10+
spec:
11+
restartPolicy: Never
12+
containers:
13+
- name: 'worker'
14+
image: 'stellar/lighthorizon-index-batch'
15+
imagePullPolicy: Always
16+
envFrom:
17+
- secretRef:
18+
name: <reference to secret name here if needed for source/target>
19+
env:
20+
- name: RUN_MODE
21+
value: "map"
22+
- name: BATCH_SIZE
23+
value: "10048"
24+
- name: FIRST_CHECKPOINT
25+
value: "41426080"
26+
- name: WORKER_COUNT
27+
value: "8"
28+
- name: TXMETA_SOURCE
29+
value: "<url of txmeta source>"
30+
- name: JOB_INDEX_ENV
31+
value: "JOB_COMPLETION_INDEX"
32+
- name: NETWORK_PASSPHRASE
33+
value: "pubnet"
34+
- name: INDEX_TARGET
35+
value: "url of target index"
36+
resources:
37+
limits:
38+
cpu: 4
39+
memory: 5Gi
40+
requests:
41+
cpu: 500m
42+
memory: 500Mi
43+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: 'batch-reduce-job'
5+
spec:
6+
completions: 52
7+
parallelism: 10
8+
completionMode: Indexed
9+
template:
10+
spec:
11+
restartPolicy: Never
12+
containers:
13+
- name: 'worker'
14+
image: 'stellar/lighthorizon-index-batch'
15+
imagePullPolicy: Always
16+
envFrom:
17+
- secretRef:
18+
name: <reference to secret name here if needed for source/target>
19+
env:
20+
- name: RUN_MODE
21+
value: "reduce"
22+
- name: MAP_JOB_COUNT
23+
value: 52
24+
- name: REDUCE_JOB_COUNT
25+
value: 52
26+
- name: WORKER_COUNT
27+
value: 8
28+
- name: INDEX_SOURCE_ROOT
29+
value: "<url of index location>"
30+
- name: JOB_INDEX_ENV
31+
value: JOB_COMPLETION_INDEX
32+
- name: INDEX_TARGET
33+
value: "<url of index location>"
34+
resources:
35+
limits:
36+
cpu: 4
37+
memory: 5Gi
38+
requests:
39+
cpu: 500m
40+
memory: 500Mi
41+
42+

exp/lighthorizon/index/backend/file.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ type FileBackend struct {
2020
parallel uint32
2121
}
2222

23+
// NewFileBackend connects to indices stored at `dir`, creating the directory if one doesn't
24+
// exist, and uses `parallel` to control how many workers to use when flushing to disk.
2325
func NewFileBackend(dir string, parallel uint32) (*FileBackend, error) {
2426
if parallel <= 0 {
2527
parallel = 1
2628
}
2729

30+
err := os.MkdirAll(dir, fs.ModeDir|0755)
31+
if err != nil {
32+
log.Errorf("Unable to mkdir %s, %v", dir, err)
33+
return nil, err
34+
}
35+
2836
return &FileBackend{
2937
dir: dir,
3038
parallel: parallel,

exp/lighthorizon/index/cmd/batch/map/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type BatchConfig struct {
2424

2525
const (
2626
batchSizeEnv = "BATCH_SIZE"
27-
jobIndexEnv = "AWS_BATCH_JOB_ARRAY_INDEX"
27+
jobIndexEnvName = "JOB_INDEX_ENV"
2828
firstCheckpointEnv = "FIRST_CHECKPOINT"
2929
txmetaSourceUrlEnv = "TXMETA_SOURCE"
3030
indexTargetUrlEnv = "INDEX_TARGET"
@@ -39,6 +39,10 @@ func NewBatchConfig() (*BatchConfig, error) {
3939
return nil, errors.New("required parameter: " + indexTargetUrlEnv)
4040
}
4141

42+
jobIndexEnv := os.Getenv(jobIndexEnvName)
43+
if jobIndexEnv == "" {
44+
return nil, errors.New("env variable can't be empty " + jobIndexEnvName)
45+
}
4246
jobIndex, err := strconv.ParseUint(os.Getenv(jobIndexEnv), 10, 32)
4347
if err != nil {
4448
return nil, errors.Wrap(err, "invalid parameter "+jobIndexEnv)

exp/lighthorizon/index/cmd/batch/reduce/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ func ReduceConfigFromEnvironment() (*ReduceConfig, error) {
3737
mapJobsEnv = "MAP_JOB_COUNT"
3838
reduceJobsEnv = "REDUCE_JOB_COUNT"
3939
workerCountEnv = "WORKER_COUNT"
40-
jobIndexEnv = "AWS_BATCH_JOB_ARRAY_INDEX"
40+
jobIndexEnvName = "JOB_INDEX_ENV"
4141
indexRootSourceEnv = "INDEX_SOURCE_ROOT"
4242
indexTargetEnv = "INDEX_TARGET"
4343
)
4444

45+
jobIndexEnv := os.Getenv(jobIndexEnvName)
46+
if jobIndexEnv == "" {
47+
return nil, errors.New("env variable can't be empty " + jobIndexEnvName)
48+
}
49+
4550
jobIndex, err := strconv.ParseUint(strings.TrimSpace(os.Getenv(jobIndexEnv)), 10, 32)
4651
if err != nil {
4752
return nil, errors.Wrap(err, "invalid parameter "+jobIndexEnv)

exp/lighthorizon/index/cmd/map.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ for (( i=0; i < $BATCH_COUNT; i++ ))
6868
do
6969
echo -n "Creating map job $i... "
7070

71-
NETWORK_PASSPHRASE='testnet' MODULES='accounts_unbacked,transactions' \
71+
NETWORK_PASSPHRASE='testnet' JOB_INDEX_ENV='AWS_BATCH_JOB_ARRAY_INDEX' MODULES='accounts_unbacked,transactions' \
7272
AWS_BATCH_JOB_ARRAY_INDEX=$i BATCH_SIZE=$BATCH_SIZE FIRST_CHECKPOINT=$FIRST \
7373
TXMETA_SOURCE=file://$1 INDEX_TARGET=file://$2 WORKER_COUNT=1 \
7474
./map &

exp/lighthorizon/index/cmd/reduce.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ for (( i=0; i < $REDUCE_JOB_COUNT; i++ ))
4747
do
4848
echo -n "Creating reduce job $i... "
4949

50-
AWS_BATCH_JOB_ARRAY_INDEX=$i MAP_JOB_COUNT=$MAP_JOB_COUNT \
50+
AWS_BATCH_JOB_ARRAY_INDEX=$i JOB_INDEX_ENV="AWS_BATCH_JOB_ARRAY_INDEX" MAP_JOB_COUNT=$MAP_JOB_COUNT \
5151
REDUCE_JOB_COUNT=$REDUCE_JOB_COUNT WORKER_COUNT=4 \
5252
INDEX_SOURCE_ROOT=file://$1 INDEX_TARGET=file://$2 \
5353
timeout -k 30s 10s ./reduce &

0 commit comments

Comments
 (0)