Skip to content

Commit d405af7

Browse files
committed
Handle shutdown
1 parent 606791e commit d405af7

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

experiment/src/org/labkey/experiment/api/ExpMaterialImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.labkey.api.data.Table;
3838
import org.labkey.api.data.TableInfo;
3939
import org.labkey.api.data.TableSelector;
40+
import org.labkey.api.data.dialect.SqlDialect;
4041
import org.labkey.api.exp.ObjectProperty;
4142
import org.labkey.api.exp.OntologyManager;
4243
import org.labkey.api.exp.PropertyDescriptor;
@@ -497,7 +498,18 @@ private void getCustomIndexValues(
497498
for (ExpMaterialTable.Column column : ExpMaterialTable.Column.values())
498499
skipColumns.add(column.name());
499500

500-
processIndexValues(props, table, skipColumns, identifiersHi, new HashSet<>(), new HashSet<>(), keywordsHi, new HashSet<>(), new HashSet<>(), jsonData);
501+
try
502+
{
503+
processIndexValues(props, table, skipColumns, identifiersHi, new HashSet<>(), new HashSet<>(), keywordsHi, new HashSet<>(), new HashSet<>(), jsonData);
504+
}
505+
catch (RuntimeException x)
506+
{
507+
// Cached temp table torn down concurrently (schema-change re-index); retry once via the live join.
508+
if (!SqlDialect.isObjectNotFoundException(x))
509+
throw x;
510+
table.uncacheMaterializedView();
511+
processIndexValues(props, table, skipColumns, identifiersHi, new HashSet<>(), new HashSet<>(), keywordsHi, new HashSet<>(), new HashSet<>(), jsonData);
512+
}
501513
}
502514

503515
static final List<Pair<Long,Long>> updateLastIndexedList = new ArrayList<>();

experiment/src/org/labkey/experiment/api/ExpMaterialTableImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import org.labkey.api.security.permissions.ReadPermission;
120120
import org.labkey.api.security.permissions.UpdatePermission;
121121
import org.labkey.api.test.TestWhen;
122+
import org.labkey.api.util.ContextListener;
122123
import org.labkey.api.util.GUID;
123124
import org.labkey.api.util.HeartBeat;
124125
import org.labkey.api.util.JunitUtil;
@@ -1377,12 +1378,23 @@ private _MaterializedQueryHelper getOrCreateMQH()
13771378
});
13781379
}
13791380

1381+
/** Drop the cached materialized helper for this table's sample type so the next read rebuilds (or uses the live join). */
1382+
void uncacheMaterializedView()
1383+
{
1384+
if (null != _ss)
1385+
_materializedQueries.remove(_ss.getLSID());
1386+
}
1387+
13801388
/* SELECT and JOIN, does not include WHERE, same as getJoinSQL() */
13811389
private @Nullable SQLFragment getMaterializedSQL()
13821390
{
13831391
if (null == _ss)
13841392
return getJoinSQL(null);
13851393

1394+
// Skip the materialized path during shutdown; temp-table cleanup can drop it mid-read (42P01), so use the live join.
1395+
if (ContextListener.isShuttingDown())
1396+
return null;
1397+
13861398
var mqh = getOrCreateMQH();
13871399

13881400
SQLFragment tempRef = mqh.tryGetFromSqlIfLoaded("_cached_view_");

search/src/org/labkey/search/model/AbstractSearchService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.labkey.api.util.Path;
5858
import org.labkey.api.util.QuietCloser;
5959
import org.labkey.api.util.ShutdownListener;
60+
import org.labkey.api.util.ShuttingDownException;
6061
import org.labkey.api.util.StringUtilsLabKey;
6162
import org.labkey.api.util.SystemMaintenance;
6263
import org.labkey.api.util.SystemMaintenance.MaintenanceTask;
@@ -1155,15 +1156,18 @@ public Container getContainer()
11551156
catch (Throwable x)
11561157
{
11571158
success = false;
1158-
try
1159-
{
1160-
ExceptionUtil.logExceptionToMothership(null, x);
1161-
}
1162-
catch (Throwable t)
1159+
if (!(_shuttingDown || x instanceof ShuttingDownException))
11631160
{
1164-
/* */
1161+
try
1162+
{
1163+
ExceptionUtil.logExceptionToMothership(null, x);
1164+
}
1165+
catch (Throwable t)
1166+
{
1167+
/* */
1168+
}
1169+
_log.error("Error running {}", null != i ? i._id : "", x);
11651170
}
1166-
_log.error("Error running {}", null != i ? i._id : "", x);
11671171
}
11681172
finally
11691173
{

0 commit comments

Comments
 (0)