Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharding sqlserver mac support #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified infrastructure/build.all.sh
100644 → 100755
Empty file.
Empty file modified infrastructure/mssql-init-container/build.sh
100644 → 100755
Empty file.
Empty file modified infrastructure/mssql/build.sh
100644 → 100755
Empty file.
Empty file modified infrastructure/mssql/deploy.k8s.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion infrastructure/mssql/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/mssql/server:2019-latest
FROM mcr.microsoft.com/mssql/server:2022-latest

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

COPY ./setup.sql .
COPY ./setup.sh .
Expand Down
Empty file modified infrastructure/mssql/src/ready-check.sh
100644 → 100755
Empty file.
Empty file modified infrastructure/mssql/src/setup.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<AkkaVersion>1.5.20</AkkaVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

<PbmVersion>1.4.1</PbmVersion>
<AkkaHostingVersion>1.5.20</AkkaHostingVersion>
<MicrosoftExtensionsVersion>[7.0.0,)</MicrosoftExtensionsVersion>
<MicrosoftExtensionsVersion>[8.0.0,)</MicrosoftExtensionsVersion>
</PropertyGroup>
<!-- SourceLink support for all Akka.NET projects -->
<ItemGroup>
Expand Down
15 changes: 9 additions & 6 deletions src/clustering/sharding-sqlserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Like all of the samples in this repository, we are using a simple domain since t

This app consists of two Akka.Cluster role types:

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
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.
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
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.

We have only two actor types in this solution:

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

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

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`.
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.
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`.
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

## Running Sample
Expand All @@ -88,9 +88,12 @@ This will build a copy of our [MSSQL image](https://github.com/petabridge/akkado

### Run the Sample

On initial run, the database can be seeded by setting the `SEED_DB=true` environment variable

Load up Rider or Visual Studio and

1. Launch `SqlSharding.Host`, followed by

1. Launch `SqlSharding.Sql.Host`, followed by
2. Launch `SqlSharding.WebApp`.

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.
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.
6 changes: 0 additions & 6 deletions src/clustering/sharding-sqlserver/ShardingSqlServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Shared", "SqlSharding.Shared\SqlSharding.Shared.csproj", "{52F92E8D-0E25-41DB-88C7-DB537166E97D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Host", "SqlSharding.Host\SqlSharding.Host.csproj", "{A8FF833D-47A2-4A7B-97D8-FBE56C973181}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.WebApp", "SqlSharding.WebApp\SqlSharding.WebApp.csproj", "{2DE443CB-EEA0-4A69-9750-C55638778565}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSharding.Sql.Host", "SqlSharding.Sql.Host\SqlSharding.Sql.Host.csproj", "{915E613A-A6ED-4633-BC50-832A15CF4596}"
Expand All @@ -24,10 +22,6 @@ Global
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52F92E8D-0E25-41DB-88C7-DB537166E97D}.Release|Any CPU.Build.0 = Release|Any CPU
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8FF833D-47A2-4A7B-97D8-FBE56C973181}.Release|Any CPU.Build.0 = Release|Any CPU
{2DE443CB-EEA0-4A69-9750-C55638778565}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2DE443CB-EEA0-4A69-9750-C55638778565}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DE443CB-EEA0-4A69-9750-C55638778565}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading