Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some more randomness to chunk assignment #3279

Merged
merged 1 commit into from Jun 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/hypertable.c
Expand Up @@ -1191,26 +1191,37 @@ ts_hypertable_has_tablespace(Hypertable *ht, Oid tspc_oid)
}

static int
hypertable_get_chunk_slice_ordinal(const Hypertable *ht, const Hypercube *hc)
hypertable_get_chunk_round_robin_index(const Hypertable *ht, const Hypercube *hc)
{
Dimension *dim;
DimensionSlice *slice;
int offset = 0;

Assert(NULL != ht);
Assert(NULL != hc);

dim = hyperspace_get_closed_dimension(ht->space, 0);

if (NULL == dim)
{
dim = hyperspace_get_open_dimension(ht->space, 0);
/* Add some randomness between hypertables so that
* if there is no space partitions, but multiple hypertables
* the initial index is different for different hypertables.
* This protects against creating a lot of chunks on the same
* data node when many hypertables are created at roughly
* the same time, e.g., from a bootstrap script.
*/
offset = (int) ht->fd.id;
}

Assert(NULL != dim);

slice = ts_hypercube_get_slice_by_dimension_id(hc, dim->fd.id);

Assert(NULL != slice);

return ts_dimension_get_slice_ordinal(dim, slice);
return ts_dimension_get_slice_ordinal(dim, slice) + offset;
}

/*
Expand All @@ -1232,7 +1243,7 @@ ts_hypertable_select_tablespace(Hypertable *ht, Chunk *chunk)
if (NULL == tspcs || tspcs->num_tablespaces == 0)
return NULL;

i = hypertable_get_chunk_slice_ordinal(ht, chunk->cube);
i = hypertable_get_chunk_round_robin_index(ht, chunk->cube);

/* Use the index of the slice to find the tablespace */
return &tspcs->tablespaces[i % tspcs->num_tablespaces];
Expand Down Expand Up @@ -2568,7 +2579,7 @@ ts_hypertable_assign_chunk_data_nodes(const Hypertable *ht, const Hypercube *cub
int num_assigned = MIN(ht->fd.replication_factor, list_length(available_nodes));
int n, i;

n = hypertable_get_chunk_slice_ordinal(ht, cube);
n = hypertable_get_chunk_round_robin_index(ht, cube);

for (i = 0; i < num_assigned; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion tsl/test/expected/dist_compression.out
Expand Up @@ -677,7 +677,7 @@ from chunk_compression_stats('conditions') where compression_status like 'Compre
chunk_name | node_name | before_total | after_total
-----------------------+-----------------------+--------------+-------------
_dist_hyper_2_6_chunk | db_dist_compression_1 | 32 kB | 32 kB
_dist_hyper_2_6_chunk | db_dist_compression_2 | 32 kB | 32 kB
_dist_hyper_2_6_chunk | db_dist_compression_3 | 32 kB | 32 kB
(2 rows)

SELECT * FROM _timescaledb_catalog.chunk ORDER BY id;
Expand Down