Skip to content

Commit

Permalink
RavenDB-17793 : throw on attempt to move bucket from prefixed range i…
Browse files Browse the repository at this point in the history
…f destination shard is not a part of shards list in the prefix setting
  • Loading branch information
aviv86 committed Jan 16, 2024
1 parent 2650170 commit 12ecc3c
Show file tree
Hide file tree
Showing 3 changed files with 594 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ public override void UpdateDatabaseRecord(DatabaseRecord record, long etag)
}
}


if (Bucket >= ShardHelper.NumberOfBuckets)
{
// prefixed bucket range
var prefixed = record.Sharding.Prefixed;
List<int> shards = null;
for (int i = 0; i < prefixed.Count; i++)
{
var bucketRangeStart = prefixed[i].BucketRangeStart;
int nextBucketRangeStart = i == prefixed.Count - 1
? int.MaxValue
: prefixed[i + 1].BucketRangeStart;

if (Bucket < bucketRangeStart || Bucket >= nextBucketRangeStart)
continue;

shards = prefixed[i].Shards;
break;
}

if (shards == null || shards.Contains(DestinationShard) == false)
throw new RachisApplyException($"Destination shard {DestinationShard} doesn't exists");
}

if (record.Sharding.Shards.ContainsKey(DestinationShard) == false)
throw new RachisApplyException($"Destination shard {DestinationShard} doesn't exists");

Expand Down
Loading

0 comments on commit 12ecc3c

Please sign in to comment.