aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java
blob: c3fd07b7bbe69fe3b27edc38ad30988e599190b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright (c) 2024, Google LLC and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.internal.storage.dfs;

import java.io.IOException;
import java.util.List;

/**
 * Block cache table.
 */
public interface DfsBlockCacheTable {
	/**
	 * Quickly check if the cache contains block 0 of the given stream.
	 * <p>
	 * This can be useful for sophisticated pre-read algorithms to quickly
	 * determine if a file is likely already in cache, especially small
	 * reftables which may be smaller than a typical DFS block size.
	 *
	 * @param key
	 *            the file to check.
	 * @return true if block 0 (the first block) is in the cache.
	 */
	boolean hasBlock0(DfsStreamKey key);

	/**
	 * Look up a cached object, creating and loading it if it doesn't exist.
	 *
	 * @param file
	 *            the pack that "contains" the cached object.
	 * @param position
	 *            offset within <code>pack</code> of the object.
	 * @param dfsReader
	 *            current thread's reader.
	 * @param fileChannel
	 *            supplier for channel to read {@code pack}.
	 * @return the object reference.
	 * @throws IOException
	 *             the reference was not in the cache and could not be loaded.
	 */
	DfsBlock getOrLoad(BlockBasedFile file, long position, DfsReader dfsReader,
			DfsBlockCache.ReadableChannelSupplier fileChannel)
			throws IOException;

	/**
	 * Look up a cached object, creating and loading it if it doesn't exist.
	 *
	 * @param key
	 *            the stream key of the pack.
	 * @param position
	 *            the position in the key. The default should be 0.
	 * @param loader
	 *            the function to load the reference.
	 * @return the object reference.
	 * @throws IOException
	 *             the reference was not in the cache and could not be loaded.
	 */
	<T> DfsBlockCache.Ref<T> getOrLoadRef(DfsStreamKey key, long position,
			DfsBlockCache.RefLoader<T> loader) throws IOException;

	/**
	 * Put a block in the block cache.
	 *
	 * @param v
	 *            the block to put in the cache.
	 */
	void put(DfsBlock v);

	/**
	 * Put a block in the block cache.
	 *
	 * @param key
	 *            the stream key of the pack.
	 * @param pos
	 *            the position in the key.
	 * @param size
	 *            the size of the object.
	 * @param v
	 *            the object to put in the block cache.
	 * @return the object reference.
	 */
	<T> DfsBlockCache.Ref<T> put(DfsStreamKey key, long pos, long size, T v);

	/**
	 * Put an object in the block cache.
	 *
	 * @param key
	 *            the stream key of the pack.
	 * @param size
	 *            the size of the object.
	 * @param v
	 *            the object to put in the block cache.
	 * @return the object reference.
	 */
	<T> DfsBlockCache.Ref<T> putRef(DfsStreamKey key, long size, T v);

	/**
	 * Check if the block cache contains an object identified by (key,
	 * position).
	 *
	 * @param key
	 *            the stream key of the pack.
	 * @param position
	 *            the position in the key.
	 * @return if the block cache contains the object identified by (key,
	 *         position).
	 */
	boolean contains(DfsStreamKey key, long position);

	/**
	 * Get the object identified by (key, position) from the block cache.
	 *
	 * @param key
	 *            the stream key of the pack.
	 * @param position
	 *            the position in the key.
	 * @return the object identified by (key, position).
	 */
	<T> T get(DfsStreamKey key, long position);

	/**
	 * Get the list of {@link BlockCacheStats} held by this cache.
	 * <p>
	 * The returned list has a {@link BlockCacheStats} per configured cache
	 * table, with a minimum of 1 {@link BlockCacheStats} object returned.
	 *
	 * Use {@link AggregatedBlockCacheStats} to combine the results of the stats
	 * in the list for an aggregated view of the cache's stats.
	 *
	 * @return the list of {@link BlockCacheStats} held by this cache.
	 */
	List<BlockCacheStats> getBlockCacheStats();

	/**
	 * Get the name of the table.
	 *
	 * @return this table's name.
	 */
	String getName();

	/**
	 * Provides methods used with Block Cache statistics.
	 */
	interface BlockCacheStats {

		/**
		 * Get the name of the block cache generating this instance.
		 *
		 * @return this cache's name.
		 */
		String getName();

		/**
		 * Get total number of bytes in the cache, per pack file extension.
		 *
		 * @return total number of bytes in the cache, per pack file extension.
		 */
		long[] getCurrentSize();

		/**
		 * Get number of requests for items in the cache, per pack file
		 * extension.
		 *
		 * @return the number of requests for items in the cache, per pack file
		 *         extension.
		 */
		long[] getHitCount();

		/**
		 * Get number of requests for items not in the cache, per pack file
		 * extension.
		 *
		 * @return the number of requests for items not in the cache, per pack
		 *         file extension.
		 */
		long[] getMissCount();

		/**
		 * Get total number of requests (hit + miss), per pack file extension.
		 *
		 * @return total number of requests (hit + miss), per pack file
		 *         extension.
		 */
		long[] getTotalRequestCount();

		/**
		 * Get hit ratios.
		 *
		 * @return hit ratios.
		 */
		long[] getHitRatio();

		/**
		 * Get number of evictions performed due to cache being full, per pack
		 * file extension.
		 *
		 * @return the number of evictions performed due to cache being full,
		 *         per pack file extension.
		 */
		long[] getEvictions();
	}
}