/** * Sharding - Horizontal data partitioning for scaling * * Distributes data across shards for linear scalability: * - Consistent hashing for automatic shard assignment * - Hotspot detection based on metrics * - Automatic rebalancing recommendations * - Multi-shard query support */ export type ShardingStrategy = 'consistent-hash' | 'range-based' | 'key-modulo'; export interface ShardKey { field: string; hashFunction: string; } export interface ShardRange { shardId: string; startHash: number; endHash: number; replicaNodes: string[]; } export interface ShardMetrics { shardId: string; entryCount: number; sizeBytes: number; reads: number; writes: number; avgQueryTimeMs: number; } export interface HotspotAlert { shardId: string; reason: string; metricValue: number; threshold: number; severity: 'low' | 'medium' | 'high'; } export interface RebalanceOperation { sourceShard: string; targetShard: string; keyRangeStart: number; keyRangeEnd: number; estimatedRecords: number; priority: number; } export interface ShardDistributionSummary { numShards: number; totalEntries: number; totalSizeBytes: number; totalReads: number; totalWrites: number; maxEntriesPerShard: number; minEntriesPerShard: number; imbalanceRatio: number; } /** * Shard Manager - TypeScript implementation */ export declare class ShardManager { private shardingKey; private strategy; private shardRanges; private shardMetrics; private rebalanceHistory; private rebalanceThreshold; constructor(shardingKey: ShardKey, strategy?: ShardingStrategy); /** * Hash a value using simple algorithm */ private hashValue; /** * Initialize shards */ initializeShards(shardIds: string[], replicaNodes?: Record): void; /** * Get shard for a key */ getShardForKey(key: string): ShardRange | null; /** * Get replica nodes for a key */ getReplicasForKey(key: string): string[]; /** * Record a shard operation */ recordShardOperation(shardId: string, operation: 'read' | 'write' | 'delete', timeMs: number, recordsAffected: number, sizeBytes: number): void; /** * Get all shard metrics */ getAllMetrics(): ShardMetrics[]; /** * Detect hotspots */ detectHotspots(): HotspotAlert[]; /** * Generate rebalance operations */ generateRebalanceOps(): RebalanceOperation[]; /** * Get distribution summary */ getDistributionSummary(): ShardDistributionSummary; /** * Record a rebalance operation */ recordRebalance(operation: RebalanceOperation): void; /** * Get rebalance history */ getRebalanceHistory(): RebalanceOperation[]; /** * Calculate standard deviation */ private calculateStdDev; } /** * Shard Router - Routes queries to appropriate shards */ export declare class ShardRouter { private shardManager; private shardConnections; constructor(shardManager: ShardManager); /** * Route a query to appropriate shards */ routeQuery(key: string): string[]; /** * Route a range query to multiple shards */ routeRangeQuery(keyPattern: string): string[]; /** * Register shard connection */ registerShardConnection(shardId: string, connection: any): void; /** * Get shard connection */ getShardConnection(shardId: string): any; } /** * Rebalancer - Coordinates data migration between shards */ export declare class Rebalancer { private shardManager; private shardRouter; private rebalanceInProgress; constructor(shardManager: ShardManager, shardRouter: ShardRouter); /** * Start automatic rebalancing */ startAutoRebalance(intervalMs?: number): Promise; /** * Perform rebalancing */ performRebalance(): Promise; /** * Check if rebalancing is needed */ isRebalanceNeeded(): boolean; } //# sourceMappingURL=sharding.d.ts.map