Skip to content

Commit 0174af8

Browse files
Hybrid Search implementation and find enumerator cleanup (#18)
Co-authored-by: jeffrey-elliott <[email protected]> Co-authored-by: Steve Hewitt <[email protected]>
1 parent eccde5d commit 0174af8

File tree

83 files changed

+3336
-1452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3336
-1452
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 15
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Setup .NET
14+
uses: actions/setup-dotnet@v4
15+
with:
16+
dotnet-version: "8.0.x"
17+
18+
- name: Restore dependencies
19+
run: dotnet restore ./src/DataStax.AstraDB.DataApi/
20+
21+
- name: Build
22+
run: dotnet build ./src/DataStax.AstraDB.DataApi/ --configuration Release --no-restore

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Release to NuGet
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*" # Matches stable versions like v1.2.3
7+
- "v*.*.*-*" # Matches pre-release versions like v2.0.1-beta
8+
9+
jobs:
10+
build-and-release:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: "8.0.x"
21+
22+
- name: Extract version from tag
23+
id: extract_version
24+
run: |
25+
TAG=${{ github.ref_name }}
26+
VERSION=${TAG#v} # Removes 'v' prefix
27+
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
28+
29+
- name: Restore dependencies
30+
run: dotnet restore ./src/DataStax.AstraDB.DataApi/
31+
32+
- name: Build
33+
run: dotnet build ./src/DataStax.AstraDB.DataApi/ --configuration Release --no-restore
34+
35+
- name: Pack
36+
run: dotnet pack ./src/DataStax.AstraDB.DataApi/ --configuration Release --no-build --output nupkgs -p:Version=${{ env.PACKAGE_VERSION }}
37+
38+
# - name: Push to NuGet
39+
# run: dotnet nuget push nupkgs/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
40+
# env:
41+
# NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
42+
43+
- name: Dry-run NuGet push
44+
run: |
45+
echo "Would run: dotnet nuget push nupkgs/*.nupkg --api-key [REDACTED] --source https://api.nuget.org/v3/index.json"
46+
47+
- name: Upload NuGet package as artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: nuget-package
51+
path: nupkgs/*.nupkg
52+
retention-days: 1

index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _layout: landing
44

55
# Overview
66

7-
This C# Client Library simplifies using the DataStax Data API to manage and interact with AstraDB instances as well as other DataStax databases.
7+
This C# Client Library simplifies using the DataStax Data API to manage and interact with Astra DB instances as well as other DataStax databases.
88

99
# Installation
1010

src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ namespace DataStax.AstraDB.DataApi.Admin;
3535
/// </example>
3636
public class AstraDatabasesAdmin
3737
{
38-
private const int WAIT_IN_SECONDS = 600;
39-
4038
private readonly CommandOptions _adminOptions;
4139
private readonly DataApiClient _client;
4240

@@ -360,7 +358,7 @@ internal async Task<IDatabaseAdmin> CreateDatabaseAsync(DatabaseCreationOptions
360358
if (existingDb.Status == "ACTIVE")
361359
{
362360
Console.WriteLine($"Database {databaseName} already exists and is ACTIVE.");
363-
return GetDatabaseAdmin(Guid.Parse(existingDb.Id));
361+
return GetDatabaseAdmin(existingDb);
364362
}
365363

366364
throw new InvalidOperationException($"Database {databaseName} already exists but is in state: {existingDb.Status}");
@@ -403,63 +401,29 @@ internal async Task<IDatabaseAdmin> CreateDatabaseAsync(DatabaseCreationOptions
403401

404402
private void WaitForDatabase(string databaseName)
405403
{
406-
WaitForDatabaseAsync(databaseName, true).ResultSync();
407-
}
408-
409-
private async Task WaitForDatabaseAsync(string databaseName)
410-
{
411-
await WaitForDatabaseAsync(databaseName, false).ConfigureAwait(false);
404+
WaitForDatabaseAsync(databaseName).ResultSync();
412405
}
413406

414-
internal async Task WaitForDatabaseAsync(string databaseName, bool runSynchronously)
407+
internal async Task WaitForDatabaseAsync(string databaseName)
415408
{
409+
const int MAX_WAIT_IN_SECONDS = 600;
410+
const int SLEEP_SECONDS = 5;
416411
Guard.NotNullOrEmpty(databaseName, nameof(databaseName));
417-
if (runSynchronously)
418-
{
419-
Console.WriteLine($"Waiting {WAIT_IN_SECONDS} seconds synchronously before checking db status...");
420-
Thread.Sleep(WAIT_IN_SECONDS * 1000);
421-
string status = GetDatabaseStatus(databaseName);
422412

423-
if (status != "ACTIVE")
424-
{
425-
throw new Exception($"Database {databaseName} is still {status} after {WAIT_IN_SECONDS} seconds.");
426-
}
413+
int secondsWaited = 0;
427414

428-
Console.WriteLine($"Database {databaseName} is ready.");
429-
return;
430-
}
431-
432-
const int retry = 30_000; // 30 seconds
433-
int waiting = 0;
434-
435-
while (waiting < WAIT_IN_SECONDS * 1000)
415+
while (secondsWaited < MAX_WAIT_IN_SECONDS)
436416
{
437417
string status = await GetDatabaseStatusAsync(databaseName).ConfigureAwait(false);
438418
if (status == "ACTIVE")
439419
{
440-
Console.WriteLine($"Database {databaseName} is ready.");
441420
return;
442421
}
443-
444-
Console.WriteLine($"Database {databaseName} is {status}... retrying in {retry / 1000} seconds.");
445-
await Task.Delay(retry).ConfigureAwait(false);
446-
waiting += retry;
447-
}
448-
449-
throw new Exception($"Database {databaseName} did not become ready within {WAIT_IN_SECONDS} seconds.");
450-
}
451-
452-
internal string GetDatabaseStatus(string databaseName)
453-
{
454-
Guard.NotNullOrEmpty(databaseName, nameof(databaseName));
455-
var db = ListDatabases().FirstOrDefault(item => databaseName.Equals(item.Info.Name));
456-
457-
if (db == null)
458-
{
459-
throw new Exception($"Database '{databaseName}' not found.");
422+
await Task.Delay(SLEEP_SECONDS * 1000).ConfigureAwait(false);
423+
secondsWaited += SLEEP_SECONDS;
460424
}
461425

462-
return db.Status;
426+
throw new Exception($"Database {databaseName} did not become ready within {MAX_WAIT_IN_SECONDS} seconds.");
463427
}
464428

465429
internal async Task<string> GetDatabaseStatusAsync(string databaseName)
@@ -638,10 +602,19 @@ internal async Task<bool> DropDatabaseAsync(Guid dbGuid, CommandOptions options,
638602
return false;
639603
}
640604

641-
private IDatabaseAdmin GetDatabaseAdmin(Guid dbGuid)
605+
private DatabaseAdminAstra GetDatabaseAdmin(DatabaseInfo dbInfo)
642606
{
643-
Guard.NotEmpty(dbGuid, nameof(dbGuid));
644-
return new DatabaseAdminAstra(dbGuid, _client, null);
607+
var apiEndpoint = $"https://{dbInfo.Id}-{dbInfo.Info.Region}.apps.astra.datastax.com";
608+
var database = _client.GetDatabase(apiEndpoint);
609+
return new DatabaseAdminAstra(database, _client, null);
610+
}
611+
612+
private DatabaseAdminAstra GetDatabaseAdmin(Guid dbGuid)
613+
{
614+
var dbInfo = GetDatabaseInfo(dbGuid);
615+
var apiEndpoint = $"https://{dbGuid}-{dbInfo.Info.Region}.apps.astra.datastax.com";
616+
var database = _client.GetDatabase(apiEndpoint);
617+
return new DatabaseAdminAstra(database, _client, null);
645618
}
646619

647620
/// <summary>

0 commit comments

Comments
 (0)