Skip to content

Partition DDL in the hot path #1570

@fbac

Description

@fbac

Currently inserting a gateway envelope can force a partition creation:

func InsertGatewayEnvelopeWithChecksStandalone(
	ctx context.Context,
	q *queries.Queries,
	row queries.InsertGatewayEnvelopeParams,
) (queries.InsertGatewayEnvelopeRow, error) {
	inserted, err := q.InsertGatewayEnvelope(ctx, row)

	if err == nil {
		return inserted, nil
	}

	if !strings.Contains(err.Error(), "no partition of relation") {
		return queries.InsertGatewayEnvelopeRow{}, err
	}

	err = q.EnsureGatewayParts(ctx, queries.EnsureGatewayPartsParams{
		OriginatorNodeID:     row.OriginatorNodeID,
		OriginatorSequenceID: row.OriginatorSequenceID,
		BandWidth:            GatewayEnvelopeBandWidth,
	})
	if err != nil {
		return queries.InsertGatewayEnvelopeRow{}, err
	}

	// retry insert
	return q.InsertGatewayEnvelope(ctx, row)
}

Even if rare, this could be avoided by using a background job that ensure partitions exists ahead of time.

Metadata

Metadata

Assignees

Labels

service/databaseItems related to the xmtpd database

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions