From 1897d67818a1bf1990bf7ed235e015ac8bbffce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 18 Feb 2020 12:21:47 +0100 Subject: [PATCH] EventIndexPanel: Catch getStats failures. Getting the stats can fail when used with Seshat. Tantivy periodically garbage collects its files. Smaller files are merged and the old ones are removed. If garbage collection occurs while we try to get the stats, which go trough the files and figure out their sizes, we can end up trying to figure out the file size of a removed file. The getStats call will fail in this case but we can ignore the failure since we will likely get a nice result next time we try. --- .../eventindex/ManageEventIndexDialog.js | 21 +++++++++++++++---- .../views/settings/EventIndexPanel.js | 19 +++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js index fa00477c1a..aea37c1875 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js @@ -48,7 +48,16 @@ export default class ManageEventIndexDialog extends React.Component { updateCurrentRoom = async(room) => { const eventIndex = EventIndexPeg.get(); - const stats = await eventIndex.getStats(); + let stats; + + // This call may fail if sporadically, not a huge issue as we will try + // later again and probably succeed. + try { + stats = await eventIndex.getStats(); + } catch { + return; + } + let currentRoom = null; if (room) currentRoom = room.name; @@ -85,12 +94,16 @@ export default class ManageEventIndexDialog extends React.Component { if (eventIndex !== null) { eventIndex.on("changedCheckpoint", this.updateCurrentRoom); - const stats = await eventIndex.getStats(); + try { + const stats = await eventIndex.getStats(); + eventIndexSize = stats.size; + eventCount = stats.eventCount; + } catch { + } + const roomStats = eventIndex.crawlingRooms(); - eventIndexSize = stats.size; crawlingRoomsCount = roomStats.crawlingRooms.size; roomCount = roomStats.totalRooms.size; - eventCount = stats.eventCount; const room = eventIndex.currentRoom(); if (room) currentRoom = room.name; diff --git a/src/components/views/settings/EventIndexPanel.js b/src/components/views/settings/EventIndexPanel.js index ded62354cb..c74d99cec9 100644 --- a/src/components/views/settings/EventIndexPanel.js +++ b/src/components/views/settings/EventIndexPanel.js @@ -39,7 +39,15 @@ export default class EventIndexPanel extends React.Component { updateCurrentRoom = async (room) => { const eventIndex = EventIndexPeg.get(); - const stats = await eventIndex.getStats(); + let stats; + + // This call may fail if sporadically, not a huge issue as we will try + // later again and probably succeed. + try { + stats = await eventIndex.getStats(); + } catch { + return; + } this.setState({ eventIndexSize: stats.size, @@ -70,9 +78,12 @@ export default class EventIndexPanel extends React.Component { if (eventIndex !== null) { eventIndex.on("changedCheckpoint", this.updateCurrentRoom); - const stats = await eventIndex.getStats(); - eventIndexSize = stats.size; - roomCount = stats.roomCount; + try { + const stats = await eventIndex.getStats(); + eventIndexSize = stats.size; + roomCount = stats.roomCount; + } catch { + } } this.setState({