|
48 | 48 | import io.evitadb.api.requestResponse.schema.mutation.catalog.RemoveCatalogSchemaMutation; |
49 | 49 | import io.evitadb.api.task.ServerTask; |
50 | 50 | import io.evitadb.core.SessionRegistry.SuspendOperation; |
| 51 | +import io.evitadb.core.SessionRegistry.SuspensionInformation; |
51 | 52 | import io.evitadb.core.async.ClientRunnableTask; |
52 | 53 | import io.evitadb.core.async.EmptySettings; |
53 | 54 | import io.evitadb.core.async.ObservableExecutorServiceWithHardDeadline; |
@@ -326,6 +327,28 @@ public void emitStartObservabilityEvents() { |
326 | 327 | ); |
327 | 328 | } |
328 | 329 |
|
| 330 | + /** |
| 331 | + * Checks if sessions were forcefully closed for the specified catalog and session ID. |
| 332 | + * |
| 333 | + * @param catalogName the name of the catalog for which to check if sessions were forcefully closed; must not be null |
| 334 | + * @param sessionId the unique identifier of the session to check; must not be null |
| 335 | + * @return true if sessions were forcefully closed for the specified catalog and session ID, false otherwise |
| 336 | + */ |
| 337 | + public boolean wasSessionForcefullyClosedForCatalog(@Nonnull String catalogName, @Nonnull UUID sessionId) { |
| 338 | + return ofNullable(this.catalogSessionRegistries.get(catalogName)) |
| 339 | + .map(it -> it.wereSessionsForcefullyClosedForCatalog(sessionId)) |
| 340 | + .orElse(false); |
| 341 | + } |
| 342 | + |
| 343 | + /** |
| 344 | + * Clears all session registries and their temporary information. |
| 345 | + */ |
| 346 | + public void clearSessionRegistries() { |
| 347 | + for (SessionRegistry value : this.catalogSessionRegistries.values()) { |
| 348 | + value.clearTemporaryInformation(); |
| 349 | + } |
| 350 | + } |
| 351 | + |
329 | 352 | /** |
330 | 353 | * Emits statistics of the ThreadPool associated with the scheduler. |
331 | 354 | */ |
@@ -741,6 +764,29 @@ ServerTask<EmptySettings, Void> createLoadCatalogTask(@Nonnull String catalogNam |
741 | 764 | ); |
742 | 765 | } |
743 | 766 |
|
| 767 | + /** |
| 768 | + * Closes all active sessions associated with the specified catalog and suspends further operations. |
| 769 | + * |
| 770 | + * @param catalogName the name of the catalog whose sessions are to be closed and suspended |
| 771 | + * @param suspendOperation the operation to be executed during the suspension of the catalog |
| 772 | + */ |
| 773 | + @Nonnull |
| 774 | + public Optional<SuspensionInformation> closeAllSessionsAndSuspend(@Nonnull String catalogName, @Nonnull SuspendOperation suspendOperation) { |
| 775 | + return ofNullable(this.catalogSessionRegistries.get(catalogName)) |
| 776 | + .flatMap(it -> it.closeAllActiveSessionsAndSuspend(suspendOperation)); |
| 777 | + } |
| 778 | + |
| 779 | + /** |
| 780 | + * Discards the suspension state of the session registry associated with the given catalog name, if present. |
| 781 | + * The method resumes operations for the session registry if it exists for the provided catalog name. |
| 782 | + * |
| 783 | + * @param catalogName The name of the catalog whose suspension state should be discarded. Must not be null. |
| 784 | + */ |
| 785 | + public void discardSuspension(@Nonnull String catalogName) { |
| 786 | + ofNullable(this.catalogSessionRegistries.get(catalogName)) |
| 787 | + .ifPresent(SessionRegistry::resumeOperations); |
| 788 | + } |
| 789 | + |
744 | 790 | /* |
745 | 791 | PRIVATE METHODS |
746 | 792 | */ |
@@ -962,6 +1008,9 @@ private void replaceCatalogReference(@Nonnull Catalog catalog) { |
962 | 1008 | } |
963 | 1009 | ); |
964 | 1010 |
|
| 1011 | + // discard suspension of the session registry for the catalog, if present |
| 1012 | + discardSuspension(catalogName); |
| 1013 | + |
965 | 1014 | // notify structural changes callbacks |
966 | 1015 | ofNullable(originalCatalog.get()) |
967 | 1016 | .ifPresent(it -> notifyStructuralChangeObservers(catalog, it)); |
|
0 commit comments