Skip to content

Commit

Permalink
upgrade to .Net 5
Browse files Browse the repository at this point in the history
  • Loading branch information
NRHelmi committed Feb 16, 2022
1 parent 745d8e8 commit d604086
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/new-csharp-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if: ${{ !contains(fromJson(steps.fetch_all_releases.outputs.all_releases).*.tag_name, steps.fetch_current_version.outputs.current_version) }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 5.0.405

# - name: Setup .NET Core # required by ClientSDK
# if: ${{ !contains(fromJson(steps.fetch_all_releases.outputs.all_releases).*.tag_name, steps.fetch_current_version.outputs.current_version) }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET Core # required by the `gpr` tool
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 5.0.405

# - name: Setup .NET Core # required by ClientSDK
# uses: actions/setup-dotnet@v1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a Client SDK for RelationalAI

- API version: 1.2.5
- API version: 1.2.6

## Frameworks supported

Expand Down
6 changes: 0 additions & 6 deletions RelationalAI/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,6 @@ public bool EnableLibrary(string srcName)
return Client.EnableLibrary(srcName);
}

public bool CloseDatabase()
{
SetConnectionOnClients();
return Client.CloseDatabase();
}

public ICollection<Relation> Cardinality(string relName = null)
{
SetConnectionOnClients();
Expand Down
3 changes: 0 additions & 3 deletions RelationalAI/GeneratedRelationalAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,6 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class ModifyWorkspaceAction : Action
{
[Newtonsoft.Json.JsonProperty("close_database", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Close_database { get; set; }

[Newtonsoft.Json.JsonProperty("delete_edb", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Delete_edb { get; set; }

Expand Down
11 changes: 4 additions & 7 deletions RelationalAI/HttpClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public static HttpClient CreateHttpClient(bool verifySSL, int timeout) {
if( verifySSL ) {
var handler = new SocketsHttpHandler()
{
// uncomment this to enable keep-alive after moving to netcore5
// ConnectCallback = s_defaultConnectCallback,
ConnectCallback = s_defaultConnectCallback,
};
HttpClient httpClient = new HttpClient(handler);
httpClient.Timeout = TimeSpan.FromSeconds(timeout);
Expand All @@ -49,8 +48,7 @@ public static HttpClient CreateHttpClient(bool verifySSL, int timeout) {
};
var handler = new SocketsHttpHandler()
{
// uncomment this to enable keep-alive after moving to netcore5
// ConnectCallback = s_defaultConnectCallback,
ConnectCallback = s_defaultConnectCallback,
SslOptions = sslOptions
};
HttpClient httpClient = new HttpClient(handler);
Expand Down Expand Up @@ -121,8 +119,7 @@ private static Socket CreateSocket(EndPoint endPoint)
return socket;
}

/*
// uncomment this block to enable keep-alive after moving to netcore5

private static async ValueTask<Stream> DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
{
// `Socket.SetSocketOption` function fails if a `DnsEndPoint` is passed, as it
Expand All @@ -146,7 +143,7 @@ private static async ValueTask<Stream> DefaultConnectAsync(SocketsHttpConnection
}
}
private static readonly Func<SocketsHttpConnectionContext, CancellationToken, ValueTask<Stream>> s_defaultConnectCallback = DefaultConnectAsync;
*/


private async static ValueTask<IPEndPoint> getIPEndPoint(DnsEndPoint dnsEndPoint)
{
Expand Down
73 changes: 1 addition & 72 deletions RelationalAI/KGMSClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class GeneratedRelationalAIClient

public const string JSON_CONTENT_TYPE = "application/json";
public const string CSV_CONTENT_TYPE = "text/csv";
public const string USER_AGENT_HEADER = "KGMSClient/1.2.5/csharp";
public const string USER_AGENT_HEADER = "KGMSClient/1.2.1/csharp";

public int DebugLevel = Connection.DEFAULT_DEBUG_LEVEL;

Expand Down Expand Up @@ -78,25 +78,6 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess

// use HTTP 2.0 (to handle keep-alive)
request.Version = System.Net.HttpVersion.Version20;

// have a separate keep-alive task (per thread)
if(!isStatusRequest(body)) {
var tokenSource = new CancellationTokenSource();
AsyncLocalKeepAliveCancellationTokenSource.Value = tokenSource;
CancellationToken ct = tokenSource.Token;

/**
* TODO: currently we swallo exceptions in KeepClientAlive.
* If we want to throw, then we need to change this to asynchronously handle the throw
* e.g.
* try {
await this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
} catch (Exception e) {
// Handle here
}
**/
var keep_alive_task = this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
}
}

private bool isStatusRequest(Transaction txn)
Expand Down Expand Up @@ -127,11 +108,6 @@ private bool _isEmpty(string str)
{
return str == null || str.Length == 0;
}

public virtual Task KeepClientAlive(HttpClient client_, String url, CancellationToken ct)
{
throw new NotImplementedException();
}
}

public partial class Transaction
Expand Down Expand Up @@ -356,46 +332,6 @@ public ILogger Logger
}
private ILogger _logger;

public override async Task KeepClientAlive(HttpClient client_, String url, CancellationToken ct)
{
while (true)
{
ct.ThrowIfCancellationRequested();
await Task.Delay(HttpClientFactory.KEEP_ALIVE_INTERVAL*1000);
ct.ThrowIfCancellationRequested();

try {
await Task.Run(() => this.KeepAliveProbe(client_, ct));
} catch (Exception e) {
// ignore. But I think we might want to throw?
Logger.Error("KeepAliveProbe failed with exception: " + e.Message);
}
}
}

private async void KeepAliveProbe(HttpClient client_, CancellationToken ct)
{
// Send "HEAD / HTTP/2" request.
var request = new System.Net.Http.HttpRequestMessage();
request.Method = new System.Net.Http.HttpMethod("HEAD");
request.RequestUri = new System.Uri(this.BaseUrl, System.UriKind.RelativeOrAbsolute);
request.Version = System.Net.HttpVersion.Version20;

var keepaliveFailureCnt = 0;
try {
await client_.SendAsync(request, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, ct).ConfigureAwait(false);
} catch (Exception e) {
keepaliveFailureCnt++;
// KEEP_ALIVE_RETRIES may be too big here (16) for the interval of 3 minutes
if ( keepaliveFailureCnt < HttpClientFactory.KEEP_ALIVE_RETRIES ) {
Logger.Warning("KeepAliveProbe failed to send request: " + e.Message);
} else {
Logger.Error("KeepAliveProbe failed to send request: " + e.Message);
Logger.Error("KeepAliveProbe retry exceeded max. Throwing");
throw e;
}
}
}

public static void AddExtraHeaders(HttpRequestMessage request)
{
Expand Down Expand Up @@ -959,13 +895,6 @@ public bool EnableLibrary(string srcName)
return RunAction(action) != null;
}

public bool CloseDatabase()
{
var action = new ModifyWorkspaceAction();
action.Close_database = conn.DbName;
return RunAction(action, isReadOnly: true) != null;
}

public ICollection<Relation> Cardinality(string relName = null)
{
var action = new CardinalityAction();
Expand Down
4 changes: 2 additions & 2 deletions RelationalAI/RelationalAI.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.2.5</Version>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.2.6</Version>
<TargetFramework>net5.0</TargetFramework>
<PackageId>RelationalAI</PackageId>
<Authors>RelationalAI</Authors>
<Company>RelationalAI</Company>
Expand Down
2 changes: 1 addition & 1 deletion RelationalAISamples/LocalWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def jaccard_similarity(a,b,v) = (count[x : tmp(a,b,x)] / count[x: (uedge(a, x) o
);

Console.WriteLine("==> Jaccard Similarity: " + JObject.FromObject(queryResult).ToString());
conn.CloseDatabase();

}
}
}
2 changes: 1 addition & 1 deletion RelationalAISamples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Getting started

First we need to install `Dotnet core 3.1` [dotnet-core-3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1) available for Windows, Linux and OSX.
First we need to install `Dotnet core 5.0` [dotnet-core-5.0](https://dotnet.microsoft.com/download/dotnet-core/5.0) available for Windows, Linux and OSX.

## Usage
### Dependencies
Expand Down
6 changes: 0 additions & 6 deletions RelationalAITests/IntegrationTestsCommons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ def cityRes(x) = exists(pos: json(:address, :city, x))
conn.CreateDatabase(overwrite: true);
Assert.True(conn.EnableLibrary("stdlib"));

// close_database
// =============================================================================
conn = connFunc();
conn.CreateDatabase(overwrite: true);
Assert.True(conn.CloseDatabase());

// cardinality
// =============================================================================
conn = connFunc();
Expand Down
1 change: 1 addition & 0 deletions RelationalAITests/LocalIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ select string.Format(
"Credential=e3536f8d-cbc6-4ed8-9de6-74cf4cb724a1/20200504/us-east/database+list/rai01_request, " +
"SignedHeaders=content-type;host;x-rai-date, " +
"Signature=77d211417454ded42dc931d25c57af6cab6cbc70f75bef4c849d37585188d659158c8c944eab866e3147bbcde21257ae0a1dfece3c0f3f43a838b3f9524e0f0a\n" +
"content-length: 2\n" +
"content-type: application/json\n" +
"host: 127.0.0.1\n" +
"x-rai-date: 20200504T103600Z\n";
Expand Down
2 changes: 1 addition & 1 deletion RelationalAITests/RelationalAITests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ let
in
stdenv.mkDerivation rec {
name = "rai-server-csharp-client-sdk-${version}";
version = "1.2.5";
version = "1.2.6";
buildInputs = [
raiserverBinary
dotnet-sdk_3
dotnet-sdk_5
dotnetPackages.Nuget
];

Expand Down

0 comments on commit d604086

Please sign in to comment.