Skip to content

Commit

Permalink
RavenDB-22482 : fix failing test : prevent NRE on ShardingConfigurati…
Browse files Browse the repository at this point in the history
…on when database was deleted during bucket migration process
  • Loading branch information
aviv committed Jul 11, 2024
1 parent e421265 commit e7d3dbf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void SetConnectionException(SubscriptionConnectionsStateOrche

protected override string GetNodeFromState(SubscriptionState taskStatus) => taskStatus.NodeTag;

protected override DatabaseTopology GetTopology(ClusterOperationContext context) => _serverStore.Cluster.ReadShardingConfiguration(context, _databaseName).Orchestrator.Topology;
protected override DatabaseTopology GetTopology(ClusterOperationContext context) => _serverStore.Cluster.ReadShardingConfiguration(context, _databaseName)?.Orchestrator.Topology;

protected override bool SubscriptionChangeVectorHasChanges(SubscriptionConnectionsStateOrchestrator state, SubscriptionState taskStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void HandleDatabaseRecordChange()
}
}

protected override DatabaseTopology GetTopology(ClusterOperationContext context) => _serverStore.Cluster.ReadShardingConfiguration(context, _databaseName).Shards[_shardNumber];
protected override DatabaseTopology GetTopology(ClusterOperationContext context) => _serverStore.Cluster.ReadShardingConfiguration(context, _databaseName)?.Shards[_shardNumber];

protected override string GetNodeFromState(SubscriptionState taskStatus)
{
Expand Down
6 changes: 1 addition & 5 deletions src/Raven.Server/ServerWide/ClusterStateMachine.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -63,7 +60,6 @@
using Sparrow.Logging;
using Sparrow.Server;
using Sparrow.Server.Utils;
using Sparrow.Threading;
using Sparrow.Utils;
using Voron;
using Voron.Data;
Expand Down Expand Up @@ -3554,7 +3550,7 @@ public Raven.Client.ServerWide.Sharding.ShardingConfiguration ReadShardingConfig
{
using (var raw = ReadRawDatabaseRecord(context, name))
{
return raw.Sharding.MaterializedConfiguration;
return raw?.Sharding.MaterializedConfiguration;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Raven.Server/ServerWide/ShardingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public bool HasActiveMigrations(string database)
{
var config = _serverStore.Cluster.ReadShardingConfiguration(database);

return config.HasActiveMigrations();
return config?.HasActiveMigrations() ?? false;
}

public DocumentConventions DocumentConventionsForShard =>
Expand Down Expand Up @@ -136,7 +136,9 @@ private ClusterChanges.DatabaseChangedDelegate CreateDelegateForReshardingStatus
case nameof(DestinationMigrationConfirmCommand):
case nameof(SourceMigrationCleanupCommand):
var config = _serverStore.Cluster.ReadShardingConfiguration(database);
if (config == null)
break;
if (config.BucketMigrations.Count == 0)
{
messages.Enqueue($"command {type} was skipped.");
Expand Down

0 comments on commit e7d3dbf

Please sign in to comment.