Skip to content

Commit 1da19d3

Browse files
Fix fs info reporting negative available size (#11573)
* fix fs info reporting negative available size Signed-off-by: panguixin <panguixin@bytedance.com> * change log Signed-off-by: panguixin <panguixin@bytedance.com> * fix test Signed-off-by: panguixin <panguixin@bytedance.com> * fix test Signed-off-by: panguixin <panguixin@bytedance.com> * spotless Signed-off-by: panguixin <panguixin@bytedance.com> --------- Signed-off-by: panguixin <panguixin@bytedance.com> Signed-off-by: Andrew Ross <andrross@amazon.com> Co-authored-by: Andrew Ross <andrross@amazon.com>
1 parent 2a6855c commit 1da19d3

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4141
- Fixed rest-high-level client searchTemplate & mtermVectors endpoints to have a leading slash ([#14465](https://github.com/opensearch-project/OpenSearch/pull/14465))
4242
- Write shard level metadata blob when snapshotting searchable snapshot indexes ([#13190](https://github.com/opensearch-project/OpenSearch/pull/13190))
4343
- Fix aggs result of NestedAggregator with sub NestedAggregator ([#13324](https://github.com/opensearch-project/OpenSearch/pull/13324))
44+
- Fix fs info reporting negative available size ([#11573](https://github.com/opensearch-project/OpenSearch/pull/11573))
4445
- Add ListPitInfo::getKeepAlive() getter ([#14495](https://github.com/opensearch-project/OpenSearch/pull/14495))
4546

4647
### Security

server/src/main/java/org/opensearch/monitor/fs/FsProbe.java

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public FsInfo stats(FsInfo previous) throws IOException {
8282
paths[i].fileCacheReserved = adjustForHugeFilesystems(dataLocations[i].fileCacheReservedSize.getBytes());
8383
paths[i].fileCacheUtilized = adjustForHugeFilesystems(fileCache.usage().usage());
8484
paths[i].available -= (paths[i].fileCacheReserved - paths[i].fileCacheUtilized);
85+
// occurs if reserved file cache space is occupied by other files, like local indices
86+
if (paths[i].available < 0) {
87+
paths[i].available = 0;
88+
}
8589
}
8690
}
8791
FsInfo.IoStats ioStats = null;

server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java

+41
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.function.Function;
5959
import java.util.function.Supplier;
6060

61+
import static org.opensearch.monitor.fs.FsProbe.adjustForHugeFilesystems;
6162
import static org.hamcrest.CoreMatchers.equalTo;
6263
import static org.hamcrest.Matchers.emptyOrNullString;
6364
import static org.hamcrest.Matchers.greaterThan;
@@ -162,6 +163,46 @@ public void testFsCacheInfo() throws IOException {
162163
}
163164
}
164165

166+
public void testFsInfoWhenFileCacheOccupied() throws IOException {
167+
Settings settings = Settings.builder().putList("node.roles", "search", "data").build();
168+
try (NodeEnvironment env = newNodeEnvironment(settings)) {
169+
// Use the total space as reserved space to simulate the situation where the cache space is occupied
170+
final long totalSpace = adjustForHugeFilesystems(env.fileCacheNodePath().fileStore.getTotalSpace());
171+
ByteSizeValue gbByteSizeValue = new ByteSizeValue(totalSpace, ByteSizeUnit.BYTES);
172+
env.fileCacheNodePath().fileCacheReservedSize = gbByteSizeValue;
173+
FileCache fileCache = FileCacheFactory.createConcurrentLRUFileCache(
174+
gbByteSizeValue.getBytes(),
175+
16,
176+
new NoopCircuitBreaker(CircuitBreaker.REQUEST)
177+
);
178+
179+
FsProbe probe = new FsProbe(env, fileCache);
180+
FsInfo stats = probe.stats(null);
181+
assertNotNull(stats);
182+
assertTrue(stats.getTimestamp() > 0L);
183+
FsInfo.Path total = stats.getTotal();
184+
assertNotNull(total);
185+
assertTrue(total.total > 0L);
186+
assertTrue(total.free > 0L);
187+
assertTrue(total.fileCacheReserved > 0L);
188+
189+
for (FsInfo.Path path : stats) {
190+
assertNotNull(path);
191+
assertFalse(path.getPath().isEmpty());
192+
assertFalse(path.getMount().isEmpty());
193+
assertFalse(path.getType().isEmpty());
194+
assertTrue(path.total > 0L);
195+
assertTrue(path.free > 0L);
196+
197+
if (path.fileCacheReserved > 0L) {
198+
assertEquals(0L, path.available);
199+
} else {
200+
assertTrue(path.available > 0L);
201+
}
202+
}
203+
}
204+
}
205+
165206
public void testFsInfoOverflow() throws Exception {
166207
final FsInfo.Path pathStats = new FsInfo.Path(
167208
"/foo/bar",

0 commit comments

Comments
 (0)