Skip to content

Commit

Permalink
RavenDB-17793 : do not allow to add prefix setting with no shards
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv committed Feb 1, 2024
1 parent 22fbdee commit b83b3a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public async Task ExecuteMoveDocuments()
await processor.ExecuteAsync();
}


[RavenShardedAction("/databases/*/admin/sharding/prefixes/add", "POST")]
public async Task AddPrefixConfiguration()
{
Expand Down Expand Up @@ -103,7 +102,6 @@ public async Task UpdatePrefixConfiguration()
{
var json = await context.ReadForMemoryAsync(RequestBodyStream(), GetType().Name);
var setting = JsonDeserializationCluster.PrefixedShardingSetting(json);
setting.Prefix = setting.Prefix.ToLower();

var shardingConfiguration = ServerStore.Cluster.ReadShardingConfiguration(DatabaseName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public override void UpdateDatabaseRecord(DatabaseRecord record, long etag)
private static int GetNextPrefixedBucketRangeStart(IEnumerable<PrefixedShardingSetting> prefixes)
{
var prefixesByRangeStart = prefixes.OrderBy(x => x.BucketRangeStart).ToList();
if (prefixesByRangeStart.Count == 0)
return ShardHelper.NumberOfBuckets;

for (int i = 0; i < prefixesByRangeStart.Count; i++)
{
var currentRangeStart = prefixesByRangeStart[i].BucketRangeStart;
Expand Down
5 changes: 5 additions & 0 deletions src/Raven.Server/ServerWide/ShardingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ internal static void AssertValidPrefix(PrefixedShardingSetting setting, Sharding
$"Cannot add prefix '{setting.Prefix}' to {nameof(ShardingConfiguration)}.{nameof(ShardingConfiguration.Prefixed)}. " +
"In order to define sharding by prefix, the prefix string must end with '/' or '-' characters.");

if (setting.Shards.Count == 0)
throw new InvalidOperationException(
$"Cannot add prefix '{setting.Prefix}' to {nameof(ShardingConfiguration)}.{nameof(ShardingConfiguration.Prefixed)}. " +
$"{nameof(PrefixedShardingSetting)}.{nameof(PrefixedShardingSetting.Shards)} cannot be empty.");

foreach (var shardNumber in setting.Shards)
{
if (shardingConfiguration.Shards.ContainsKey(shardNumber) == false)
Expand Down

0 comments on commit b83b3a0

Please sign in to comment.