From 6cec2863d2ec95955cc6b465fba6f1f6f8cd029e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 17:47:10 +0000 Subject: [PATCH 1/4] Initial plan From ffab25fe39ba96101d059a1232f8bbb03a79b543 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 17:53:52 +0000 Subject: [PATCH 2/4] Review main.ts: fix logging, remove unused code, reorder methods Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com> --- main.ts | 56 ++++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/main.ts b/main.ts index 252149d..773d288 100644 --- a/main.ts +++ b/main.ts @@ -180,22 +180,20 @@ class EagerEngineScheduler { class ClusterManager { private nodes: Map; private localId: string; - private localAddr: string; - constructor(localId: string, localAddr: string) { + constructor(localId: string, _localAddr: string) { this.nodes = new Map(); this.localId = localId; - this.localAddr = localAddr; - } - - getAllOtherNodes(): NodeInfo[] { - return this.getAllNodes().filter((node) => node.id !== this.localId); } getAllNodes(): NodeInfo[] { return Array.from(this.nodes.values()); } + getAllOtherNodes(): NodeInfo[] { + return this.getAllNodes().filter((node) => node.id !== this.localId); + } + getAllNodeInfo(): Node[] { return this.getAllNodes().map((node) => ({ id: node.id, addr: node.addr })); } @@ -243,13 +241,11 @@ interface NetworkHandlerCallbacks { class NetworkHandler { private server: grpc.Server; - private id: string; private addr: string; private callbacks: NetworkHandlerCallbacks; - constructor(addr: string, id: string, callbacks: NetworkHandlerCallbacks) { + constructor(addr: string, _id: string, callbacks: NetworkHandlerCallbacks) { this.server = new grpc.Server(); - this.id = id; this.addr = addr; this.callbacks = callbacks; } @@ -419,7 +415,7 @@ class EagerNode { await this.syncDataWithNode(nodeClient); - console.log(`Joined node: ${node.id} at ${node.addr}`); + console.log(`Joining node: ${node.id} at ${node.addr}`); } } @@ -439,7 +435,7 @@ class EagerNode { try { await this.networkHandler.callLeave(currentNode, node.client); this.clusterManager.removeNode(node.id); - console.log(`Left node: ${node.id}`); + console.log(`Leaving node: ${node.id}`); } catch (error) { console.error(`Failed to leave node ${node.id}:`, error); } @@ -503,28 +499,20 @@ class EagerNode { } const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - try { - await this.networkHandler.callPushData(results, node.client); - } catch (error) { - console.error(`Failed to push data to node ${node.id}:`, error); - } + await this.networkHandler.callPushData(results, node.client); } } private async syncDataWithNode(client: NodeClient): Promise { - try { - const localData = this.engineScheduler.getData(); - if (localData.length > 0) { - await this.networkHandler.callPushData(localData, client); - } + const localData = this.engineScheduler.getData(); + if (localData.length > 0) { + await this.networkHandler.callPushData(localData, client); + } - const remoteData = await this.networkHandler.callPullData(client); - if (remoteData.length > 0) { - this.engineScheduler.addDataBatch(remoteData); - console.log(`Synced ${remoteData.length} data items from remote`); - } - } catch (error) { - console.error("Data sync failed:", error); + const remoteData = await this.networkHandler.callPullData(client); + if (remoteData.length > 0) { + this.engineScheduler.addDataBatch(remoteData); + console.log(`Synced ${remoteData.length} data items from remote`); } } @@ -545,11 +533,7 @@ class EagerNode { const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - try { - await this.networkHandler.callPushData([formatted], node.client); - } catch (error) { - console.error(`Failed to push input to node ${node.id}:`, error); - } + await this.networkHandler.callPushData([formatted], node.client); } } }); @@ -586,10 +570,6 @@ class EagerNode { console.log("========================\n"); }); } - - getNodeInfo(): { id: string; addr: string } { - return { id: this.id, addr: this.addr }; - } } function isIntegerString(str: string): boolean { From 12ed02424a0608376152854a6c03f935c2423ee2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 17:55:56 +0000 Subject: [PATCH 3/4] Keep try-catch blocks but remove error logging for data operations Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com> --- main.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/main.ts b/main.ts index 773d288..5cf857a 100644 --- a/main.ts +++ b/main.ts @@ -499,20 +499,28 @@ class EagerNode { } const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - await this.networkHandler.callPushData(results, node.client); + try { + await this.networkHandler.callPushData(results, node.client); + } catch (_error) { + // Silent failure when pushing data to other nodes + } } } private async syncDataWithNode(client: NodeClient): Promise { - const localData = this.engineScheduler.getData(); - if (localData.length > 0) { - await this.networkHandler.callPushData(localData, client); - } + try { + const localData = this.engineScheduler.getData(); + if (localData.length > 0) { + await this.networkHandler.callPushData(localData, client); + } - const remoteData = await this.networkHandler.callPullData(client); - if (remoteData.length > 0) { - this.engineScheduler.addDataBatch(remoteData); - console.log(`Synced ${remoteData.length} data items from remote`); + const remoteData = await this.networkHandler.callPullData(client); + if (remoteData.length > 0) { + this.engineScheduler.addDataBatch(remoteData); + console.log(`Synced ${remoteData.length} data items from remote`); + } + } catch (_error) { + // Silent failure when syncing data } } @@ -533,7 +541,11 @@ class EagerNode { const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - await this.networkHandler.callPushData([formatted], node.client); + try { + await this.networkHandler.callPushData([formatted], node.client); + } catch (_error) { + // Silent failure when pushing data to other nodes + } } } }); From fd272e95984d845bba65280317f1fb64bbb883ee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 18:01:17 +0000 Subject: [PATCH 4/4] Remove all try-catch blocks per requirement #5 Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com> --- main.ts | 93 ++++++++++++++++++++------------------------------------- 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/main.ts b/main.ts index 5cf857a..50a1c3c 100644 --- a/main.ts +++ b/main.ts @@ -404,27 +404,22 @@ class EagerNode { async joinCluster(joinAddr: string): Promise { const client = this.clusterManager.createNodeClient(joinAddr); - try { - const nodes = await this.networkHandler.callList(client); - const currentNode = { id: this.id, addr: this.addr }; + const nodes = await this.networkHandler.callList(client); + const currentNode = { id: this.id, addr: this.addr }; - for (const node of nodes) { - if (node.id !== this.id) { - const { client: nodeClient } = this.clusterManager.addNode(node.id, node.addr); - await this.networkHandler.callJoin(currentNode, nodeClient); + for (const node of nodes) { + if (node.id !== this.id) { + const { client: nodeClient } = this.clusterManager.addNode(node.id, node.addr); + await this.networkHandler.callJoin(currentNode, nodeClient); - await this.syncDataWithNode(nodeClient); + await this.syncDataWithNode(nodeClient); - console.log(`Joining node: ${node.id} at ${node.addr}`); - } + console.log(`Joining node: ${node.id} at ${node.addr}`); } - - client.cluster.close(); - client.engine.close(); - } catch (error) { - console.error(`Failed to join cluster at ${joinAddr}:`, error); - throw error; } + + client.cluster.close(); + client.engine.close(); } private async leaveCluster(): Promise { @@ -432,13 +427,9 @@ class EagerNode { const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - try { - await this.networkHandler.callLeave(currentNode, node.client); - this.clusterManager.removeNode(node.id); - console.log(`Leaving node: ${node.id}`); - } catch (error) { - console.error(`Failed to leave node ${node.id}:`, error); - } + await this.networkHandler.callLeave(currentNode, node.client); + this.clusterManager.removeNode(node.id); + console.log(`Leaving node: ${node.id}`); } } @@ -499,28 +490,20 @@ class EagerNode { } const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - try { - await this.networkHandler.callPushData(results, node.client); - } catch (_error) { - // Silent failure when pushing data to other nodes - } + await this.networkHandler.callPushData(results, node.client); } } private async syncDataWithNode(client: NodeClient): Promise { - try { - const localData = this.engineScheduler.getData(); - if (localData.length > 0) { - await this.networkHandler.callPushData(localData, client); - } + const localData = this.engineScheduler.getData(); + if (localData.length > 0) { + await this.networkHandler.callPushData(localData, client); + } - const remoteData = await this.networkHandler.callPullData(client); - if (remoteData.length > 0) { - this.engineScheduler.addDataBatch(remoteData); - console.log(`Synced ${remoteData.length} data items from remote`); - } - } catch (_error) { - // Silent failure when syncing data + const remoteData = await this.networkHandler.callPullData(client); + if (remoteData.length > 0) { + this.engineScheduler.addDataBatch(remoteData); + console.log(`Synced ${remoteData.length} data items from remote`); } } @@ -541,11 +524,7 @@ class EagerNode { const otherNodes = this.clusterManager.getAllOtherNodes(); for (const node of otherNodes) { - try { - await this.networkHandler.callPushData([formatted], node.client); - } catch (_error) { - // Silent failure when pushing data to other nodes - } + await this.networkHandler.callPushData([formatted], node.client); } } }); @@ -606,23 +585,17 @@ async function main() { const engine = new AtsdsSearchEngine(); const node = new EagerNode(engine, listenAddr); - try { - await node.start(); - - if (process.argv.length === 4) { - const joinAddr = addAddressPrefixForPort(process.argv[3], "127.0.0.1"); - console.log(`Joining cluster at ${joinAddr}...`); - await node.joinCluster(joinAddr); - } else { - console.log("Starting as first node in new cluster..."); - } + await node.start(); - process.stdin.resume(); - } catch (error) { - console.error("Failed to start node:", error); - await node.stop(); - process.exit(1); + if (process.argv.length === 4) { + const joinAddr = addAddressPrefixForPort(process.argv[3], "127.0.0.1"); + console.log(`Joining cluster at ${joinAddr}...`); + await node.joinCluster(joinAddr); + } else { + console.log("Starting as first node in new cluster..."); } + + process.stdin.resume(); } if (import.meta.main) {