mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(storage): log effective storage mode at boot (#3495)
PersistentPathValidator now logs the effective storage mode once at INFO, making memory-mode data loss visible instead of silent. * Fix #2225 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
547090bdfb
commit
15eff7e4cd
2 files changed
+80
-7
No files matched your search
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.ResolvedServiceCatalog;
|
||||
import io.github.hectorvent.floci.core.common.ServiceDescriptor;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -20,6 +21,8 @@ import java.util.List;
|
||||
@ApplicationScoped
|
||||
public class PersistentPathValidator {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PersistentPathValidator.class);
|
||||
|
||||
private final ResolvedServiceCatalog catalog;
|
||||
private final EmulatorConfig config;
|
||||
|
||||
@@ -37,10 +40,13 @@ public class PersistentPathValidator {
|
||||
.filter(d -> d.enabled() && d.supportsStorage() && !"memory".equals(d.storageMode()))
|
||||
.toList();
|
||||
if (persistent.isEmpty()) {
|
||||
LOG.info("Storage mode: memory (state is NOT persisted across restarts)");
|
||||
return;
|
||||
}
|
||||
|
||||
Path root = Path.of(config.storage().persistentPath());
|
||||
LOG.infov("Storage mode: persistent (state for {0} is written to {1})",
|
||||
describe(persistent), root.toAbsolutePath());
|
||||
try {
|
||||
probeWritable(root);
|
||||
Path s3Root = root.resolve("s3");
|
||||
@@ -49,20 +55,23 @@ public class PersistentPathValidator {
|
||||
probeWritable(s3Root);
|
||||
}
|
||||
} catch (IOException | SecurityException e) {
|
||||
String services = persistent.stream()
|
||||
.map(d -> d.storageKey() + "=" + d.storageMode())
|
||||
.distinct()
|
||||
.limit(8)
|
||||
.reduce((a, b) -> a + ", " + b)
|
||||
.orElse("");
|
||||
throw new IllegalStateException(
|
||||
"Persistent storage path '" + root.toAbsolutePath()
|
||||
+ "' is not writable, but non-memory storage is enabled (" + services
|
||||
+ "' is not writable, but non-memory storage is enabled (" + describe(persistent)
|
||||
+ "). Fix the volume mount permissions (it may be read-only or root-owned),"
|
||||
+ " or point FLOCI_STORAGE_PERSISTENT_PATH at a writable directory.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String describe(List<ServiceDescriptor> persistent) {
|
||||
return persistent.stream()
|
||||
.map(d -> d.storageKey() + "=" + d.storageMode())
|
||||
.distinct()
|
||||
.limit(8)
|
||||
.reduce((a, b) -> a + ", " + b)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
static void probeWritable(Path dir) throws IOException {
|
||||
Files.createDirectories(dir);
|
||||
Path probe = Files.createTempFile(dir, ".floci-write-probe", null);
|
||||
|
||||
Reference in new issue
Block a user