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 all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -36,11 +36,10 @@
private final String authorName;
private final String authorEmail;
private final String message;
private final Repository localRepository;
private final StorageSerializer<T> serializer;
private final StorageDeserializer<T> deserializer;
private final Repository localRepository;

private Hash hash;
private RepositoryStorage<T> repositoryStorage;
private Set<T> current;

@@ -54,27 +53,36 @@
this.serializer = serializer;
this.deserializer = deserializer;

try {
Repository localRepository;
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 {
localRepository = Repository.materialize(localStorage, repository.url(), "+" + ref + ":storage");
try {
return Repository.materialize(localStorage, repository.url(), "+" + ref + ":storage");
} catch (IOException ignored) {
// The remote ref may not yet exist
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;
}
} catch (IOException e) {
// The remote ref may not yet exist
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);
lastException = e;
}
this.localRepository = localRepository;
hash = localRepository.head();
repositoryStorage = new RepositoryStorage<>(localRepository, fileName, authorName, authorEmail, message, serializer, deserializer);
current = current();
} catch (IOException e) {
throw new UncheckedIOException(e);
retryCount++;
}
throw new UncheckedIOException("Retry count exceeded", lastException);
}

@Override
@@ -100,7 +108,6 @@ public void put(Collection<T> items) {
try {
var updatedHash = localRepository.head();
localRepository.push(updatedHash, hostedRepository.url(), ref);
hash = updatedHash;
current = updated;
return;
} catch (IOException e) {