-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This table will be used to control backfill tasks. The task table keeps a history of blocks processed, but they are used for detecting a re-organization. It does not track an integration's individual progress. By introducing the intg table, we now can know the precise set of blocks that an integration has processed. This will enable a backfill task to group a set of integrations that need backfilling and process block history based on the needs of the integration. This commit also introduces the notion of e2pg.{task,intg} pruning. We keep around the last 200 blocks for each src_name / src_name,name. This should help keep queries on this table fast while also preserving history for reorgs and debugging.
- Loading branch information
1 parent
5fe392d
commit 0ce4970
Showing
5 changed files
with
230 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package e2pg | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"blake.io/pqx/pqxtest" | ||
"github.com/indexsupply/x/wpg" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
"kr.dev/diff" | ||
) | ||
|
||
func TestPruneIntg(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
pqxtest.CreateDB(t, Schema) | ||
pg, err := pgxpool.New(ctx, pqxtest.DSNForTest(t)) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
|
||
iub := newIUB(1) | ||
iub.updates[0].Name = "foo" | ||
iub.updates[0].SrcName = "bar" | ||
iub.updates[0].Num = 1 | ||
|
||
err = iub.write(ctx, pg) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
checkQuery(t, pg, `select count(*) = 1 from e2pg.intg`) | ||
|
||
err = iub.write(ctx, pg) | ||
if err == nil || !strings.Contains(err.Error(), "intg_name_src_name_num_idx1") { | ||
t.Errorf("expected 2nd write to return unique error") | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
iub.updates[0].Num = uint64(i + 2) | ||
err := iub.write(ctx, pg) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
} | ||
checkQuery(t, pg, `select count(*) = 11 from e2pg.intg`) | ||
err = PruneIntg(ctx, pg) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
checkQuery(t, pg, `select count(*) = 10 from e2pg.intg`) | ||
|
||
iub.updates[0].Name = "foo" | ||
iub.updates[0].SrcName = "baz" | ||
iub.updates[0].Num = 1 | ||
err = iub.write(ctx, pg) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
checkQuery(t, pg, `select count(*) = 1 from e2pg.intg where src_name = 'baz'`) | ||
checkQuery(t, pg, `select count(*) = 11 from e2pg.intg`) | ||
|
||
err = PruneIntg(ctx, pg) | ||
diff.Test(t, t.Fatalf, err, nil) | ||
checkQuery(t, pg, `select count(*) = 11 from e2pg.intg`) | ||
} | ||
|
||
func checkQuery(tb testing.TB, pg wpg.Conn, query string) { | ||
var found bool | ||
err := pg.QueryRow(context.Background(), query).Scan(&found) | ||
diff.Test(tb, tb.Fatalf, err, nil) | ||
if !found { | ||
tb.Errorf("query\n%s\nreturned false", query) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters