Skip to content

Commit bd5958e

Browse files
authored
Merge pull request #537 from tidesdb/cs-red
update csharp reference based on v0.6.4
2 parents 830b4f1 + 09b85e3 commit bd5958e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/content/docs/reference/csharp.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ db.PromoteToPrimary();
179179
// Now writes are accepted
180180
```
181181

182+
When the object store enforces conditional writes, promotion acquires the primary lease by advancing its epoch with a compare-and-swap. If another node already holds the lease the call is refused with `ErrorCode.Precondition` (the node stays a working replica for an orchestrator to retry); it throws `ErrorCode.InvalidArgs` if the node is already a primary. The active lease epoch is observable through `DbStats.PrimaryEpoch` (held by this node) and `DbStats.SeenEpoch` (highest observed).
183+
184+
```csharp
185+
try
186+
{
187+
db.PromoteToPrimary();
188+
}
189+
catch (TidesDBException ex) when (ex.ErrorCode == ErrorCode.Precondition)
190+
{
191+
// Another node won the promotion race; remain a replica and let the orchestrator retry.
192+
}
193+
```
194+
182195
**Object Store Configuration Options**
183196

184197
| Property | Type | Default | Description |
@@ -975,8 +988,9 @@ catch (TidesDBException ex)
975988
- `TDB_ERR_LOCKED` (-12) · Database is locked
976989
- `TDB_ERR_READONLY` (-13) · Database is read-only
977990
- `TDB_ERR_BUSY` (-14) · Resource busy
991+
- `TDB_ERR_PRECONDITION` (-15) · A conditional object-store write failed its precondition (HTTP 412). Raised by single-writer fencing — e.g. `PromoteToPrimary` when another node already holds the primary lease
978992

979-
These map to the `ErrorCode` enum (`ErrorCode.Locked`, `ErrorCode.Readonly`, `ErrorCode.Busy`, …) exposed on `TidesDBException.ErrorCode`.
993+
These map to the `ErrorCode` enum (`ErrorCode.Locked`, `ErrorCode.Readonly`, `ErrorCode.Busy`, `ErrorCode.Precondition`, …) exposed on `TidesDBException.ErrorCode`.
980994

981995
## Complete Example
982996

@@ -1237,7 +1251,12 @@ Console.WriteLine($"Unified is flushing: {dbStats.UnifiedIsFlushing}");
12371251

12381252
// Object store stats (when enabled)
12391253
Console.WriteLine($"Object store enabled: {dbStats.ObjectStoreEnabled}");
1254+
Console.WriteLine($"Object store connector: {dbStats.ObjectStoreConnector}");
12401255
Console.WriteLine($"Replica mode: {dbStats.ReplicaMode}");
1256+
1257+
// Single-writer fencing (object store mode)
1258+
Console.WriteLine($"Primary epoch (held): {dbStats.PrimaryEpoch}");
1259+
Console.WriteLine($"Seen epoch (highest observed): {dbStats.SeenEpoch}");
12411260
```
12421261

12431262
:::note[Stack Allocated]
@@ -1632,6 +1651,8 @@ Per-CF write amplification = (`WalBytesWritten` + `FlushBytesWritten` + `Compact
16321651
| `TotalUploads` | ulong | Lifetime count of objects uploaded to object store |
16331652
| `TotalUploadFailures` | ulong | Lifetime count of permanently failed uploads |
16341653
| `ReplicaMode` | bool | Whether running in read-only replica mode |
1654+
| `PrimaryEpoch` | ulong | Single-writer fencing (object store mode): the lease epoch this primary currently holds (0 when not a primary / no lease) |
1655+
| `SeenEpoch` | ulong | Single-writer fencing (object store mode): the highest lease epoch this node has observed in the store |
16351656
| `UwalBytesWritten` | ulong | Framed bytes appended to the shared unified WAL (0 if unified mode off) |
16361657
| `WalBytesWritten` | ulong | Per-CF WAL bytes summed across all column families |
16371658
| `FlushBytesWritten` | ulong | Flush output bytes summed across all column families |

0 commit comments

Comments
 (0)