Compare commits

...
Author SHA1 Message Date
prathamesh0 b59505eab2 Add block hash to primary keys in transactions, receipts and logs tables (#100)
* Add block hash to primary keys in transactions, receipts and logs tables

* Add block hash in postgraphile triggers for transactions, receipts and logs tables

* Make indexes on transaction cid and mh_key non-unique
2022-07-07 16:21:06 +05:30
Abdul Rabbani 4e948c58ce Merge pull request #93 from vulcanize/feature/update-go
Update the go-version in build container
2022-06-20 09:28:10 -04:00
Abdul Rabbani 65b7bee7a6 Update the go-version in build container 2022-06-20 09:23:39 -04:00
nabarun 48eb594ea9 Fix docker-compose for publishing image (#91)
* Fix docker-compose for publishing image

* Add docker build in pr workflow
2022-06-14 13:03:22 +05:30
prathamesh0 a44724c3d7 Fix stored functions for in-place snapshot (#87) 2022-06-14 11:00:54 +05:30
prathamesh0 60074a945c Update instructions and docker-compose files for simplified db setup (#88) 2022-06-07 14:46:47 +05:30
Abdul Rabbani 91d30b9ea1 Merge pull request #84 from vulcanize/feature/startup-script
Update startup_script.sh
2022-05-31 12:25:55 -04:00
Abdul Rabbani 3f034d40ce Update startup_script.sh 2022-05-27 09:23:48 -04:00
Ashwin Phatak 14762a119f Merge pull request #79 from deep-stack/pm-single-node
Run migrations on a single-node TimescaleDB setup
2022-05-17 16:19:34 +05:30
prathamesh 1c4759da05 Clean up README 2022-05-17 16:01:48 +05:30
prathamesh 49daf851cc Run migrations on a single-node TimescaleDB setup 2022-05-17 15:50:55 +05:30
Ashwin Phatak b64ad6e3f7 Merge pull request #78 from deep-stack/pm-docker-job
Merge changes for docker process to build and push a docker image
2022-05-17 11:19:52 +05:30
prathamesh 0ad88f6126 Merge changes for docker process to build and push a docker image 2022-05-17 10:27:00 +05:30
Abdul Rabbani 3014e51326 Merge pull request #77 from vulcanize/feature/docker-cicd
Use a single file to build and push a docker image
2022-05-16 11:46:27 -04:00
Abdul Rabbani 972ab2f102 Allow edited release tags to run the pipeline 2022-05-13 08:03:26 -04:00
Abdul Rabbani 47d4961ea6 Require the push job to wait. 2022-05-13 07:59:13 -04:00
Abdul Rabbani 31f115540f Combine docker build and push for releases 2022-05-12 11:18:08 -04:00
Ashwin Phatak 00897cef2c Merge pull request #76 from vulcanize/pm-v4-merge
Merge latest changes from main into sharding branch
2022-05-11 15:22:53 +05:30
prathamesh bc68969abb Fix migrations naming after merge 2022-05-10 19:34:01 +05:30
Ian Norden 05600e51d2 Merge pull request #59 from vulcanize/release-v3.2.0
update the pre- and post- batch sets with new meta schema and tables
2022-03-31 12:47:32 -05:00
i-norden 201cadbd49 update the pre- and post- batch sets with new meta schema and tables 2022-03-31 12:45:27 -05:00
Ian Norden 82f28ae6ba Merge pull request #53 from vulcanize/feature/known_table
Add `known_gaps` table
2022-03-31 11:12:54 -05:00
Abdul Rabbani 63e3d66cc1 Merge branch 'main' into feature/known_table 2022-03-31 12:07:28 -04:00
Abdul Rabbani 2ffb98c6f7 Change file name 2022-03-31 12:06:11 -04:00
Abdul Rabbani b2f8f63a65 Update file name 2022-03-31 10:47:29 -04:00
Abdul Rabbani e99787242e Add Migration file 2022-03-31 10:45:11 -04:00
Ian Norden d8dbd14af8 Merge pull request #54 from deep-stack/ng-watched-addresses-v3
Add a table for watched addresses (v3)
2022-03-23 07:08:59 -05:00
nabarun 679f3e8d79 Remove GO111MODULE flag when installing goose in makefile
Passing GO111MODULE=off with go get throws error. The CI fails due to this when using the makefile.
2022-03-21 17:07:46 +05:30
Abdul Rabbani a1b75c31e9 Update schema.sql 2022-03-19 09:17:48 -04:00
Abdul Rabbani 35b40e6ff7 Add known_gaps table - DO NOT MERGE YET!!
We will probably need to change the `modulus_block_number` columns name
2022-03-18 14:35:07 -04:00
nabarun a500c1a49a Add table for watched addresses in eth_meta schema 2022-03-17 19:02:05 +05:30
30 changed files with 255 additions and 508 deletions
-25
View File
@@ -1,25 +0,0 @@
name: Docker Compose Build
on:
push:
branches:
- main
jobs:
build:
name: Run docker build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get the version
id: vars
run: echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7})
- name: Run docker build
run: make docker-build
- name: Tag docker image
run: docker tag vulcanize/ipld-eth-db docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}}
- name: Docker Login
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin
- name: Docker Push
run: docker push docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}}
+15
View File
@@ -3,6 +3,21 @@ name: Docker Build
on: [pull_request] on: [pull_request]
jobs: jobs:
build:
name: Run docker build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run docker build
run: make docker-build
test:
# Add a dummy job to avoid failing GitHub CI checks.
# Other checks to be added later.
name: Dummy job
runs-on: ubuntu-latest
steps:
- name: Run dummy job
run: echo "Empty dummy job"
# concise_migration_diff: # concise_migration_diff:
# name: Verify concise migration and generated schema # name: Verify concise migration and generated schema
# runs-on: ubuntu-latest # runs-on: ubuntu-latest
+19 -2
View File
@@ -1,11 +1,28 @@
name: Publish Docker image name: Publish Docker image
on: on:
release: release:
types: [published] types: [published, edited]
jobs: jobs:
build:
name: Run docker build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get the version
id: vars
run: echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7})
- name: Run docker build
run: make docker-build
- name: Tag docker image
run: docker tag vulcanize/ipld-eth-db docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}}
- name: Docker Login
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin
- name: Docker Push
run: docker push docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}}
push_to_registries: push_to_registries:
name: Push Docker image to Docker Hub name: Push Docker image to Docker Hub
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build
steps: steps:
- name: Get the version - name: Get the version
id: vars id: vars
@@ -21,4 +38,4 @@ jobs:
- name: Tag docker image - name: Tag docker image
run: docker tag docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}} vulcanize/ipld-eth-db:${{steps.vars.outputs.tag}} run: docker tag docker.pkg.github.com/vulcanize/ipld-eth-db/ipld-eth-db:${{steps.vars.outputs.sha}} vulcanize/ipld-eth-db:${{steps.vars.outputs.tag}}
- name: Docker Push to Docker Hub - name: Docker Push to Docker Hub
run: docker push vulcanize/ipld-eth-db:${{steps.vars.outputs.tag}} run: docker push vulcanize/ipld-eth-db:${{steps.vars.outputs.tag}}
+2 -1
View File
@@ -1 +1,2 @@
.idea/ .idea/
.vscode
+1 -6
View File
@@ -1,4 +1,4 @@
FROM golang:1.16-alpine as builder FROM golang:1.18-alpine as builder
RUN apk --update --no-cache add make git g++ linux-headers RUN apk --update --no-cache add make git g++ linux-headers
@@ -17,11 +17,6 @@ WORKDIR /app
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/startup_script.sh . COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/startup_script.sh .
# copy over files for multi-node setup
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/docker-compose.test.yml docker-multi-node/docker-compose.test.yml
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/init-access-node.sh docker-multi-node/scripts/init-access-node.sh
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/scripts/init-data-node.sh docker-multi-node/scripts/init-data-node.sh
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/db/migrations migrations/vulcanizedb COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-db/db/migrations migrations/vulcanizedb
+2 -2
View File
@@ -8,7 +8,7 @@ BIN = $(GOPATH)/bin
## Migration tool ## Migration tool
GOOSE = $(BIN)/goose GOOSE = $(BIN)/goose
$(BIN)/goose: $(BIN)/goose:
GO111MODULE=off go get -u github.com/pressly/goose/cmd/goose go get -u github.com/pressly/goose/cmd/goose
.PHONY: installtools .PHONY: installtools
installtools: | $(GOOSE) installtools: | $(GOOSE)
@@ -115,7 +115,7 @@ import:
## Build docker image with schema ## Build docker image with schema
.PHONY: docker-build .PHONY: docker-build
docker-build: docker-build:
docker-compose build docker-compose -f docker-compose.test.yml build
## Build docker image for migration ## Build docker image for migration
.PHONY: docker-concise-migration-build .PHONY: docker-concise-migration-build
+11 -21
View File
@@ -12,34 +12,24 @@ Schemas and utils for IPLD ETH Postgres database
docker-compose down -v --remove-orphans docker-compose down -v --remove-orphans
``` ```
* Spin up an access node and three data nodes using [docker-compose.test.yml](./docker-compose.test.yml): * Spin up `ipld-eth-db` using an existing image:
```bash * Update image source used for running the migrations in [docker-compose.yml](./docker-compose.yml) (if required).
docker-compose -f docker-compose.test.yml up
```
Following final output should be seen on all the nodes: * Run:
``` ```
LOG: TimescaleDB background worker launcher connected to shared catalogs docker-compose -f docker-compose.yml up
``` ```
* Edit [startup_script.sh](./scripts/startup_script.sh) to change the number of migrations to be run: * Spin up `ipld-eth-db` using a locally built image:
```bash * Update [Dockerfile](./Dockerfile) (if required).
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up-to 21
```
* In another `ipld-eth-db` terminal window, build an image `migrations-test` using [Dockerfile](./db/Dockerfile): * Update build context used for running the migrations in [docker-compose.test.yml](./docker-compose.test.yml) (if required).
```bash * Run:
docker build -t migrations-test -f ./db/Dockerfile .
```
* After the access and data nodes have spun up, start a container using `migrations-test` image to run the db migrations: ```
docker-compose -f docker-compose.test.yml up --build
```bash ```
# Here, we are running the container using host network.
# So connect to access node on 127.0.0.1:8066
docker run --rm --network host -e DATABASE_USER=postgres -e DATABASE_PASSWORD=password -e DATABASE_HOSTNAME=127.0.0.1 -e DATABASE_PORT=8066 -e DATABASE_NAME=vulcanize_testing_v4 migrations-test
```
+1 -1
View File
@@ -1,4 +1,4 @@
FROM golang:1.16-alpine as builder FROM golang:1.18-alpine as builder
RUN apk --update --no-cache add make git g++ linux-headers RUN apk --update --no-cache add make git g++ linux-headers
@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS eth.transaction_cids (
tx_data BYTEA, tx_data BYTEA,
tx_type INTEGER, tx_type INTEGER,
value NUMERIC, value NUMERIC,
PRIMARY KEY (tx_hash, block_number) PRIMARY KEY (tx_hash, header_id, block_number)
); );
-- +goose Down -- +goose Down
@@ -1,6 +1,7 @@
-- +goose Up -- +goose Up
CREATE TABLE IF NOT EXISTS eth.receipt_cids ( CREATE TABLE IF NOT EXISTS eth.receipt_cids (
block_number BIGINT NOT NULL, block_number BIGINT NOT NULL,
header_id VARCHAR(66) NOT NULL,
tx_id VARCHAR(66) NOT NULL, tx_id VARCHAR(66) NOT NULL,
leaf_cid TEXT NOT NULL, leaf_cid TEXT NOT NULL,
contract VARCHAR(66), contract VARCHAR(66),
@@ -9,7 +10,7 @@ CREATE TABLE IF NOT EXISTS eth.receipt_cids (
post_state VARCHAR(66), post_state VARCHAR(66),
post_status INTEGER, post_status INTEGER,
log_root VARCHAR(66), log_root VARCHAR(66),
PRIMARY KEY (tx_id, block_number) PRIMARY KEY (tx_id, header_id, block_number)
); );
-- +goose Down -- +goose Down
@@ -1,6 +1,7 @@
-- +goose Up -- +goose Up
CREATE TABLE IF NOT EXISTS eth.log_cids ( CREATE TABLE IF NOT EXISTS eth.log_cids (
block_number BIGINT NOT NULL, block_number BIGINT NOT NULL,
header_id VARCHAR(66) NOT NULL,
leaf_cid TEXT NOT NULL, leaf_cid TEXT NOT NULL,
leaf_mh_key TEXT NOT NULL, leaf_mh_key TEXT NOT NULL,
rct_id VARCHAR(66) NOT NULL, rct_id VARCHAR(66) NOT NULL,
@@ -11,7 +12,7 @@ CREATE TABLE IF NOT EXISTS eth.log_cids (
topic2 VARCHAR(66), topic2 VARCHAR(66),
topic3 VARCHAR(66), topic3 VARCHAR(66),
log_data BYTEA, log_data BYTEA,
PRIMARY KEY (rct_id, index, block_number) PRIMARY KEY (rct_id, index, header_id, block_number)
); );
-- +goose Down -- +goose Down
+6 -2
View File
@@ -14,13 +14,14 @@ CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id);
-- transaction indexes -- transaction indexes
CREATE INDEX tx_block_number_index ON eth.transaction_cids USING brin (block_number); CREATE INDEX tx_block_number_index ON eth.transaction_cids USING brin (block_number);
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
CREATE UNIQUE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid, block_number); CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid, block_number);
CREATE UNIQUE INDEX tx_mh_block_number_index ON eth.transaction_cids USING btree (mh_key, block_number); CREATE INDEX tx_mh_block_number_index ON eth.transaction_cids USING btree (mh_key, block_number);
CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst);
CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src);
-- receipt indexes -- receipt indexes
CREATE INDEX rct_block_number_index ON eth.receipt_cids USING brin (block_number); CREATE INDEX rct_block_number_index ON eth.receipt_cids USING brin (block_number);
CREATE INDEX rct_header_id_index ON eth.receipt_cids USING btree (header_id);
CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid);
CREATE INDEX rct_leaf_mh_block_number_index ON eth.receipt_cids USING btree (leaf_mh_key, block_number); CREATE INDEX rct_leaf_mh_block_number_index ON eth.receipt_cids USING btree (leaf_mh_key, block_number);
CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract); CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
@@ -55,6 +56,7 @@ CREATE INDEX access_list_storage_keys_index ON eth.access_list_elements USING gi
-- log indexes -- log indexes
CREATE INDEX log_block_number_index ON eth.log_cids USING brin (block_number); CREATE INDEX log_block_number_index ON eth.log_cids USING brin (block_number);
CREATE INDEX log_header_id_index ON eth.log_cids USING btree (header_id);
CREATE INDEX log_leaf_mh_block_number_index ON eth.log_cids USING btree (leaf_mh_key, block_number); CREATE INDEX log_leaf_mh_block_number_index ON eth.log_cids USING btree (leaf_mh_key, block_number);
CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid);
CREATE INDEX log_address_index ON eth.log_cids USING btree (address); CREATE INDEX log_address_index ON eth.log_cids USING btree (address);
@@ -72,6 +74,7 @@ DROP INDEX eth.log_topic0_index;
DROP INDEX eth.log_address_index; DROP INDEX eth.log_address_index;
DROP INDEX eth.log_cid_index; DROP INDEX eth.log_cid_index;
DROP INDEX eth.log_leaf_mh_block_number_index; DROP INDEX eth.log_leaf_mh_block_number_index;
DROP INDEX eth.log_header_id_index;
DROP INDEX eth.log_block_number_index; DROP INDEX eth.log_block_number_index;
-- access list indexes -- access list indexes
@@ -106,6 +109,7 @@ DROP INDEX eth.rct_contract_hash_index;
DROP INDEX eth.rct_contract_index; DROP INDEX eth.rct_contract_index;
DROP INDEX eth.rct_leaf_mh_block_number_index; DROP INDEX eth.rct_leaf_mh_block_number_index;
DROP INDEX eth.rct_leaf_cid_index; DROP INDEX eth.rct_leaf_cid_index;
DROP INDEX eth.rct_header_id_index;
DROP INDEX eth.rct_block_number_index; DROP INDEX eth.rct_block_number_index;
-- transaction indexes -- transaction indexes
@@ -22,17 +22,20 @@ BEGIN
ELSIF (TG_TABLE_NAME = 'log_cids') THEN ELSIF (TG_TABLE_NAME = 'log_cids') THEN
obj := json_build_array( obj := json_build_array(
TG_TABLE_NAME, TG_TABLE_NAME,
NEW.header_id,
NEW.rct_id, NEW.rct_id,
NEW.index NEW.index
); );
ELSIF (TG_TABLE_NAME = 'receipt_cids') THEN ELSIF (TG_TABLE_NAME = 'receipt_cids') THEN
obj := json_build_array( obj := json_build_array(
TG_TABLE_NAME, TG_TABLE_NAME,
NEW.header_id,
NEW.tx_id NEW.tx_id
); );
ELSIF (TG_TABLE_NAME = 'transaction_cids') THEN ELSIF (TG_TABLE_NAME = 'transaction_cids') THEN
obj := json_build_array( obj := json_build_array(
TG_TABLE_NAME, TG_TABLE_NAME,
NEW.header_id,
NEW.tx_hash NEW.tx_hash
); );
ELSIF (TG_TABLE_NAME = 'access_list_elements') THEN ELSIF (TG_TABLE_NAME = 'access_list_elements') THEN
@@ -0,0 +1,5 @@
-- +goose Up
CREATE SCHEMA eth_meta;
-- +goose Down
DROP SCHEMA eth_meta;
-16
View File
@@ -1,16 +0,0 @@
-- +goose NO TRANSACTION
-- +goose Up
-- this is generated by a script
SELECT add_data_node('dn3', host => 'data-node-3', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
SELECT add_data_node('dn2', host => 'data-node-2', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
SELECT add_data_node('dn1', host => 'data-node-1', port => 5432, database => 'vulcanize_testing_v4', password => 'password');
CALL distributed_exec($$ CREATE SCHEMA eth $$);
-- +goose Down
-- this is generated by a script
CALL distributed_exec($$ DROP SCHEMA eth $$);
SELECT delete_data_node('dn1', force => true, if_attached => true);
SELECT delete_data_node('dn2', force => true, if_attached => true);
SELECT delete_data_node('dn3', force => true, if_attached => true);
@@ -0,0 +1,10 @@
-- +goose Up
CREATE TABLE eth_meta.watched_addresses (
address VARCHAR(66) PRIMARY KEY,
created_at BIGINT NOT NULL,
watched_at BIGINT NOT NULL,
last_filled_at BIGINT NOT NULL DEFAULT 0
);
-- +goose Down
DROP TABLE eth_meta.watched_addresses;
@@ -1,130 +0,0 @@
-- +goose Up
-- creating distributed hypertables from duplicate tables for now as we are getting the following error (while running geth
-- unit tests) if regular tables are directly converted to distributed hypertables
-- error: "cannot PREPARE a transaction that has executed LISTEN, UNLISTEN, or NOTIFY"
-- create new regular tables
CREATE TABLE eth.log_cids_i (LIKE eth.log_cids INCLUDING ALL);
CREATE TABLE eth.access_list_elements_i (LIKE eth.access_list_elements INCLUDING ALL);
CREATE TABLE eth.state_accounts_i (LIKE eth.state_accounts INCLUDING ALL);
CREATE TABLE eth.storage_cids_i (LIKE eth.storage_cids INCLUDING ALL);
CREATE TABLE eth.state_cids_i (LIKE eth.state_cids INCLUDING ALL);
CREATE TABLE eth.receipt_cids_i (LIKE eth.receipt_cids INCLUDING ALL);
CREATE TABLE eth.transaction_cids_i (LIKE eth.transaction_cids INCLUDING ALL);
CREATE TABLE eth.uncle_cids_i (LIKE eth.uncle_cids INCLUDING ALL);
CREATE TABLE eth.header_cids_i (LIKE eth.header_cids INCLUDING ALL);
CREATE TABLE public.blocks_i (LIKE public.blocks INCLUDING ALL);
-- turn them into distributed hypertables
SELECT create_distributed_hypertable('public.blocks_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.header_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.uncle_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.transaction_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.receipt_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.state_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.storage_cids_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.state_accounts_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.access_list_elements_i', 'block_number', chunk_time_interval => 32768);
SELECT create_distributed_hypertable('eth.log_cids_i', 'block_number', chunk_time_interval => 32768);
-- migrate data
INSERT INTO eth.log_cids_i (SELECT * FROM eth.log_cids);
INSERT INTO eth.access_list_elements_i (SELECT * FROM eth.access_list_elements);
INSERT INTO eth.state_accounts_i (SELECT * FROM eth.state_accounts);
INSERT INTO eth.storage_cids_i (SELECT * FROM eth.storage_cids);
INSERT INTO eth.state_cids_i (SELECT * FROM eth.state_cids);
INSERT INTO eth.receipt_cids_i (SELECT * FROM eth.receipt_cids);
INSERT INTO eth.transaction_cids_i (SELECT * FROM eth.transaction_cids);
INSERT INTO eth.uncle_cids_i (SELECT * FROM eth.uncle_cids);
INSERT INTO eth.header_cids_i (SELECT * FROM eth.header_cids);
INSERT INTO public.blocks_i (SELECT * FROM public.blocks);
-- drop tables
DROP TABLE eth.log_cids;
DROP TABLE eth.access_list_elements;
DROP TABLE eth.state_accounts;
DROP TABLE eth.storage_cids;
DROP TABLE eth.state_cids;
DROP TABLE eth.receipt_cids;
DROP TABLE eth.transaction_cids;
DROP TABLE eth.uncle_cids;
DROP TABLE eth.header_cids;
DROP TABLE public.blocks;
-- rename distributed hypertables
ALTER TABLE eth.log_cids_i RENAME TO log_cids;
ALTER TABLE eth.access_list_elements_i RENAME TO access_list_elements;
ALTER TABLE eth.state_accounts_i RENAME TO state_accounts;
ALTER TABLE eth.storage_cids_i RENAME TO storage_cids;
ALTER TABLE eth.state_cids_i RENAME TO state_cids;
ALTER TABLE eth.receipt_cids_i RENAME TO receipt_cids;
ALTER TABLE eth.transaction_cids_i RENAME TO transaction_cids;
ALTER TABLE eth.uncle_cids_i RENAME TO uncle_cids;
ALTER TABLE eth.header_cids_i RENAME TO header_cids;
ALTER TABLE public.blocks_i RENAME TO blocks;
CALL distributed_exec('ALTER TABLE eth.log_cids_i RENAME TO log_cids');
CALL distributed_exec('ALTER TABLE eth.access_list_elements_i RENAME TO access_list_elements');
CALL distributed_exec('ALTER TABLE eth.state_accounts_i RENAME TO state_accounts');
CALL distributed_exec('ALTER TABLE eth.storage_cids_i RENAME TO storage_cids');
CALL distributed_exec('ALTER TABLE eth.state_cids_i RENAME TO state_cids');
CALL distributed_exec('ALTER TABLE eth.receipt_cids_i RENAME TO receipt_cids');
CALL distributed_exec('ALTER TABLE eth.transaction_cids_i RENAME TO transaction_cids');
CALL distributed_exec('ALTER TABLE eth.uncle_cids_i RENAME TO uncle_cids');
CALL distributed_exec('ALTER TABLE eth.header_cids_i RENAME TO header_cids');
CALL distributed_exec('ALTER TABLE public.blocks_i RENAME TO blocks');
-- update version
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.00-dh')
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0-dh', NOW());
-- +goose Down
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0')
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0', NOW());
-- reversing conversion to hypertables requires migrating all data from every chunk back to a single table
-- create new regular tables
CREATE TABLE eth.log_cids_i (LIKE eth.log_cids INCLUDING ALL);
CREATE TABLE eth.access_list_elements_i (LIKE eth.access_list_elements INCLUDING ALL);
CREATE TABLE eth.state_accounts_i (LIKE eth.state_accounts INCLUDING ALL);
CREATE TABLE eth.storage_cids_i (LIKE eth.storage_cids INCLUDING ALL);
CREATE TABLE eth.state_cids_i (LIKE eth.state_cids INCLUDING ALL);
CREATE TABLE eth.receipt_cids_i (LIKE eth.receipt_cids INCLUDING ALL);
CREATE TABLE eth.transaction_cids_i (LIKE eth.transaction_cids INCLUDING ALL);
CREATE TABLE eth.uncle_cids_i (LIKE eth.uncle_cids INCLUDING ALL);
CREATE TABLE eth.header_cids_i (LIKE eth.header_cids INCLUDING ALL);
CREATE TABLE public.blocks_i (LIKE public.blocks INCLUDING ALL);
-- migrate data
INSERT INTO eth.log_cids_i (SELECT * FROM eth.log_cids);
INSERT INTO eth.access_list_elements_i (SELECT * FROM eth.access_list_elements);
INSERT INTO eth.state_accounts_i (SELECT * FROM eth.state_accounts);
INSERT INTO eth.storage_cids_i (SELECT * FROM eth.storage_cids);
INSERT INTO eth.state_cids_i (SELECT * FROM eth.state_cids);
INSERT INTO eth.receipt_cids_i (SELECT * FROM eth.receipt_cids);
INSERT INTO eth.transaction_cids_i (SELECT * FROM eth.transaction_cids);
INSERT INTO eth.uncle_cids_i (SELECT * FROM eth.uncle_cids);
INSERT INTO eth.header_cids_i (SELECT * FROM eth.header_cids);
INSERT INTO public.blocks_i (SELECT * FROM public.blocks);
-- drop distributed hypertables
DROP TABLE eth.log_cids;
DROP TABLE eth.access_list_elements;
DROP TABLE eth.state_accounts;
DROP TABLE eth.storage_cids;
DROP TABLE eth.state_cids;
DROP TABLE eth.receipt_cids;
DROP TABLE eth.transaction_cids;
DROP TABLE eth.uncle_cids;
DROP TABLE eth.header_cids;
DROP TABLE public.blocks;
-- rename hypertable tables
ALTER TABLE eth.log_cids_i RENAME TO log_cids;
ALTER TABLE eth.access_list_elements_i RENAME TO access_list_elements;
ALTER TABLE eth.state_accounts_i RENAME TO state_accounts;
ALTER TABLE eth.storage_cids_i RENAME TO storage_cids;
ALTER TABLE eth.state_cids_i RENAME TO state_cids;
ALTER TABLE eth.receipt_cids_i RENAME TO receipt_cids;
ALTER TABLE eth.transaction_cids_i RENAME TO transaction_cids;
ALTER TABLE eth.uncle_cids_i RENAME TO uncle_cids;
ALTER TABLE eth.header_cids_i RENAME TO header_cids;
ALTER TABLE public.blocks_i RENAME TO blocks;
@@ -0,0 +1,10 @@
-- +goose Up
CREATE TABLE eth_meta.known_gaps (
starting_block_number bigint PRIMARY KEY,
ending_block_number bigint,
checked_out boolean,
processing_key bigint
);
-- +goose Down
DROP TABLE eth_meta.known_gaps;
@@ -1,5 +0,0 @@
-- +goose Up
-- to be generated by a script
-- +goose Down
-- to be generated by a script
@@ -0,0 +1,68 @@
-- +goose Up
SELECT create_hypertable('public.blocks', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.header_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.uncle_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.transaction_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.receipt_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.state_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.storage_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.state_accounts', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.access_list_elements', 'block_number', migrate_data => true, chunk_time_interval => 32768);
SELECT create_hypertable('eth.log_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
-- update version
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0-h')
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0-h', NOW());
-- +goose Down
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0')
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0', NOW());
-- reversing conversion to hypertable requires migrating all data from every chunk back to a single table
-- create new regular tables
CREATE TABLE eth.log_cids_i (LIKE eth.log_cids INCLUDING ALL);
CREATE TABLE eth.access_list_elements_i (LIKE eth.access_list_elements INCLUDING ALL);
CREATE TABLE eth.state_accounts_i (LIKE eth.state_accounts INCLUDING ALL);
CREATE TABLE eth.storage_cids_i (LIKE eth.storage_cids INCLUDING ALL);
CREATE TABLE eth.state_cids_i (LIKE eth.state_cids INCLUDING ALL);
CREATE TABLE eth.receipt_cids_i (LIKE eth.receipt_cids INCLUDING ALL);
CREATE TABLE eth.transaction_cids_i (LIKE eth.transaction_cids INCLUDING ALL);
CREATE TABLE eth.uncle_cids_i (LIKE eth.uncle_cids INCLUDING ALL);
CREATE TABLE eth.header_cids_i (LIKE eth.header_cids INCLUDING ALL);
CREATE TABLE public.blocks_i (LIKE public.blocks INCLUDING ALL);
-- migrate data
INSERT INTO eth.log_cids_i (SELECT * FROM eth.log_cids);
INSERT INTO eth.access_list_elements_i (SELECT * FROM eth.access_list_elements);
INSERT INTO eth.state_accounts_i (SELECT * FROM eth.state_accounts);
INSERT INTO eth.storage_cids_i (SELECT * FROM eth.storage_cids);
INSERT INTO eth.state_cids_i (SELECT * FROM eth.state_cids);
INSERT INTO eth.receipt_cids_i (SELECT * FROM eth.receipt_cids);
INSERT INTO eth.transaction_cids_i (SELECT * FROM eth.transaction_cids);
INSERT INTO eth.uncle_cids_i (SELECT * FROM eth.uncle_cids);
INSERT INTO eth.header_cids_i (SELECT * FROM eth.header_cids);
INSERT INTO public.blocks_i (SELECT * FROM public.blocks);
-- drop hypertables
DROP TABLE eth.log_cids;
DROP TABLE eth.access_list_elements;
DROP TABLE eth.state_accounts;
DROP TABLE eth.storage_cids;
DROP TABLE eth.state_cids;
DROP TABLE eth.receipt_cids;
DROP TABLE eth.transaction_cids;
DROP TABLE eth.uncle_cids;
DROP TABLE eth.header_cids;
DROP TABLE public.blocks;
-- rename new tables
ALTER TABLE eth.log_cids_i RENAME TO log_cids;
ALTER TABLE eth.access_list_elements_i RENAME TO access_list_elements;
ALTER TABLE eth.state_accounts_i RENAME TO state_accounts;
ALTER TABLE eth.storage_cids_i RENAME TO storage_cids;
ALTER TABLE eth.state_cids_i RENAME TO state_cids;
ALTER TABLE eth.receipt_cids_i RENAME TO receipt_cids;
ALTER TABLE eth.transaction_cids_i RENAME TO transaction_cids;
ALTER TABLE eth.uncle_cids_i RENAME TO uncle_cids;
ALTER TABLE eth.header_cids_i RENAME TO header_cids;
ALTER TABLE public.blocks_i RENAME TO blocks;
@@ -155,26 +155,26 @@ BEGIN
END IF; END IF;
-- select all of the state nodes for this snapshot: the latest state node record at every unique path -- select all of the state nodes for this snapshot: the latest state node record at every unique path
SELECT DISTINCT ON (state_path) blocks.data, state_cids.state_leaf_key, state_cids.cid, state_cids.state_path, SELECT ARRAY (SELECT DISTINCT ON (state_path) ROW (blocks.data, state_cids.state_leaf_key, state_cids.cid, state_cids.state_path,
state_cids.node_type, state_cids.mh_key state_cids.node_type, state_cids.mh_key)
INTO results
FROM eth.state_cids FROM eth.state_cids
INNER JOIN public.blocks INNER JOIN public.blocks
ON (state_cids.mh_key, state_cids.block_number) = (blocks.key, blocks.block_number) ON (state_cids.mh_key, state_cids.block_number) = (blocks.key, blocks.block_number)
WHERE state_cids.block_number BETWEEN starting_height AND ending_height WHERE state_cids.block_number BETWEEN starting_height AND ending_height
ORDER BY state_path, block_number DESC; ORDER BY state_path, state_cids.block_number DESC)
INTO results;
-- from the set returned above, insert public.block records at the ending_height block number -- from the set returned above, insert public.block records at the ending_height block number
INSERT INTO public.blocks (block_number, key, data) INSERT INTO public.blocks (block_number, key, data)
SELECT ending_height, r.mh_key, r.data SELECT ending_height, r.mh_key, r.data
FROM results r; FROM unnest(results) r;
-- from the set returned above, insert eth.state_cids records at the ending_height block number -- from the set returned above, insert eth.state_cids records at the ending_height block number
-- anchoring all the records to the canonical header found at ending_height -- anchoring all the records to the canonical header found at ending_height
INSERT INTO eth.state_cids (block_number, header_id, state_leaf_key, cid, state_path, node_type, diff, mh_key) INSERT INTO eth.state_cids (block_number, header_id, state_leaf_key, cid, state_path, node_type, diff, mh_key)
SELECT ending_height, canonical_hash, r.state_leaf_key, r.cid, r.state_path, r.node_type, false, r.mh_key SELECT ending_height, canonical_hash, r.state_leaf_key, r.cid, r.state_path, r.node_type, false, r.mh_key
FROM results r FROM unnest(results) r
ON CONFLICT (state_path, header_id) DO NOTHING; ON CONFLICT (state_path, header_id, block_number) DO NOTHING;
END END
$BODY$ $BODY$
LANGUAGE 'plpgsql'; LANGUAGE 'plpgsql';
@@ -208,29 +208,29 @@ BEGIN
END IF; END IF;
-- select all of the storage nodes for this snapshot: the latest storage node record at every unique state leaf key -- select all of the storage nodes for this snapshot: the latest storage node record at every unique state leaf key
SELECT DISTINCT ON (state_leaf_key, storage_path) block.data, storage_cids.state_path, storage_cids.storage_leaf_key, SELECT ARRAY (SELECT DISTINCT ON (state_leaf_key, storage_path) ROW (blocks.data, storage_cids.state_path, storage_cids.storage_leaf_key,
storage_cids.cid, storage_cids.storage_path, storage_cids.node_type, storage_cids.mh_key storage_cids.cid, storage_cids.storage_path, storage_cids.node_type, storage_cids.mh_key)
INTO results
FROM eth.storage_cids FROM eth.storage_cids
INNER JOIN public.blocks INNER JOIN public.blocks
ON (storage_cids.mh_key, storage_cids.block_number) = (blocks.key, blocks.block_number) ON (storage_cids.mh_key, storage_cids.block_number) = (blocks.key, blocks.block_number)
INNER JOIN eth.state_cids INNER JOIN eth.state_cids
ON (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id) ON (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
WHERE storage_cids.block_number BETWEEN starting_height AND ending_height WHERE storage_cids.block_number BETWEEN starting_height AND ending_height
ORDER BY state_path, storage_path, block_number DESC; ORDER BY state_leaf_key, storage_path, storage_cids.state_path, storage_cids.block_number DESC)
INTO results;
-- from the set returned above, insert public.block records at the ending_height block number -- from the set returned above, insert public.block records at the ending_height block number
INSERT INTO public.blocks (block_number, key, data) INSERT INTO public.blocks (block_number, key, data)
SELECT ending_height, r.mh_key, r.data SELECT ending_height, r.mh_key, r.data
FROM results r; FROM unnest(results) r;
-- from the set returned above, insert eth.state_cids records at the ending_height block number -- from the set returned above, insert eth.state_cids records at the ending_height block number
-- anchoring all the records to the canonical header found at ending_height -- anchoring all the records to the canonical header found at ending_height
INSERT INTO eth.storage_cids (block_number, header_id, state_path, storage_leaf_key, cid, storage_path, INSERT INTO eth.storage_cids (block_number, header_id, state_path, storage_leaf_key, cid, storage_path,
node_type, diff, mh_key) node_type, diff, mh_key)
SELECT ending_height, canonical_hash, r.state_path, r.storage_leaf_key, r.cid, r.storage_path, r.node_type, false, r.mh_key SELECT ending_height, canonical_hash, r.state_path, r.storage_leaf_key, r.cid, r.storage_path, r.node_type, false, r.mh_key
FROM results r FROM unnest(results) r
ON CONFLICT (storage_path, state_path, header_id) DO NOTHING; ON CONFLICT (storage_path, state_path, header_id, block_number) DO NOTHING;
END END
$BODY$ $BODY$
LANGUAGE 'plpgsql'; LANGUAGE 'plpgsql';
@@ -1,27 +0,0 @@
-- +goose Up
-- to be generated by a script
SELECT set_replication_factor('public.blocks', 3);
SELECT set_replication_factor('eth.header_cids', 3);
SELECT set_replication_factor('eth.uncle_cids', 3);
SELECT set_replication_factor('eth.transaction_cids', 3);
SELECT set_replication_factor('eth.receipt_cids', 3);
SELECT set_replication_factor('eth.state_cids', 3);
SELECT set_replication_factor('eth.storage_cids', 3);
SELECT set_replication_factor('eth.state_accounts', 3);
SELECT set_replication_factor('eth.access_list_elements', 3);
SELECT set_replication_factor('eth.log_cids', 3);
-- +goose Down
-- to be generated by a script
SELECT set_replication_factor('public.blocks', 1);
SELECT set_replication_factor('eth.header_cids', 1);
SELECT set_replication_factor('eth.uncle_cids', 1);
SELECT set_replication_factor('eth.transaction_cids', 1);
SELECT set_replication_factor('eth.receipt_cids', 1);
SELECT set_replication_factor('eth.state_cids', 1);
SELECT set_replication_factor('eth.storage_cids', 1);
SELECT set_replication_factor('eth.state_accounts', 1);
SELECT set_replication_factor('eth.access_list_elements', 1);
SELECT set_replication_factor('eth.log_cids', 1);
+18 -53
View File
@@ -1,62 +1,27 @@
version: '3.2' version: '3.2'
services: services:
access-node: migrations:
restart: on-failure
depends_on:
- ipld-eth-db
image: vulcanize/ipld-eth-db
# Build image using local context
build: .
environment:
DATABASE_USER: "vdbm"
DATABASE_NAME: "vulcanize_testing"
DATABASE_PASSWORD: "password"
DATABASE_HOSTNAME: "ipld-eth-db"
DATABASE_PORT: 5432
ipld-eth-db:
image: timescale/timescaledb:latest-pg14 image: timescale/timescaledb:latest-pg14
restart: always restart: always
container_name: access-node
depends_on:
- data-node-1
- data-node-2
- data-node-3
command: ["postgres", "-c", "log_statement=all"] command: ["postgres", "-c", "log_statement=all"]
environment: environment:
POSTGRES_USER: "postgres" POSTGRES_USER: "vdbm"
POSTGRES_DB: "vulcanize_testing_v4" POSTGRES_DB: "vulcanize_testing"
POSTGRES_PASSWORD: "password" POSTGRES_PASSWORD: "password"
ports: ports:
- "127.0.0.1:8066:5432" - "127.0.0.1:8077:5432"
volumes:
- ./scripts/init-access-node.sh:/docker-entrypoint-initdb.d/init-access-node.sh
data-node-1:
image: timescale/timescaledb:latest-pg14
restart: unless-stopped
container_name: data-node-1
command: ["postgres", "-c", "log_statement=all"]
environment:
POSTGRES_USER: "postgres"
POSTGRES_DB: "vulcanize_testing_v4"
POSTGRES_PASSWORD: "password"
ports:
- "127.0.0.1:8067:5432"
volumes:
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
data-node-2:
image: timescale/timescaledb:latest-pg14
restart: unless-stopped
container_name: data-node-2
command: ["postgres", "-c", "log_statement=all"]
environment:
POSTGRES_USER: "postgres"
POSTGRES_DB: "vulcanize_testing_v4"
POSTGRES_PASSWORD: "password"
ports:
- "127.0.0.1:8068:5432"
volumes:
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
data-node-3:
image: timescale/timescaledb:latest-pg14
restart: unless-stopped
container_name: data-node-3
command: ["postgres", "-c", "log_statement=all"]
environment:
POSTGRES_USER: "postgres"
POSTGRES_DB: "vulcanize_testing_v4"
POSTGRES_PASSWORD: "password"
ports:
- "127.0.0.1:8069:5432"
volumes:
- ./scripts/init-data-node.sh:/docker-entrypoint-initdb.d/init-data-node.sh
+16 -4
View File
@@ -1,14 +1,26 @@
version: '3.2' version: '3.2'
services: services:
migrations:
restart: on-failure
depends_on:
- ipld-eth-db
# Use an existing image
image: vulcanize/ipld-eth-db:v4.1.4-alpha
environment:
DATABASE_USER: "vdbm"
DATABASE_NAME: "vulcanize_testing"
DATABASE_PASSWORD: "password"
DATABASE_HOSTNAME: "ipld-eth-db"
DATABASE_PORT: 5432
ipld-eth-db: ipld-eth-db:
image: timescale/timescaledb:latest-pg14
restart: always restart: always
image: vulcanize/ipld-eth-db command: ["postgres", "-c", "log_statement=all"]
build: .
environment: environment:
POSTGRES_USER: "vdbm" POSTGRES_USER: "vdbm"
POSTGRES_DB: "vulcanize_testing" POSTGRES_DB: "vulcanize_testing"
POSTGRES_PASSWORD: "password" POSTGRES_PASSWORD: "password"
hostname: db
ports: ports:
- "127.0.0.1:8077:5432" - "127.0.0.1:8077:5432"
+47
View File
@@ -37,6 +37,13 @@ COMMENT ON EXTENSION timescaledb IS 'Enables scalable inserts and complex querie
CREATE SCHEMA eth; CREATE SCHEMA eth;
--
-- Name: eth_meta; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA eth_meta;
SET default_tablespace = ''; SET default_tablespace = '';
SET default_table_access_method = heap; SET default_table_access_method = heap;
@@ -534,6 +541,30 @@ CREATE TABLE eth.uncle_cids (
); );
--
-- Name: known_gaps; Type: TABLE; Schema: eth_meta; Owner: -
--
CREATE TABLE eth_meta.known_gaps (
starting_block_number bigint NOT NULL,
ending_block_number bigint,
checked_out boolean,
processing_key bigint
);
--
-- Name: watched_addresses; Type: TABLE; Schema: eth_meta; Owner: -
--
CREATE TABLE eth_meta.watched_addresses (
address character varying(66) NOT NULL,
created_at bigint NOT NULL,
watched_at bigint NOT NULL,
last_filled_at bigint DEFAULT 0 NOT NULL
);
-- --
-- Name: blocks; Type: TABLE; Schema: public; Owner: - -- Name: blocks; Type: TABLE; Schema: public; Owner: -
-- --
@@ -695,6 +726,22 @@ ALTER TABLE ONLY eth.uncle_cids
ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (block_hash, block_number); ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (block_hash, block_number);
--
-- Name: known_gaps known_gaps_pkey; Type: CONSTRAINT; Schema: eth_meta; Owner: -
--
ALTER TABLE ONLY eth_meta.known_gaps
ADD CONSTRAINT known_gaps_pkey PRIMARY KEY (starting_block_number);
--
-- Name: watched_addresses watched_addresses_pkey; Type: CONSTRAINT; Schema: eth_meta; Owner: -
--
ALTER TABLE ONLY eth_meta.watched_addresses
ADD CONSTRAINT watched_addresses_pkey PRIMARY KEY (address);
-- --
-- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
-138
View File
@@ -1,138 +0,0 @@
#!/bin/bash
# Guards
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] || [ -z "$5" ]
then
echo "Env variables not provided"
echo "Usage: ./add_nodes.sh <MIGRATION_FILE_PATH:string> <NODE_NAME:string> <NODE_HOST:string> <NODE_PORT:numeric/string> <NODE_DATABASE:string> <EXECUTE_SQL:bool>"
echo "Only <EXECUTE_SQL> is optional"
exit 1
fi
if [ -z "$6" ]
then
echo "EXECUTE_SQL not set, will not run statements against an access server"
else
echo "EXECUTE_SQL is set, will run stataments against an access server"
echo "Note: this mode is not recommended except in the case when the migration has already been applied with previous
nodes and we need/want to add more while still recording them in the existing migration (and adding their Down statements to said migration)"
echo "Expected environment variables:"
echo "DATABASE_HOSTNAME, DATABASE_NAME, DATABASE_PORT, DATABASE_USER"
echo "For now, DATABASE_PASSWORD will be prompted for on each psql call"
fi
# Remote DB node info
export MIGRATION_FILE_PATH=$1
export NODE_NAME=$2
export NODE_HOST=$3
export NODE_PORT=$4
export NODE_DATABASE=$5
printf "Enter the ${NODE_HOST} database password:\n"
stty -echo
read NODE_PASSWORD
stty echo
export NODE_PASSWORD
if ! [ -z "$6" ]
then
# Access DB info
echo "heeeeey"
export DATABASE_HOSTNAME=localhost
export DATABASE_PORT=5432
export DATABASE_USER=vdbm
export DATABASE_NAME=vulcanize_db
fi
# Array of distributed hypertable names
declare -a tables_names=("public.blocks" "eth.header_cid" "eth.uncle_cids" "eth.transaction_cids"
"eth.receipt_cids" "eth.state_cid" "eth.storage_cids" "eth.state_accounts"
"eth.access_list_elements" "eth.log_cids"
)
# Array to append Up statements to for later (optional) execution
declare -a up_stmts=()
echo "Writing Up and Down statements to provided migration file at ${migration_file_path}"
# Create add node statement
up_add_pg_str="SELECT add_data_node('${NODE_NAME}', host => '${NODE_HOST}', port => ${NODE_PORT}, database => '${NODE_DATABASE}', password => '${NODE_PASSWORD}');"
up_stmts+=(${up_add_pg_str})
# Insert at the 3rd line of the file
sed -i.bak '3 i\
'"${up_add_pg_str}"'
' "${MIGRATION_FILE_PATH}"
# Check for error
if [[ $? -eq 0 ]]; then
echo "Wrote Up add node statement ${up_add_pg_str}"
else
echo "Could not write Up add node statement ${up_add_pg_str}. Is the migration file path correct?"
exit 1
fi
# Create attach node statements
for table_name in "${tables_names[@]}"
do
up_attach_pg_str="SELECT attach_data_node('${NODE_NAME}', '${table_name}', if_not_attached => true);"
up_stmts+=(${up_attach_pg_str})
# Insert at the 4th line of the file
sed -i.bak '4 i\
'"${up_attach_pg_str}"'
' "${MIGRATION_FILE_PATH}"
# Check for error
if [[ $? -eq 0 ]]; then
echo "Wrote Up attach node statement ${up_attach_pg_str}"
else
echo "Could not write Up attach node statement ${up_attach_pg_str}. Is the migration file path correct?"
exit 1
fi
done
## Create detach and remove node statement
down_attach_pg_str="SELECT detach_data_node('${NODE_NAME}', force => true, if_attached = true);"
down_add_pg_str="SELECT delete_data_node('${NODE_NAME}', force => true, if_attached => true);"
# Append them at the last line in the file
sed -i.bak '$ a\
'"${down_attach_pg_str}"'
' "${MIGRATION_FILE_PATH}"
# Check for error
if [[ $? -eq 0 ]]; then
echo "Wrote Down attach node statement ${down_attach_pg_str}"
else
echo "Could not write Down attach node statement ${down_attach_pg_str}. Is the migration file path correct?"
exit 1
fi
# Append them at the last line in the file
sed -i.bak '$ a\
'"${down_add_pg_str}"'
' "${MIGRATION_FILE_PATH}"
# Check for error
if [[ $? -eq 0 ]]; then
echo "Wrote Down add node statement ${down_add_pg_str}"
else
echo "Could not write Down add node statement ${down_add_pg_str}. Is the migration file path correct?"
exit 1
fi
# Execute Up statements on the server if we are in that mode
if [ -z "$6" ]
then
echo "Done!"
exit 0
fi
echo "Executing Up statements against provided server"
for up_stmt in "${up_stmts[@]}"
do
psql -c '\x' -c "${up_stmt}" -h $DATABASE_HOSTNAME -p $DATABASE_PORT -U $DATABASE_USER -d $DATABASE_NAME -W
# Check for error
if [[ $? -eq 0 ]]; then
echo "Executed Up statement ${up_stmt}}"
else
echo "Could not execute Up statement ${up_stmt}. Is the migration file path correct?"
exit 1
fi
done
echo "Done!"
exit 0
-29
View File
@@ -1,29 +0,0 @@
#!/bin/sh
set -e
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multinode-timescaledb/multinode-config/
# To achieve good query performance you need to enable partition-wise aggregation on the access node. This pushes down aggregation queries to the data nodes.
# https://www.postgresql.org/docs/12/runtime-config-query.html#enable_partitionwise_aggregate
sed -ri "s!^#?(enable_partitionwise_aggregate)\s*=.*!\1 = on!" /var/lib/postgresql/data/postgresql.conf
grep "enable_partitionwise_aggregate" /var/lib/postgresql/data/postgresql.conf
# JIT should be set to off on the access node as JIT currently doesn't work well with distributed queries.
# https://www.postgresql.org/docs/12/runtime-config-query.html#jit
sed -ri "s!^#?(jit)\s*=.*!\1 = off!" /var/lib/postgresql/data/postgresql.conf
grep "jit" /var/lib/postgresql/data/postgresql.conf
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multinode-timescaledb/multinode-auth/
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multinode-timescaledb/multinode-auth/#password-authentication
# Set password_encryption = 'scram-sha-256' in postgresql.conf on the access node.
sed -ri "s!^#?(password_encryption)\s*=.*!\1 = 'scram-sha-256'!" /var/lib/postgresql/data/postgresql.conf
grep "password_encryption" /var/lib/postgresql/data/postgresql.conf
# Append to data/passfile *:*:*:ROLE:ROLE_PASSWORD
# This file stores the passwords for each role that the access node connects to on the data nodes.
echo "*:*:*:postgres:password">>/var/lib/postgresql/data/passfile
chmod 0600 /var/lib/postgresql/data/passfile
# Add "host all all ACCESS_NODE_IP scram-sha-256" pg_hba.conf on the data nodes.
# Skipped. Using default "host all all all scram-sha-256" for now.
-27
View File
@@ -1,27 +0,0 @@
#!/bin/sh
set -e
# https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/timescaledb-config/#timescaledb-last-tuned-string
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multi-node-setup/required-configuration/
# It is necessary to change the parameter max_prepared_transactions to a non-zero value ('150' is recommended).
# https://www.postgresql.org/docs/12/runtime-config-resource.html#max_prepared_transactions
sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 150!" /var/lib/postgresql/data/postgresql.conf
grep "max_prepared_transactions" /var/lib/postgresql/data/postgresql.conf
# Statement timeout should be disabled on the data nodes and managed through the access node configuration if desired.
# https://www.postgresql.org/docs/12/runtime-config-client.html#statement_timeout
sed -ri "s!^#?(statement_timeout)\s*=.*!\1 = 0!" /var/lib/postgresql/data/postgresql.conf
grep "statement_timeout" /var/lib/postgresql/data/postgresql.conf
# On the data nodes, set the wal_level to logical or higher to move or copy chunks between data nodes.
# https://www.postgresql.org/docs/14/runtime-config-wal.html
sed -ri "s!^#?(wal_level)\s*=.*!\1 = 'logical'!" /var/lib/postgresql/data/postgresql.conf
grep "wal_level" /var/lib/postgresql/data/postgresql.conf
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multinode-timescaledb/multinode-auth/
# https://docs.timescale.com/timescaledb/latest/how-to-guides/multinode-timescaledb/multinode-auth/#password-authentication
# Set password_encryption = 'scram-sha-256' in postgresql.conf on the data node.
sed -ri "s!^#?(password_encryption)\s*=.*!\1 = 'scram-sha-256'!" /var/lib/postgresql/data/postgresql.conf
grep "password_encryption" /var/lib/postgresql/data/postgresql.conf
+2 -2
View File
@@ -7,13 +7,13 @@ VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME
# Run the DB migrations # Run the DB migrations
echo "Connecting with: $VDB_PG_CONNECT" echo "Connecting with: $VDB_PG_CONNECT"
sleep 15
echo "Running database migrations" echo "Running database migrations"
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up-to 21 ./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up
# If the db migrations ran without err # If the db migrations ran without err
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Migration process ran successfully" echo "Migration process ran successfully"
tail -f /dev/null
else else
echo "Could not run migrations. Are the database details correct?" echo "Could not run migrations. Are the database details correct?"
exit 1 exit 1