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
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
/**
|
|
* Distributed Query Planner for Brainy 3.0
|
|
*
|
|
* Intelligently plans and executes distributed queries across shards
|
|
* Optimizes for data locality, parallelism, and network efficiency
|
|
*/
|
|
import type { StorageAdapter } from '../coreTypes.js';
|
|
import type { DistributedCoordinator } from './coordinator.js';
|
|
import type { ShardManager } from './shardManager.js';
|
|
import type { HTTPTransport } from './httpTransport.js';
|
|
import type { TripleIntelligenceEngine } from '../triple/TripleIntelligence.js';
|
|
export interface QueryPlan {
|
|
/**
|
|
* Shards that need to be queried
|
|
*/
|
|
shards: string[];
|
|
/**
|
|
* Nodes responsible for each shard
|
|
*/
|
|
nodeAssignments: Map<string, string[]>;
|
|
/**
|
|
* Whether query can be parallelized
|
|
*/
|
|
parallel: boolean;
|
|
/**
|
|
* Estimated cost (0-1000)
|
|
*/
|
|
cost: number;
|
|
/**
|
|
* Query strategy
|
|
*/
|
|
strategy: 'broadcast' | 'targeted' | 'scatter-gather' | 'local-only';
|
|
}
|
|
export interface DistributedQueryResult {
|
|
results: any[];
|
|
totalCount: number;
|
|
executionTime: number;
|
|
nodeStats: Map<string, {
|
|
resultsReturned: number;
|
|
executionTime: number;
|
|
errors?: string[];
|
|
}>;
|
|
}
|
|
export declare class DistributedQueryPlanner {
|
|
private nodeId;
|
|
private coordinator;
|
|
private shardManager;
|
|
private transport;
|
|
private tripleEngine?;
|
|
private storage;
|
|
constructor(nodeId: string, coordinator: DistributedCoordinator, shardManager: ShardManager, transport: HTTPTransport, storage: StorageAdapter, tripleEngine?: TripleIntelligenceEngine);
|
|
/**
|
|
* Plan a distributed query
|
|
*/
|
|
planQuery(query: any): Promise<QueryPlan>;
|
|
/**
|
|
* Execute a distributed query based on plan
|
|
*/
|
|
executeQuery(query: any, plan: QueryPlan): Promise<DistributedQueryResult>;
|
|
/**
|
|
* Execute query on local shards
|
|
*/
|
|
private executeLocalQuery;
|
|
/**
|
|
* Execute query on remote node
|
|
*/
|
|
private executeRemoteQuery;
|
|
/**
|
|
* Get data from a specific shard
|
|
*/
|
|
private getShardData;
|
|
/**
|
|
* Filter data based on query criteria
|
|
*/
|
|
private filterData;
|
|
/**
|
|
* Check if item matches filter
|
|
*/
|
|
private matchesFilter;
|
|
/**
|
|
* Merge results from multiple nodes using Triple Intelligence
|
|
*/
|
|
private mergeResults;
|
|
/**
|
|
* Simple deduplication of results
|
|
*/
|
|
private deduplicateResults;
|
|
/**
|
|
* Get unique key for result
|
|
*/
|
|
private getResultKey;
|
|
/**
|
|
* Determine query type
|
|
*/
|
|
private getQueryType;
|
|
/**
|
|
* Determine which shards are affected by query
|
|
*/
|
|
private determineAffectedShards;
|
|
/**
|
|
* Optimize query plan based on statistics
|
|
*/
|
|
optimizePlan(plan: QueryPlan): Promise<QueryPlan>;
|
|
}
|