use of oap.storage.migration.JsonMetadata in project oap by oaplatform.
the class FsPersistenceBackend method migration.
@SneakyThrows
private Path migration(Path path) {
return Threads.synchronously(lock, () -> {
JsonMetadata oldV = new JsonMetadata(Binder.json.unmarshal(new TypeReference<Map<String, Object>>() {
}, path));
Persisted fn = Persisted.valueOf(path);
log.debug("migration {}", fn);
val migration = Lists.find2(migrations, m -> m.fromVersion() == fn.version);
if (migration == null)
throw new FileStorageMigrationException("migration from version " + fn + " not found");
Path name = fn.toVersion(migration.fromVersion() + 1);
JsonMetadata newV = migration.run(oldV);
long writeLen = -1;
while (name.toFile().length() != writeLen) {
try (val out = new CountingOutputStream(IoStreams.out(name, PLAIN, DEFAULT_BUFFER, false, true))) {
Binder.json.marshal(out, newV.underlying);
writeLen = out.getCount();
}
}
Files.delete(path);
return name;
});
}
Aggregations