Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

381: Retry failed materialization of hosted repository storage #617

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -38,9 +38,9 @@
private final String message;
private final StorageSerializer<T> serializer;
private final StorageDeserializer<T> deserializer;
private final Repository localRepository;

private RepositoryStorage<T> repositoryStorage;
private Repository localRepository;
private Set<T> current;

HostedRepositoryStorage(HostedRepository repository, Path localStorage, String ref, String fileName, String authorName, String authorEmail, String message, StorageSerializer<T> serializer, StorageDeserializer<T> deserializer) {
@@ -53,28 +53,30 @@
this.serializer = serializer;
this.deserializer = deserializer;

localRepository = tryMaterialize(repository, localStorage, ref, fileName, authorName, authorEmail, message);
repositoryStorage = new RepositoryStorage<>(localRepository, fileName, authorName, authorEmail, message, serializer, deserializer);
current = current();
}

private static Repository tryMaterialize(HostedRepository repository, Path localStorage, String ref, String fileName, String authorName, String authorEmail, String message) {
int retryCount = 0;
IOException lastException = null;

while (retryCount < 10) {
try {
Repository localRepository;
try {
localRepository = Repository.materialize(localStorage, repository.url(), "+" + ref + ":storage");
} catch (IOException e) {
return Repository.materialize(localStorage, repository.url(), "+" + ref + ":storage");
} catch (IOException ignored) {
// The remote ref may not yet exist
localRepository = Repository.init(localStorage, repository.repositoryType());
Repository localRepository = Repository.init(localStorage, repository.repositoryType());
var storage = Files.writeString(localStorage.resolve(fileName), "");
localRepository.add(storage);
var firstCommit = localRepository.commit(message, authorName, authorEmail);

// If the materialization failed for any other reason than the remote ref not existing, this will fail
localRepository.push(firstCommit, repository.url(), ref);
return localRepository;
}
this.localRepository = localRepository;
repositoryStorage = new RepositoryStorage<>(localRepository, fileName, authorName, authorEmail, message, serializer, deserializer);
current = current();
return;
} catch (IOException e) {
lastException = e;
}