CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
160 lines
3.7 KiB
TypeScript
160 lines
3.7 KiB
TypeScript
/**
|
|
* Storage-based Discovery for Zero-Config Distributed Brainy
|
|
* Uses shared storage (S3/GCS/R2) as coordination point
|
|
* REAL PRODUCTION CODE - No mocks, no stubs!
|
|
*/
|
|
import { EventEmitter } from 'events';
|
|
import { StorageAdapter } from '../coreTypes.js';
|
|
export interface NodeInfo {
|
|
id: string;
|
|
endpoint: string;
|
|
hostname: string;
|
|
started: number;
|
|
lastSeen: number;
|
|
role: 'primary' | 'replica' | 'candidate';
|
|
shards: string[];
|
|
capacity: {
|
|
cpu: number;
|
|
memory: number;
|
|
storage: number;
|
|
};
|
|
stats: {
|
|
nouns: number;
|
|
verbs: number;
|
|
queries: number;
|
|
latency: number;
|
|
};
|
|
}
|
|
export interface ClusterConfig {
|
|
version: number;
|
|
created: number;
|
|
updated: number;
|
|
leader: string | null;
|
|
nodes: Record<string, NodeInfo>;
|
|
shards: {
|
|
count: number;
|
|
assignments: Record<string, string[]>;
|
|
};
|
|
settings: {
|
|
replicationFactor: number;
|
|
shardCount: number;
|
|
autoRebalance: boolean;
|
|
minNodes: number;
|
|
maxNodesPerShard: number;
|
|
};
|
|
}
|
|
export declare class StorageDiscovery extends EventEmitter {
|
|
private nodeId;
|
|
private storage;
|
|
private nodeInfo;
|
|
private clusterConfig;
|
|
private heartbeatInterval;
|
|
private discoveryInterval;
|
|
private endpoint;
|
|
private isRunning;
|
|
private readonly HEARTBEAT_INTERVAL;
|
|
private readonly DISCOVERY_INTERVAL;
|
|
private readonly NODE_TIMEOUT;
|
|
private readonly CLUSTER_PATH;
|
|
constructor(storage: StorageAdapter, nodeId?: string);
|
|
/**
|
|
* Start discovery and registration
|
|
*/
|
|
start(httpPort: number): Promise<ClusterConfig>;
|
|
/**
|
|
* Stop discovery and unregister
|
|
*/
|
|
stop(): Promise<void>;
|
|
/**
|
|
* Initialize a new cluster (we're the first node)
|
|
*/
|
|
private initializeCluster;
|
|
/**
|
|
* Join an existing cluster
|
|
*/
|
|
private joinCluster;
|
|
/**
|
|
* Leave cluster cleanly
|
|
*/
|
|
private leaveCluster;
|
|
/**
|
|
* Register node in storage
|
|
*/
|
|
private registerNode;
|
|
/**
|
|
* Heartbeat to keep node alive
|
|
*/
|
|
private startHeartbeat;
|
|
/**
|
|
* Discover other nodes and monitor health
|
|
*/
|
|
private startDiscovery;
|
|
/**
|
|
* Discover nodes from storage
|
|
*/
|
|
private discoverNodes;
|
|
/**
|
|
* Load node registry from storage
|
|
*/
|
|
private loadNodeRegistry;
|
|
/**
|
|
* Update node registry in storage
|
|
*/
|
|
private updateNodeRegistry;
|
|
/**
|
|
* Check health of known nodes
|
|
*/
|
|
private checkNodeHealth;
|
|
/**
|
|
* Load cluster configuration from storage
|
|
*/
|
|
private loadClusterConfig;
|
|
/**
|
|
* Save cluster configuration to storage
|
|
*/
|
|
private saveClusterConfig;
|
|
/**
|
|
* Trigger leader election (simplified - not full Raft)
|
|
*/
|
|
private triggerLeaderElection;
|
|
/**
|
|
* Request shard assignment for this node
|
|
*/
|
|
private requestShardAssignment;
|
|
/**
|
|
* Check if rebalancing is needed
|
|
*/
|
|
private shouldRebalance;
|
|
/**
|
|
* Trigger shard rebalancing
|
|
*/
|
|
private triggerRebalance;
|
|
/**
|
|
* Redistribute shards among active nodes
|
|
*/
|
|
private redistributeShards;
|
|
/**
|
|
* Detect our public endpoint
|
|
*/
|
|
private detectEndpoint;
|
|
/**
|
|
* Generate unique node ID
|
|
*/
|
|
private generateNodeId;
|
|
/**
|
|
* Get current cluster configuration
|
|
*/
|
|
getClusterConfig(): ClusterConfig | null;
|
|
/**
|
|
* Get active nodes
|
|
*/
|
|
getActiveNodes(): NodeInfo[];
|
|
/**
|
|
* Get shards assigned to this node
|
|
*/
|
|
getMyShards(): string[];
|
|
/**
|
|
* Update node statistics
|
|
*/
|
|
updateStats(stats: Partial<NodeInfo['stats']>): void;
|
|
}
|