Skip to content

Commit fdebec7

Browse files
jblackburn21Jason Blackburn
and
Jason Blackburn
authored
Sharding sqlserver mac support (#183)
* cleaned up sharding-sqlserver sample to support mac os * cleaned up sharding-sqlserver sample to use SqlSharding.Sql.Host --------- Co-authored-by: Jason Blackburn <[email protected]>
1 parent a0e5ca2 commit fdebec7

27 files changed

+28
-875
lines changed

infrastructure/build.all.sh

100644100755
File mode changed.

infrastructure/mssql-init-container/build.sh

100644100755
File mode changed.

infrastructure/mssql/build.sh

100644100755
File mode changed.

infrastructure/mssql/deploy.k8s.sh

100644100755
File mode changed.

infrastructure/mssql/src/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/mssql/server:2019-latest
1+
FROM mcr.microsoft.com/mssql/server:2022-latest
22

33
COPY ./setup.sql .
44
COPY ./setup.sh .

infrastructure/mssql/src/ready-check.sh

100644100755
File mode changed.

infrastructure/mssql/src/setup.sh

100644100755
File mode changed.

src/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<AkkaVersion>1.5.20</AkkaVersion>
2020
<PbmVersion>1.4.1</PbmVersion>
2121
<AkkaHostingVersion>1.5.20</AkkaHostingVersion>
22-
<MicrosoftExtensionsVersion>[7.0.0,)</MicrosoftExtensionsVersion>
22+
<MicrosoftExtensionsVersion>[8.0.0,)</MicrosoftExtensionsVersion>
2323
</PropertyGroup>
2424
<!-- SourceLink support for all Akka.NET projects -->
2525
<ItemGroup>

src/clustering/sharding-sqlserver/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Like all of the samples in this repository, we are using a simple domain since t
2121

2222
This app consists of two Akka.Cluster role types:
2323

24-
1. `SqlSharding.WebApp` - a web-application that joins the cluster and queries actors hosted on the `SqlSharding.Host` instances via Akka.Cluster.Sharding and Akka.Cluster.Singleton and
25-
2. `SqlSharding.Host` - a [headless Akka.NET process](https://petabridge.com/blog/akkadotnet-ihostedservice/) that hosts the `ShardRegion` for all `ProductTotalsActor` instances and a `ClusterSingletonManager` for the singular `ProductIndexActor` instance.
24+
1. `SqlSharding.WebApp` - a web-application that joins the cluster and queries actors hosted on the `SqlSharding.Sql.Host` instances via Akka.Cluster.Sharding and Akka.Cluster.Singleton and
25+
2. `SqlSharding.Sql.Host` - a [headless Akka.NET process](https://petabridge.com/blog/akkadotnet-ihostedservice/) that hosts the `ShardRegion` for all `ProductTotalsActor` instances and a `ClusterSingletonManager` for the singular `ProductIndexActor` instance.
2626

2727
We have only two actor types in this solution:
2828

@@ -60,8 +60,8 @@ Implementing this with actors instead gives us the following:
6060

6161
Here are the key details for understanding what this sample does and how it works:
6262

63-
1. **Akka.Cluster.Sharding does all of the heavy lifting** - it guarantees that for every unique `productID` there exists exactly one `ProductTotalsActor` that owns the state of that entity. That guarantee is upheld even across network splits. One `ProductTotalsActor` can be moved from one `SqlSharding.Host` node to another, message traffic to that actor will be paused while this happens, the actor will be recreated on its new home node, and message traffic will be resumed. The `WebApp` and `ProductIndexActor` instances have no idea that this is happening *and they don't need to*. In addition to that, the `ShardRegion` hosting the `ProductIndexActor` will dynamically create new instances of those actors on-demand and will, by default, kill existing instances of those actors if they haven't been sent a message for more than 120 seconds. You can change how the "kill off actors" behavior works, however: `akka.cluster.sharding.remember-entities=off` turns this off and keeps entity actors alive forever, or you can just change the time threshold via `akka.cluster.sharding.passivate-idle-entity-after = 400s`.
64-
2. **`ShardRegionProxy` is how `SqlSharding.WebApp` communicates with `ProductTotalsActor`s hosted on the `SqlSharding.Host` instances** - again, the Akka.Cluster.Sharding infrastructure does most of the heavy work here; but this time from the perspective of the WebApp - all of the messages sent to the `/product/{productId}` route are ultimately routed to a `ShardRegionProxy` `IActorRef`. This actor knows how to communicate with the `ShardRegion` on the `SqlSharding.Host` role to dynamically instantiate a new `ProductTotalsActor` instance, if necessary, and route messages to it.
63+
1. **Akka.Cluster.Sharding does all of the heavy lifting** - it guarantees that for every unique `productID` there exists exactly one `ProductTotalsActor` that owns the state of that entity. That guarantee is upheld even across network splits. One `ProductTotalsActor` can be moved from one `SqlSharding.Sql.Host` node to another, message traffic to that actor will be paused while this happens, the actor will be recreated on its new home node, and message traffic will be resumed. The `WebApp` and `ProductIndexActor` instances have no idea that this is happening *and they don't need to*. In addition to that, the `ShardRegion` hosting the `ProductIndexActor` will dynamically create new instances of those actors on-demand and will, by default, kill existing instances of those actors if they haven't been sent a message for more than 120 seconds. You can change how the "kill off actors" behavior works, however: `akka.cluster.sharding.remember-entities=off` turns this off and keeps entity actors alive forever, or you can just change the time threshold via `akka.cluster.sharding.passivate-idle-entity-after = 400s`.
64+
2. **`ShardRegionProxy` is how `SqlSharding.WebApp` communicates with `ProductTotalsActor`s hosted on the `SqlSharding.Sql.Host` instances** - again, the Akka.Cluster.Sharding infrastructure does most of the heavy work here; but this time from the perspective of the WebApp - all of the messages sent to the `/product/{productId}` route are ultimately routed to a `ShardRegionProxy` `IActorRef`. This actor knows how to communicate with the `ShardRegion` on the `SqlSharding.Sql.Host` role to dynamically instantiate a new `ProductTotalsActor` instance, if necessary, and route messages to it.
6565
3. **Akka.Persistence is what we use to manage entity state, and we use event-sourcing to provide long-term extensibility** - the separation between commands, events, and queries is an important feature of how this application is designed. Cleanly segmenting the "message grammar" helps keep things organized ultimately simplifies the stateful piece of our programming model: the state of any given entity must be derived from the sum of its events. We use Akka.Persistence.SqlServer to store / recover this data and we use Google.Protobuf to serialize events, state, commands, and queries in a highly versionable way.
6666

6767
## Running Sample
@@ -88,9 +88,12 @@ This will build a copy of our [MSSQL image](https://github.com/petabridge/akkado
8888
8989
### Run the Sample
9090

91+
On initial run, the database can be seeded by setting the `SEED_DB=true` environment variable
92+
9193
Load up Rider or Visual Studio and
9294

93-
1. Launch `SqlSharding.Host`, followed by
95+
96+
1. Launch `SqlSharding.Sql.Host`, followed by
9497
2. Launch `SqlSharding.WebApp`.
9598

96-
Provided that you don't see any SQL Server connection errors originating from `SqlSharding.Host` - you should have no trouble using the WebApp's UI to add products, submit orders, change inventory levels, and more.
99+
Provided that you don't see any SQL Server connection errors originating from `SqlSharding.Sql.Host` - you should have no trouble using the WebApp's UI to add products, submit orders, change inventory levels, and more.

src/clustering/sharding-sqlserver/ShardingSqlServer.sln

-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Shared", "SqlSharding.Shared\SqlSharding.Shared.csproj", "{52F92E8D-0E25-41DB-88C7-DB537166E97D}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Host", "SqlSharding.Host\SqlSharding.Host.csproj", "{A8FF833D-47A2-4A7B-97D8-FBE56C973181}"
9-
EndProject
108
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.WebApp", "SqlSharding.WebApp\SqlSharding.WebApp.csproj", "{2DE443CB-EEA0-4A69-9750-C55638778565}"
119
EndProject
1210
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Sql.Host", "SqlSharding.Sql.Host\SqlSharding.Sql.Host.csproj", "{915E613A-A6ED-4633-BC50-832A15CF4596}"
@@ -24,10 +22,6 @@ Global
2422
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Debug|Any CPU.Build.0 = Debug|Any CPU
2523
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2624
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Release|Any CPU.Build.0 = Release|Any CPU
27-
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28-
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Debug|Any CPU.Build.0 = Debug|Any CPU
29-
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Release|Any CPU.ActiveCfg = Release|Any CPU
30-
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Release|Any CPU.Build.0 = Release|Any CPU
3125
{2DE443CB-EEA0-4A69-9750-C55638778565}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3226
{2DE443CB-EEA0-4A69-9750-C55638778565}.Debug|Any CPU.Build.0 = Debug|Any CPU
3327
{2DE443CB-EEA0-4A69-9750-C55638778565}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/clustering/sharding-sqlserver/SqlSharding.Host/Actors/ProductIndexActor.cs

-172
This file was deleted.

src/clustering/sharding-sqlserver/SqlSharding.Host/Actors/ProductTotalsActor.cs

-111
This file was deleted.

0 commit comments

Comments
 (0)