Add checkedGet() to ProjectCache.
Currently get() squashes all exceptions to a null return value, making client unable to distinguish between not found or a transient error. Add a checkedGet() method, that raises IOException, when the exception is anything other than not found. Eventually, checkedGet() will replace get(), after all the callers have been updated to deal with the exception. Change-Id: I55294d0438cfc6164ca975a228006ad046d1961b
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/** Cache of project information, including access rights. */
|
||||
@@ -28,10 +29,21 @@ public interface ProjectCache {
|
||||
* Get the cached data for a project by its unique name.
|
||||
*
|
||||
* @param projectName name of the project.
|
||||
* @return the cached data; null if no such project exists.
|
||||
* @return the cached data; null if no such project exists or a error occured.
|
||||
* @see #checkedGet(com.google.gerrit.reviewdb.client.Project.NameKey)
|
||||
*/
|
||||
public ProjectState get(Project.NameKey projectName);
|
||||
|
||||
/**
|
||||
* Get the cached data for a project by its unique name.
|
||||
*
|
||||
* @param projectName name of the project.
|
||||
* @throws IOException when there was an error.
|
||||
* @return the cached data; null if no such project exists.
|
||||
*/
|
||||
public ProjectState checkedGet(Project.NameKey projectName)
|
||||
throws IOException;
|
||||
|
||||
/** Invalidate the cached information about the given project. */
|
||||
public void evict(Project p);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -34,6 +35,7 @@ import org.eclipse.jgit.lib.Repository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -101,13 +103,18 @@ public class ProjectCacheImpl implements ProjectCache {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached data for a project by its unique name.
|
||||
*
|
||||
* @param projectName name of the project.
|
||||
* @return the cached data; null if no such project exists.
|
||||
*/
|
||||
@Override
|
||||
public ProjectState get(final Project.NameKey projectName) {
|
||||
try {
|
||||
return checkedGet(projectName);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState checkedGet(Project.NameKey projectName)
|
||||
throws IOException {
|
||||
if (projectName == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -121,12 +128,14 @@ public class ProjectCacheImpl implements ProjectCache {
|
||||
} catch (ExecutionException e) {
|
||||
if (!(e.getCause() instanceof RepositoryNotFoundException)) {
|
||||
log.warn(String.format("Cannot read project %s", projectName.get()), e);
|
||||
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
|
||||
throw new IOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Invalidate the cached information about the given project. */
|
||||
@Override
|
||||
public void evict(final Project p) {
|
||||
if (p != null) {
|
||||
byName.invalidate(p.getNameKey().get());
|
||||
|
||||
Reference in New Issue
Block a user