Skip to content

Commit

Permalink
fix: deactivate indices before subdomain import
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Feb 28, 2022
1 parent ba2d4de commit 949a131
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
16 changes: 16 additions & 0 deletions src/import-v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ export async function importV1BnsData(db: PgDataStore, importDir: string) {
const client = await db.pool.connect();
try {
await client.query('BEGIN');
// Temporarily disable BNS table indices to speed up INSERTs.
await client.query(`
UPDATE pg_index
SET indisready = false, indisvalid = false
WHERE indrelid = ANY (
SELECT oid FROM pg_class
WHERE relname IN ('subdomains', 'zonefiles', 'namespaces', 'names')
)
`);
const zhashes = await readZones(path.join(importDir, 'name_zonefiles.txt'));
await pipeline(
fs.createReadStream(path.join(importDir, 'chainstate.txt')),
Expand Down Expand Up @@ -458,13 +467,20 @@ export async function importV1BnsData(db: PgDataStore, importDir: string) {
logger.info(`Subdomains imported: ${subdomainsImported}`);
}
}
logger.info(`Subdomains imported: ${subdomainsImported}`);

const updatedConfigState: DbConfigState = {
...configState,
bns_names_onchain_imported: true,
bns_subdomains_imported: true,
};
await db.updateConfigState(updatedConfigState, client);

// Re-enable indices
await client.query(`REINDEX TABLE subdomains`);
await client.query(`REINDEX TABLE zonefiles`);
await client.query(`REINDEX TABLE namespaces`);
await client.query(`REINDEX TABLE names`);
await client.query('COMMIT');
} catch (error) {
await client.query('ROLLBACK');
Expand Down
6 changes: 0 additions & 6 deletions src/migrations/1608030374841_namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,5 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
});

pgm.createIndex('namespaces', 'namespace_id', { method: 'hash' });
pgm.createIndex('namespaces', 'microblock_hash', { method: 'hash' });
pgm.createIndex('namespaces', [{ name: 'ready_block', sort: 'DESC' }]);
pgm.createIndex('namespaces', [
{ name: 'namespace_id' },
{ name: 'ready_block', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
]);
}
7 changes: 0 additions & 7 deletions src/migrations/1608030374842_names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,5 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createIndex('names', 'name', { method: 'hash' });
pgm.createIndex('names', 'namespace_id', { method: 'hash' });
pgm.createIndex('names', 'zonefile_hash', { method: 'hash' });
pgm.createIndex('names', 'index_block_hash', { method: 'hash' });
pgm.createIndex('names', 'microblock_hash', { method: 'hash' });
pgm.createIndex('names', [{ name: 'registered_at', sort: 'DESC' }]);
pgm.createIndex('names', [
{ name: 'name' },
{ name: 'registered_at', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
]);
}
11 changes: 2 additions & 9 deletions src/migrations/1610030345948_subdomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
});

pgm.createIndex('subdomains', 'owner', { method: 'hash' });
pgm.createIndex('subdomains', 'tx_id', { method: 'hash' });
pgm.createIndex('subdomains', 'index_block_hash', { method: 'hash' });
pgm.createIndex('subdomains', 'microblock_hash', { method: 'hash' });
pgm.createIndex('subdomains', 'name', { method: 'hash' });
pgm.createIndex('subdomains', 'zonefile_hash', { method: 'hash' });
pgm.createIndex('subdomains', 'fully_qualified_subdomain', { method: 'hash' });
pgm.createIndex('subdomains', [
{ name: 'fully_qualified_subdomain' },
{ name: 'block_height', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
]);
pgm.createIndex('subdomains', [{ name: 'block_height', sort: 'DESC' }]);
}

0 comments on commit 949a131

Please sign in to comment.