Rename FileList cache to DiffSummary
We want to store the number of inserted/deleted lines in this cache in addition to the file list. Change-Id: Iaa6414c5e99d1c5724c99ac677c2fd9522ef6b05
This commit is contained in:
@@ -642,7 +642,7 @@ Default is 1024 for most caches, except:
|
||||
* `"adv_bases"`: default is `4096`
|
||||
* `"diff"`: default is `10m` (10 MiB of memory)
|
||||
* `"diff_intraline"`: default is `10m` (10 MiB of memory)
|
||||
* `"diff_file_list"`: default is `10m` (10 MiB of memory)
|
||||
* `"diff_summary"`: default is `10m` (10 MiB of memory)
|
||||
* `"plugin_resources"`: default is 2m (2 MiB of memory)
|
||||
|
||||
+
|
||||
@@ -660,7 +660,7 @@ performed once every 24 hours.
|
||||
+
|
||||
Default is 128 MiB per cache, except:
|
||||
+
|
||||
* `"diff_file_list"`: default is `1g` (1 GiB of disk space)
|
||||
* `"diff_summary"`: default is `1g` (1 GiB of disk space)
|
||||
|
||||
+
|
||||
If 0, disk storage for the cache is disabled.
|
||||
@@ -733,7 +733,7 @@ estimate in bytes of memory used. Administrators should try to target
|
||||
cache.diff.memoryLimit to fit all files users will view in a 1 or 2
|
||||
day span.
|
||||
|
||||
cache `"diff_file_list"`::
|
||||
cache `"diff_summary"`::
|
||||
+
|
||||
Each item caches list of file paths which are different between two
|
||||
commits. Gerrit uses this cache to accelerate computing of the list
|
||||
|
||||
@@ -34,12 +34,12 @@ import java.util.List;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
public class FileList implements Serializable {
|
||||
public class DiffSummary implements Serializable {
|
||||
private static final long serialVersionUID = PatchListKey.serialVersionUID;
|
||||
|
||||
private transient String[] paths;
|
||||
|
||||
public FileList(String[] paths) {
|
||||
public DiffSummary(String[] paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class FileListLoader implements Callable<FileList> {
|
||||
static final Logger log = LoggerFactory.getLogger(FileListLoader.class);
|
||||
public class DiffSummaryLoader implements Callable<DiffSummary> {
|
||||
static final Logger log = LoggerFactory.getLogger(DiffSummaryLoader.class);
|
||||
|
||||
public interface Factory {
|
||||
FileListLoader create(PatchListKey key, Project.NameKey project);
|
||||
DiffSummaryLoader create(PatchListKey key, Project.NameKey project);
|
||||
}
|
||||
|
||||
private final PatchListCache patchListCache;
|
||||
@@ -39,7 +39,7 @@ public class FileListLoader implements Callable<FileList> {
|
||||
private final Project.NameKey project;
|
||||
|
||||
@AssistedInject
|
||||
FileListLoader(PatchListCache plc,
|
||||
DiffSummaryLoader(PatchListCache plc,
|
||||
@Assisted PatchListKey k,
|
||||
@Assisted Project.NameKey p) {
|
||||
patchListCache = plc;
|
||||
@@ -48,12 +48,12 @@ public class FileListLoader implements Callable<FileList> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileList call() throws Exception {
|
||||
public DiffSummary call() throws Exception {
|
||||
PatchList patchList = patchListCache.get(key, project);
|
||||
return toFileList(patchList);
|
||||
return toDiffSummary(patchList);
|
||||
}
|
||||
|
||||
static FileList toFileList(PatchList patchList) {
|
||||
static DiffSummary toDiffSummary(PatchList patchList) {
|
||||
List<String> r = new ArrayList<>(patchList.getPatches().size());
|
||||
for (PatchListEntry e : patchList.getPatches()) {
|
||||
if (Patch.isMagic(e.getNewName())) {
|
||||
@@ -75,6 +75,6 @@ public class FileListLoader implements Callable<FileList> {
|
||||
}
|
||||
}
|
||||
Collections.sort(r);
|
||||
return new FileList(r.toArray(new String[r.size()]));
|
||||
return new DiffSummary(r.toArray(new String[r.size()]));
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ package com.google.gerrit.server.patch;
|
||||
|
||||
import com.google.common.cache.Weigher;
|
||||
|
||||
/** Computes memory usage for FileList in bytes of memory used */
|
||||
public class FileListWeigher implements Weigher<PatchListKey, FileList> {
|
||||
/** Computes memory usage for {@link DiffSummary} in bytes of memory used. */
|
||||
public class DiffSummaryWeigher implements Weigher<PatchListKey, DiffSummary> {
|
||||
|
||||
@Override
|
||||
public int weigh(PatchListKey key, FileList value) {
|
||||
public int weigh(PatchListKey key, DiffSummary value) {
|
||||
int size = 16 + 4 * 8 + 2 * 36; // Size of PatchListKey, 64 bit JVM
|
||||
|
||||
// Size of the list of paths ...
|
||||
@@ -34,6 +34,6 @@ public interface PatchListCache {
|
||||
IntraLineDiff getIntraLineDiff(IntraLineDiffKey key,
|
||||
IntraLineDiffArgs args);
|
||||
|
||||
FileList getFileList(Change change, PatchSet patchSet)
|
||||
DiffSummary getDiffSummary(Change change, PatchSet patchSet)
|
||||
throws PatchListNotAvailableException;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static com.google.gerrit.server.patch.FileListLoader.toFileList;
|
||||
import static com.google.gerrit.server.patch.DiffSummaryLoader.toDiffSummary;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.ExecutionException;
|
||||
public class PatchListCacheImpl implements PatchListCache {
|
||||
static final String FILE_NAME = "diff";
|
||||
static final String INTRA_NAME = "diff_intraline";
|
||||
static final String FILE_LIST = "diff_file_list";
|
||||
static final String DIFF_SUMMARY = "diff_summary";
|
||||
|
||||
public static Module module() {
|
||||
return new CacheModule() {
|
||||
@@ -57,10 +57,10 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
.maximumWeight(10 << 20)
|
||||
.weigher(IntraLineWeigher.class);
|
||||
|
||||
factory(FileListLoader.Factory.class);
|
||||
persist(FILE_LIST, PatchListKey.class, FileList.class)
|
||||
factory(DiffSummaryLoader.Factory.class);
|
||||
persist(DIFF_SUMMARY, PatchListKey.class, DiffSummary.class)
|
||||
.maximumWeight(10 << 20)
|
||||
.weigher(FileListWeigher.class)
|
||||
.weigher(DiffSummaryWeigher.class)
|
||||
.diskLimit(1 << 30);
|
||||
|
||||
bind(PatchListCacheImpl.class);
|
||||
@@ -71,27 +71,27 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
|
||||
private final Cache<PatchListKey, PatchList> fileCache;
|
||||
private final Cache<IntraLineDiffKey, IntraLineDiff> intraCache;
|
||||
private final Cache<PatchListKey, FileList> fileListCache;
|
||||
private final Cache<PatchListKey, DiffSummary> diffSummaryCache;
|
||||
private final PatchListLoader.Factory fileLoaderFactory;
|
||||
private final IntraLineLoader.Factory intraLoaderFactory;
|
||||
private final FileListLoader.Factory fileListLoaderFactory;
|
||||
private final DiffSummaryLoader.Factory diffSummaryLoaderFactory;
|
||||
private final boolean computeIntraline;
|
||||
|
||||
@Inject
|
||||
PatchListCacheImpl(
|
||||
@Named(FILE_NAME) Cache<PatchListKey, PatchList> fileCache,
|
||||
@Named(INTRA_NAME) Cache<IntraLineDiffKey, IntraLineDiff> intraCache,
|
||||
@Named(FILE_LIST) Cache<PatchListKey, FileList> fileListCache,
|
||||
@Named(DIFF_SUMMARY) Cache<PatchListKey, DiffSummary> diffSummaryCache,
|
||||
PatchListLoader.Factory fileLoaderFactory,
|
||||
IntraLineLoader.Factory intraLoaderFactory,
|
||||
FileListLoader.Factory fileListLoaderFactory,
|
||||
DiffSummaryLoader.Factory diffSummaryLoaderFactory,
|
||||
@GerritServerConfig Config cfg) {
|
||||
this.fileCache = fileCache;
|
||||
this.intraCache = intraCache;
|
||||
this.fileListCache = fileListCache;
|
||||
this.diffSummaryCache = diffSummaryCache;
|
||||
this.fileLoaderFactory = fileLoaderFactory;
|
||||
this.intraLoaderFactory = intraLoaderFactory;
|
||||
this.fileListLoaderFactory = fileListLoaderFactory;
|
||||
this.diffSummaryLoaderFactory = diffSummaryLoaderFactory;
|
||||
|
||||
this.computeIntraline =
|
||||
cfg.getBoolean("cache", INTRA_NAME, "enabled",
|
||||
@@ -103,7 +103,7 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
throws PatchListNotAvailableException {
|
||||
try {
|
||||
PatchList pl = fileCache.get(key, fileLoaderFactory.create(key, project));
|
||||
fileListCache.put(key, toFileList(pl));
|
||||
diffSummaryCache.put(key, toDiffSummary(pl));
|
||||
return pl;
|
||||
} catch (ExecutionException e) {
|
||||
PatchListLoader.log.warn("Error computing " + key, e);
|
||||
@@ -159,19 +159,19 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileList getFileList(Change change, PatchSet patchSet)
|
||||
public DiffSummary getDiffSummary(Change change, PatchSet patchSet)
|
||||
throws PatchListNotAvailableException {
|
||||
Project.NameKey project = change.getProject();
|
||||
ObjectId b = ObjectId.fromString(patchSet.getRevision().get());
|
||||
Whitespace ws = Whitespace.IGNORE_NONE;
|
||||
return getFileList(PatchListKey.againstDefaultBase(b, ws), project);
|
||||
return getDiffSummary(PatchListKey.againstDefaultBase(b, ws), project);
|
||||
}
|
||||
|
||||
private FileList getFileList(PatchListKey key, Project.NameKey project)
|
||||
private DiffSummary getDiffSummary(PatchListKey key, Project.NameKey project)
|
||||
throws PatchListNotAvailableException {
|
||||
try {
|
||||
return fileListCache.get(key,
|
||||
fileListLoaderFactory.create(key, project));
|
||||
return diffSummaryCache.get(key,
|
||||
diffSummaryLoaderFactory.create(key, project));
|
||||
} catch (ExecutionException e) {
|
||||
PatchListLoader.log.warn("Error computing " + key, e);
|
||||
throw new PatchListNotAvailableException(e);
|
||||
|
||||
@@ -58,7 +58,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MergeUtil;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.NotesMigration;
|
||||
import com.google.gerrit.server.patch.FileList;
|
||||
import com.google.gerrit.server.patch.DiffSummary;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
@@ -336,7 +336,7 @@ public class ChangeData {
|
||||
private List<PatchSetApproval> currentApprovals;
|
||||
private Map<Integer, List<String>> files;
|
||||
private Map<Integer, Optional<PatchList>> patchLists;
|
||||
private Map<Integer, Optional<FileList>> fileLists;
|
||||
private Map<Integer, Optional<DiffSummary>> diffSummaries;
|
||||
private Collection<Comment> publishedComments;
|
||||
private CurrentUser visibleTo;
|
||||
private ChangeControl changeControl;
|
||||
@@ -588,7 +588,7 @@ public class ChangeData {
|
||||
return null;
|
||||
}
|
||||
|
||||
Optional<FileList> p = getFileList(c, ps);
|
||||
Optional<DiffSummary> p = getDiffSummary(c, ps);
|
||||
if (!p.isPresent()) {
|
||||
List<String> emptyFileList = Collections.emptyList();
|
||||
if (lazyLoad) {
|
||||
@@ -623,22 +623,22 @@ public class ChangeData {
|
||||
return r;
|
||||
}
|
||||
|
||||
private Optional<FileList> getFileList(Change c, PatchSet ps) {
|
||||
private Optional<DiffSummary> getDiffSummary(Change c, PatchSet ps) {
|
||||
Integer psId = ps.getId().get();
|
||||
if (fileLists == null) {
|
||||
fileLists = new HashMap<>();
|
||||
if (diffSummaries == null) {
|
||||
diffSummaries = new HashMap<>();
|
||||
}
|
||||
Optional<FileList> r = fileLists.get(psId);
|
||||
Optional<DiffSummary> r = diffSummaries.get(psId);
|
||||
if (r == null) {
|
||||
if (!lazyLoad) {
|
||||
return Optional.absent();
|
||||
}
|
||||
try {
|
||||
r = Optional.of(patchListCache.getFileList(c, ps));
|
||||
r = Optional.of(patchListCache.getDiffSummary(c, ps));
|
||||
} catch (PatchListNotAvailableException e) {
|
||||
r = Optional.absent();
|
||||
}
|
||||
fileLists.put(psId, r);
|
||||
diffSummaries.put(psId, r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user