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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/opsqueue_python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opsqueue_python"
version = "0.30.2"
version = "0.30.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
1 change: 1 addition & 0 deletions libs/opsqueue_python/opsqueue_python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ buildPythonPackage rec {
".toml"
".lock"
".db"
".md"
];
};

Expand Down
2 changes: 1 addition & 1 deletion opsqueue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opsqueue"
version = "0.30.1"
version = "0.30.4"
edition = "2021"
description = "lightweight batch processing queue for heavy loads"
repository = "https://github.com/channable/opsqueue"
Expand Down
3 changes: 3 additions & 0 deletions opsqueue/migrations/20250416081453_track_chunk_size.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE submissions DROP COLUMN chunk_size;
ALTER TABLE submissions_completed DROP COLUMN chunk_size;
ALTER TABLE submissions_failed DROP COLUMN chunk_size;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- 1. Drop all indexes and finally the column itself
DROP INDEX random_chunks_order;
DROP INDEX random_chunks_metadata_order;
DROP INDEX random_chunks_metadata_order2;
ALTER TABLE chunks DROP COLUMN random_order;
ALTER TABLE chunks_metadata DROP COLUMN random_order;

-- 2. Recreate the column with its **old, bad** definition
ALTER TABLE chunks ADD COLUMN random_order INTEGER NOT NULL GENERATED ALWAYS AS (
(((submission_id + chunk_index) % 65536) * 40503) % 65536
) VIRTUAL;
ALTER TABLE chunks_metadata ADD COLUMN random_order INTEGER NOT NULL GENERATED ALWAYS AS (
(((submission_id + chunk_index) % 65536) * 40503) % 65536
) VIRTUAL;


-- 3. Recreate all dropped indexes
CREATE INDEX random_chunks_order ON chunks (
random_order
, submission_id
, chunk_index
);

CREATE INDEX random_chunks_metadata_order ON chunks_metadata (
metadata_key
, metadata_value
, random_order
, submission_id
, chunk_index
);

CREATE INDEX random_chunks_metadata_order2 ON chunks_metadata (
metadata_key
, random_order
, metadata_value
, submission_id
, chunk_index
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- 1. Drop all indexes and finally the column itself
DROP INDEX random_chunks_order;
DROP INDEX random_chunks_metadata_order;
DROP INDEX random_chunks_metadata_order2;
ALTER TABLE chunks DROP COLUMN random_order;
ALTER TABLE chunks_metadata DROP COLUMN random_order;

-- 2. Recreate the column with its new, proper definition
--
-- Compared to the OG definition, we ensure that the top 42 bits of `submission_id`
-- which contain the timestamp part of the snowflake,
-- always participate in the `random_order`,
-- since the lower 22 bits are likely to be `0` except when under peak load.
ALTER TABLE chunks ADD COLUMN random_order INTEGER NOT NULL GENERATED ALWAYS AS (
(((submission_id + (submission_id >> 22) + chunk_index) % 65536) * 40503) % 65536
) VIRTUAL;
ALTER TABLE chunks_metadata ADD COLUMN random_order INTEGER NOT NULL GENERATED ALWAYS AS (
(((submission_id + (submission_id >> 22) + chunk_index) % 65536) * 40503) % 65536
) VIRTUAL;


-- 3. Recreate all dropped indexes
CREATE INDEX random_chunks_order ON chunks (
random_order
, submission_id
, chunk_index
);

CREATE INDEX random_chunks_metadata_order ON chunks_metadata (
metadata_key
, metadata_value
, random_order
, submission_id
, chunk_index
);

CREATE INDEX random_chunks_metadata_order2 ON chunks_metadata (
metadata_key
, random_order
, metadata_value
, submission_id
, chunk_index
);
Binary file modified opsqueue/opsqueue_example_database_schema.db
Binary file not shown.
Loading
Loading