Skip to content

Commit

Permalink
RavenDB-17793 : address minor PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv committed Jul 3, 2024
1 parent 72ccf9c commit c22e059
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Raven.Client.Exceptions.Sharding;
using Raven.Server.Documents.Sharding;
using Raven.Server.Routing;
using Raven.Server.Utils;
Expand All @@ -26,19 +25,19 @@ public async Task ExecuteMoveDocuments()
[RavenAction("/databases/*/admin/sharding/prefixed", "PUT", AuthorizationStatus.DatabaseAdmin)]
public Task AddPrefixedShardingSetting()
{
throw new NotSupportedInShardingException("This operation is not available from a specific shard");
throw new NotSupportedException("This operation is not available from a specific shard");
}

[RavenAction("/databases/*/admin/sharding/prefixed", "DELETE", AuthorizationStatus.DatabaseAdmin)]
public Task DeletePrefixedShardingSetting()
{
throw new NotSupportedInShardingException("This operation is not available from a specific shard");
throw new NotSupportedException("This operation is not available from a specific shard");
}

[RavenAction("/databases/*/admin/sharding/prefixed", "POST", AuthorizationStatus.DatabaseAdmin)]
public Task UpdatePrefixedShardingSetting()
{
throw new NotSupportedInShardingException("This operation is not available from a specific shard");
throw new NotSupportedException("This operation is not available from a specific shard");
}

private void ValidateShardDatabaseName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Raven.Client.Documents.Commands;
using Raven.Client.Documents.Conventions;
Expand Down Expand Up @@ -53,7 +52,7 @@ public async Task AddPrefixedShardingSetting()
urls = shardingConfiguration.Orchestrator.Topology.Members.Select(clusterTopology.GetUrlFromTag).ToArray();
}

if (await AssertNoDocumentsStartingWith(context, setting.Prefix, urls) == false)
if (await AssertNoDocumentsStartingWithAsync(context, setting.Prefix, urls) == false)
throw new InvalidOperationException(
$"Cannot add prefix '{setting.Prefix}' to {nameof(ShardingConfiguration)}.{nameof(ShardingConfiguration.Prefixed)}. " +
$"There are existing documents in database '{DatabaseName}' that start with '{setting.Prefix}'. " +
Expand All @@ -63,8 +62,8 @@ public async Task AddPrefixedShardingSetting()
var (raftIndex, _) = await ServerStore.SendToLeaderAsync(cmd);

await DatabaseContext.ServerStore.WaitForExecutionOnRelevantNodesAsync(context, shardingConfiguration.Orchestrator.Topology.Members, raftIndex);

HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent;
NoContentStatus();
}
}

Expand All @@ -88,7 +87,7 @@ public async Task DeletePrefixedShardingSetting()
urls = shardingConfiguration.Orchestrator.Topology.Members.Select(clusterTopology.GetUrlFromTag).ToArray();
}

if (await AssertNoDocumentsStartingWith(context, setting.Prefix, urls) == false)
if (await AssertNoDocumentsStartingWithAsync(context, setting.Prefix, urls) == false)
throw new InvalidOperationException(
$"Cannot remove prefix '{setting.Prefix}' from {nameof(ShardingConfiguration)}.{nameof(ShardingConfiguration.Prefixed)}. " +
$"There are existing documents in database '{DatabaseName}' that start with '{setting.Prefix}'. " +
Expand All @@ -99,7 +98,7 @@ public async Task DeletePrefixedShardingSetting()

await DatabaseContext.ServerStore.WaitForExecutionOnRelevantNodesAsync(context, shardingConfiguration.Orchestrator.Topology.Members, raftIndex);

HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent;
NoContentStatus();
}
}

Expand All @@ -125,7 +124,7 @@ public async Task UpdatePrefixedShardingSetting()

await DatabaseContext.ServerStore.WaitForExecutionOnRelevantNodesAsync(context, shardingConfiguration.Orchestrator.Topology.Members, raftIndex);

HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent;
NoContentStatus();
}
}

Expand Down Expand Up @@ -195,7 +194,7 @@ private static void AssertValidShardsDistribution(PrefixedShardingSetting oldSet
}
}

private async Task<bool> AssertNoDocumentsStartingWith(JsonOperationContext context, string prefix, string[] urls, string database = null)
private async Task<bool> AssertNoDocumentsStartingWithAsync(JsonOperationContext context, string prefix, string[] urls, string database = null)
{
using (var requestExecutor = RequestExecutor.CreateForServer(urls, database ?? DatabaseName, ServerStore.Server.Certificate.Certificate, DocumentConventions.DefaultForServer))
{
Expand Down

0 comments on commit c22e059

Please sign in to comment.