Troubleshooting Guide¶
Common issues, solutions, and frequently asked questions for DTDE.
Table of Contents¶
Common Issues¶
Empty Query Results¶
Symptom: Queries return no results when data exists.
Possible Causes:
-
Shards not configured
-
Shard key mismatch
-
Case sensitivity
- Default: Case-sensitive matching
- Ensure shard key values match exactly
Solution:
// Ensure shard configuration matches data
dtde.AddShard(s => s
.WithId("EU")
.WithShardKeyValue("EU")); // Must match data exactly
// If data has "eu" (lowercase), configure accordingly:
dtde.AddShard(s => s
.WithId("EU")
.WithShardKeyValue("eu"));
"No Shards Found" Error¶
Symptom: No shards found for entity type 'X'
Causes: 1. Entity not configured for sharding 2. Shard registry empty 3. Predicate doesn't match any shard
Solutions:
-
Add sharding configuration:
-
Add shard definitions:
-
Enable diagnostics to debug:
Temporal Query Issues¶
Symptom: ValidAt() returns all records or no records.
Causes: 1. Entity not configured for temporal 2. Date property values incorrect 3. Null handling issue
Solutions:
-
Ensure temporal configuration:
-
Check date values:
-
Handle null end dates:
nullExpirationDate = currently valid- Ensure this matches your data
SaveChanges Fails¶
Symptom: SaveChangesAsync() throws exception.
Common Causes:
- Write to read-only shard:
Solution: Check shard is writable:
var shard = context.ShardRegistry.GetShard("archive-2020");
if (shard.IsReadOnly)
{
// Route to different shard or reject
}
- Shard key changed:
- Changing shard key value on update requires special handling
-
Entity would need to move between shards
-
Connection issues:
- Verify connection strings for database sharding
- Check network connectivity
Error Messages¶
"Shard key property 'X' not found"¶
Cause: Property name in ShardBy() doesn't exist.
Solution:
// Ensure property exists and spelling is correct
entity.ShardBy(c => c.Region); // Property must exist on Customer
"Multiple shards found for write operation"¶
InvalidOperationException: Multiple shards match for write operation. Cannot determine target shard.
Cause: Shard configuration overlaps.
Solution:
// Ensure shard key values don't overlap
dtde.AddShard(s => s.WithShardKeyValue("EU")); // Unique
dtde.AddShard(s => s.WithShardKeyValue("US")); // Unique
"Shard configuration file not found"¶
Solution:
// Use absolute path or ensure file is in correct location
var path = Path.Combine(AppContext.BaseDirectory, "shards.json");
dtde.AddShardsFromConfig(path);
"Cannot create context for shard"¶
Cause: Database shard missing connection string.
Solution:
dtde.AddShard(s => s
.WithId("shard-eu")
.WithConnectionString("Server=...;Database=...")); // Required for database sharding
Performance Issues¶
Slow Cross-Shard Queries¶
Symptom: Queries spanning multiple shards are slow.
Diagnosis:
Solutions:
-
Optimize shard predicates:
-
Increase parallelism:
-
Add indexes:
High Memory Usage¶
Symptom: Memory grows during large queries.
Solutions:
-
Use streaming:
-
Implement pagination:
-
Use projections:
Connection Pool Exhaustion¶
Symptom: TimeoutException on high load.
Solutions:
-
Increase pool size:
-
Reduce parallel shards:
-
Use connection pooling per shard:
Configuration Problems¶
DbContext Not Using DTDE¶
Symptom: Standard EF Core behavior, no sharding.
Checklist: - [ ] Inherits from DtdeDbContext - [ ] UseDtde() called in options - [ ] Entity has sharding configuration
// ✅ Correct
public class AppDbContext : DtdeDbContext { }
// ❌ Wrong
public class AppDbContext : DbContext { }
Shards Not Loading from JSON¶
Symptom: AddShardsFromConfig() has no effect.
Solutions:
-
Check file path:
-
Validate JSON format:
-
Check for JSON errors:
Entity Configuration Not Applied¶
Symptom: Sharding/temporal not working for specific entity.
Checklist: - [ ] base.OnModelCreating(modelBuilder) called first - [ ] Configuration in correct entity block
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder); // ✅ Must call first
modelBuilder.Entity<Customer>(entity =>
{
entity.ShardBy(c => c.Region); // ✅ Inside Entity<> block
});
}
FAQ¶
Can I use DTDE with existing databases?¶
Yes. DTDE works with pre-existing tables:
Can entities use only temporal without sharding?¶
Yes. Configure temporal only:
modelBuilder.Entity<Contract>(entity =>
{
// No ShardBy() - uses single table
entity.HasTemporalValidity(c => c.ValidFrom, c => c.ValidTo);
});
How do I handle shard key changes?¶
Shard key changes require special handling:
// Option 1: Delete from old shard, insert to new
var customer = await db.Customers.FindAsync(id);
db.Customers.Remove(customer);
await db.SaveChangesAsync();
customer.Region = "EU"; // New shard key
db.Customers.Add(customer);
await db.SaveChangesAsync();
// Option 2: Implement move logic in application
Does DTDE support transactions across shards?¶
Not in v1. Cross-shard transactions are a non-goal for the initial release.
For consistency across shards: - Use eventual consistency patterns - Implement saga/compensation patterns - Use distributed transaction coordinators (external)
Can I mix sharded and non-sharded entities?¶
Yes. Only configured entities use DTDE features:
// Sharded
modelBuilder.Entity<Order>().ShardBy(o => o.Year);
// Non-sharded (standard EF Core)
modelBuilder.Entity<Setting>(); // No ShardBy()
How do I unit test with DTDE?¶
Use test mode or mock the context:
// Option 1: Enable test mode
options.UseDtde(dtde => dtde.EnableTestMode());
// Option 2: Use in-memory database for tests
options.UseInMemoryDatabase("TestDb");
options.UseDtde();
What databases are supported?¶
Currently: SQL Server only (v1).
Future versions may support: - PostgreSQL - MySQL - Azure Cosmos DB
Getting Help¶
Enable Diagnostics¶
Collect Debug Information¶
// Log shard information
var shards = context.ShardRegistry.GetAllShards();
foreach (var shard in shards)
{
logger.LogDebug("Shard: {Id}, Key: {Key}, Table: {Table}",
shard.ShardId, shard.ShardKeyValue, shard.TableName);
}
// Log entity metadata
var metadata = context.MetadataRegistry.GetEntityMetadata<Customer>();
logger.LogDebug("Entity: {Type}, HasSharding: {Sharding}, HasTemporal: {Temporal}",
metadata?.EntityType.Name,
metadata?.ShardingConfiguration != null,
metadata?.ValidityConfiguration != null);
Report Issues¶
When reporting issues, include:
- DTDE version
- .NET version
- EF Core version
- Configuration (sanitized)
- Error message (full stack trace)
- Minimal reproduction steps
Next Steps¶
- API Reference - Complete API documentation
- Configuration - Configuration options
- Architecture - System design