Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ServiceControl.Persistence.EFCore.PostgreSql.Migrations
{
/// <inheritdoc />
public partial class AddRetryBatches : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "retry_id",
table: "failed_message_retries");

migrationBuilder.AddColumn<Guid>(
name: "retry_batch_id",
table: "failed_message_retries",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

migrationBuilder.AddColumn<int>(
name: "stage_attempts",
table: "failed_message_retries",
type: "integer",
nullable: false,
defaultValue: 0);

migrationBuilder.CreateTable(
name: "retry_batch_now_forwarding",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false),
retry_batch_id = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_retry_batch_now_forwarding", x => x.id);
});

migrationBuilder.CreateTable(
name: "retry_batches",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
status = table.Column<int>(type: "integer", nullable: false),
retry_session_id = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
request_id = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
retry_type = table.Column<int>(type: "integer", nullable: false),
initial_batch_size = table.Column<int>(type: "integer", nullable: false),
start_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
last = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
staging_id = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: true),
context = table.Column<string>(type: "text", nullable: true),
originator = table.Column<string>(type: "text", nullable: true),
classifier = table.Column<string>(type: "text", nullable: true),
initiated_by_id = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: true),
initiated_by_name = table.Column<string>(type: "text", nullable: true),
operation_id = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_retry_batches", x => x.id);
});

migrationBuilder.CreateIndex(
name: "ix_failed_message_retries_retry_batch_id",
table: "failed_message_retries",
column: "retry_batch_id");

migrationBuilder.CreateIndex(
name: "ix_retry_batches_status_retry_session_id",
table: "retry_batches",
columns: new[] { "status", "retry_session_id" });
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "retry_batch_now_forwarding");

migrationBuilder.DropTable(
name: "retry_batches");

migrationBuilder.DropIndex(
name: "ix_failed_message_retries_retry_batch_id",
table: "failed_message_retries");

migrationBuilder.DropColumn(
name: "retry_batch_id",
table: "failed_message_retries");

migrationBuilder.DropColumn(
name: "stage_attempts",
table: "failed_message_retries");

migrationBuilder.AddColumn<string>(
name: "retry_id",
table: "failed_message_retries",
type: "character varying(450)",
maxLength: 450,
nullable: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,20 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("uuid")
.HasColumnName("unique_message_id");

b.Property<string>("RetryId")
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("retry_id");
b.Property<Guid>("RetryBatchId")
.HasColumnType("uuid")
.HasColumnName("retry_batch_id");

b.Property<int>("StageAttempts")
.HasColumnType("integer")
.HasColumnName("stage_attempts");

b.HasKey("UniqueMessageId")
.HasName("pk_failed_message_retries");

b.HasIndex("RetryBatchId")
.HasDatabaseName("ix_failed_message_retries_retry_batch_id");

b.ToTable("failed_message_retries", (string)null);
});

Expand Down Expand Up @@ -455,6 +461,100 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("message_redirects", (string)null);
});

modelBuilder.Entity("ServiceControl.Persistence.EFCore.Entities.RetryBatchEntity", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid")
.HasColumnName("id");

b.Property<string>("Classifier")
.HasColumnType("text")
.HasColumnName("classifier");

b.Property<string>("Context")
.HasColumnType("text")
.HasColumnName("context");

b.Property<int>("InitialBatchSize")
.HasColumnType("integer")
.HasColumnName("initial_batch_size");

b.Property<string>("InitiatedById")
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("initiated_by_id");

b.Property<string>("InitiatedByName")
.HasColumnType("text")
.HasColumnName("initiated_by_name");

b.Property<DateTime?>("Last")
.HasColumnType("timestamp with time zone")
.HasColumnName("last");

b.Property<string>("OperationId")
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("operation_id");

b.Property<string>("Originator")
.HasColumnType("text")
.HasColumnName("originator");

b.Property<string>("RequestId")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("request_id");

b.Property<string>("RetrySessionId")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("retry_session_id");

b.Property<int>("RetryType")
.HasColumnType("integer")
.HasColumnName("retry_type");

b.Property<string>("StagingId")
.HasMaxLength(450)
.HasColumnType("character varying(450)")
.HasColumnName("staging_id");

b.Property<DateTime>("StartTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("start_time");

b.Property<int>("Status")
.HasColumnType("integer")
.HasColumnName("status");

b.HasKey("Id")
.HasName("pk_retry_batches");

b.HasIndex("Status", "RetrySessionId")
.HasDatabaseName("ix_retry_batches_status_retry_session_id");

b.ToTable("retry_batches", (string)null);
});

modelBuilder.Entity("ServiceControl.Persistence.EFCore.Entities.RetryBatchNowForwardingEntity", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id");

b.Property<Guid>("RetryBatchId")
.HasColumnType("uuid")
.HasColumnName("retry_batch_id");

b.HasKey("Id")
.HasName("pk_retry_batch_now_forwarding");

b.ToTable("retry_batch_now_forwarding", (string)null);
});

modelBuilder.Entity("ServiceControl.Persistence.EFCore.Entities.SubscriptionEntity", b =>
{
b.Property<string>("MessageType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ ON CONFLICT (id) DO NOTHING
}
}

public async Task InsertMissingRetryClaims(ServiceControlDbContext dbContext, IReadOnlyList<FailedMessageRetryEntity> rows, CancellationToken cancellationToken)
{
foreach (var chunk in rows.Chunk(MaxRowsPerStatement))
{
await Execute(
dbContext,
$"""
INSERT INTO failed_message_retries (unique_message_id, retry_batch_id, stage_attempts)
VALUES
{ParameterRows(chunk.Length, 3)}
ON CONFLICT (unique_message_id) DO NOTHING
""",
chunk.Select(retry => new object?[] { retry.UniqueMessageId, retry.RetryBatchId, retry.StageAttempts }),
cancellationToken);
}
}

static async Task Execute(ServiceControlDbContext dbContext, string sql, IEnumerable<object?[]> rows, CancellationToken cancellationToken)
{
await using var command = dbContext.Database.GetDbConnection().CreateCommand();
Expand Down
Loading
Loading