warning shard-count-clamped
What it means#
@shard(by: .field, count: n) asks for n shards of the table. A table cannot have more shards than its database: on a
database with fewer shards the count is clamped to the database's (and the program warns about it at run time when the table is
first used). The compiler reports it in advance when the outcome does not depend on the run: every Db.open(...) of the program
is a literal builtin://name?shards=N URL (an explicit shards= is not changed by OXL_BUILTIN_SHARDS or the cluster
profile) and n is larger than the largest N. A URL that is not a literal, or a builtin:// URL without ?shards=, turns the
check off. count: may be any compile-time integer expression (count: SHARDS, count: 4 * 4); a count below 1 is a
table-schema error.
Example#
@table("orders") @shard(by: .userId, count: 16) // <- shard-count-clamped: the program's database has 4 shards
data Order { @pk id: u64; userId: u64 }
fn main() io, db {
let db = Db.open("builtin://shop?shards=4")!
}shard-count-clamped
How to fix#
Lower count: to the number of shards of the database, or open the database with more shards (?shards=16). The
number of shards of a table is stored with its data: reopening the database with a different count (or ?shards=) is refused
with an error that says how many shards the table was created with (D-8320), because the rows written before would sit on the
wrong shards. Rows are not migrated between shard sets; to change the count, read the rows with the old count and insert them
into a new database with the new one.