Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add support for `matched_fields` with the unified highlighter ([#18164](https://github.com/opensearch-project/OpenSearch/issues/18164))
- [repository-s3] Add support for SSE-KMS and S3 bucket owner verification ([#18312](https://github.com/opensearch-project/OpenSearch/pull/18312))
- Added File Cache Stats - Involves Block level as well as full file level stats ([#17538](https://github.com/opensearch-project/OpenSearch/issues/17479))
- Added File Cache Pinning ([#17617](https://github.com/opensearch-project/OpenSearch/issues/13648))

### Changed
- Create generic DocRequest to better categorize ActionRequests ([#18269](https://github.com/opensearch-project/OpenSearch/pull/18269)))

### Dependencies
- Update Apache Lucene from 10.1.0 to 10.2.1 ([#17961](https://github.com/opensearch-project/OpenSearch/pull/17961))
- Bump `com.google.code.gson:gson` from 2.12.1 to 2.13.1 ([#17923](https://github.com/opensearch-project/OpenSearch/pull/17923), [#18266](https://github.com/opensearch-project/OpenSearch/pull/18266))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,15 @@ public String toString() {
*/
public void afterSyncToRemote(String file) {
ensureOpen();
/*
Decrementing the refCount here for the path so that it becomes eligible for eviction
This is a temporary solution until pinning support is added
TODO - Unpin the files here from FileCache so that they become eligible for eviction, once pinning/unpinning support is added in FileCache
Uncomment the below commented line(to remove the file from cache once uploaded) to test block based functionality
*/

logger.trace(
"Composite Directory[{}]: File {} uploaded to Remote Store and now can be eligible for eviction in FileCache",
this::toString,
() -> file
);
fileCache.decRef(getFilePath(file));
// fileCache.remove(getFilePath(fileName));
final Path filePath = getFilePath(file);
fileCache.unpin(filePath);
// fileCache.remove(filePath);
}

// Visibility public since we need it in IT tests
Expand Down Expand Up @@ -390,12 +386,10 @@ private String[] getRemoteFiles() throws IOException {

protected void cacheFile(String name) throws IOException {
Path filePath = getFilePath(name);
// put will increase the refCount for the path, making sure it is not evicted, will decrease the ref after it is uploaded to Remote
// so that it can be evicted after that
// this is just a temporary solution, will pin the file once support for that is added in FileCache
// TODO : Pin the above filePath in the file cache once pinning support is added so that it cannot be evicted unless it has been
// successfully uploaded to Remote

fileCache.put(filePath, new CachedFullFileIndexInput(fileCache, filePath, localDirectory.openInput(name, IOContext.DEFAULT)));
fileCache.pin(filePath);
fileCache.decRef(filePath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,28 @@ public class AggregateFileCacheStats implements Writeable, ToXContentFragment {
private final FileCacheStats overallFileCacheStats;
private final FileCacheStats fullFileCacheStats;
private final FileCacheStats blockFileCacheStats;
private final FileCacheStats pinnedFileCacheStats;

public AggregateFileCacheStats(
final long timestamp,
final FileCacheStats overallFileCacheStats,
final FileCacheStats fullFileCacheStats,
final FileCacheStats blockFileCacheStats
final FileCacheStats blockFileCacheStats,
FileCacheStats pinnedFileCacheStats
) {
this.timestamp = timestamp;
this.overallFileCacheStats = overallFileCacheStats;
this.fullFileCacheStats = fullFileCacheStats;
this.blockFileCacheStats = blockFileCacheStats;
this.pinnedFileCacheStats = pinnedFileCacheStats;
}

public AggregateFileCacheStats(final StreamInput in) throws IOException {
this.timestamp = in.readLong();
this.overallFileCacheStats = new FileCacheStats(in);
this.fullFileCacheStats = new FileCacheStats(in);
this.blockFileCacheStats = new FileCacheStats(in);
this.pinnedFileCacheStats = new FileCacheStats(in);
}

public static short calculatePercentage(long used, long max) {
Expand All @@ -69,6 +73,7 @@ public void writeTo(final StreamOutput out) throws IOException {
overallFileCacheStats.writeTo(out);
fullFileCacheStats.writeTo(out);
blockFileCacheStats.writeTo(out);
pinnedFileCacheStats.writeTo(out);
}

public long getTimestamp() {
Expand All @@ -91,6 +96,10 @@ public ByteSizeValue getUsed() {
return new ByteSizeValue(overallFileCacheStats.getUsed());
}

public ByteSizeValue getPinnedUsage() {
return new ByteSizeValue(overallFileCacheStats.getPinnedUsage());
}

public short getUsedPercent() {
return calculatePercentage(getUsed().getBytes(), getTotal().getBytes());
}
Expand All @@ -114,6 +123,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.humanReadableField(Fields.ACTIVE_IN_BYTES, Fields.ACTIVE, getActive());
builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, getTotal());
builder.humanReadableField(Fields.USED_IN_BYTES, Fields.USED, getUsed());
builder.humanReadableField(Fields.PINNED_IN_BYTES, Fields.PINNED, getPinnedUsage());
builder.humanReadableField(Fields.EVICTIONS_IN_BYTES, Fields.EVICTIONS, getEvicted());
builder.field(Fields.ACTIVE_PERCENT, getActivePercent());
builder.field(Fields.USED_PERCENT, getUsedPercent());
Expand All @@ -122,7 +132,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
overallFileCacheStats.toXContent(builder, params);
fullFileCacheStats.toXContent(builder, params);
blockFileCacheStats.toXContent(builder, params);

pinnedFileCacheStats.toXContent(builder, params);
builder.endObject();
return builder;
}
Expand All @@ -134,6 +144,8 @@ static final class Fields {
static final String ACTIVE_IN_BYTES = "active_in_bytes";
static final String USED = "used";
static final String USED_IN_BYTES = "used_in_bytes";
static final String PINNED = "pinned";
static final String PINNED_IN_BYTES = "pinned_in_bytes";
static final String EVICTIONS = "evictions";
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
static final String TOTAL = "total";
Expand All @@ -153,7 +165,8 @@ static final class Fields {
public enum FileCacheStatsType {
FULL_FILE_STATS("full_file_stats"),
BLOCK_FILE_STATS("block_file_stats"),
OVER_ALL_STATS("over_all_stats");
OVER_ALL_STATS("over_all_stats"),
PINNED_FILE_STATS("pinned_file_stats");

private final String fileCacheStatsType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@
theCache.decRef(key);
}

/**
* Pins the key in the cache, preventing it from being evicted.
*
* @param key
*/
@Override
public void pin(Path key) {
theCache.pin(key);
}

/**
* Unpins the key in the cache, allowing it to be evicted.
*
* @param key
*/
@Override
public void unpin(Path key) {
theCache.unpin(key);
}

@Override
public Integer getRef(Path key) {
return theCache.getRef(key);
Expand All @@ -141,14 +161,22 @@

@Override
public long usage() {
long l = theCache.usage();
return l;
return theCache.usage();
}

@Override
public long activeUsage() {
long l = theCache.activeUsage();
return l;
return theCache.activeUsage();
}

/**
* Returns the pinned usage of this cache.
*
* @return the combined pinned weight of the values in this cache.
*/
@Override
public long pinnedUsage() {
return theCache.pinnedUsage();

Check warning on line 179 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L179

Added line #L179 was not covered by tests
}

@Override
Expand Down Expand Up @@ -225,12 +253,14 @@
final RefCountedCacheStats overallCacheStats = stats.getOverallCacheStats();
final RefCountedCacheStats fullFileCacheStats = stats.getFullFileCacheStats();
final RefCountedCacheStats blockFileCacheStats = stats.getBlockFileCacheStats();
final RefCountedCacheStats pinnedFileCacheStats = stats.getPinnedFileCacheStats();

Check warning on line 256 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L256

Added line #L256 was not covered by tests
return new AggregateFileCacheStats(
System.currentTimeMillis(),
new FileCacheStats(
overallCacheStats.activeUsage(),
capacity(),
overallCacheStats.usage(),
overallCacheStats.pinnedUsage(),

Check warning on line 263 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L263

Added line #L263 was not covered by tests
overallCacheStats.evictionWeight(),
overallCacheStats.hitCount(),
overallCacheStats.missCount(),
Expand All @@ -240,6 +270,7 @@
fullFileCacheStats.activeUsage(),
capacity(),
fullFileCacheStats.usage(),
fullFileCacheStats.pinnedUsage(),

Check warning on line 273 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L273

Added line #L273 was not covered by tests
fullFileCacheStats.evictionWeight(),
fullFileCacheStats.hitCount(),
fullFileCacheStats.missCount(),
Expand All @@ -249,10 +280,21 @@
blockFileCacheStats.activeUsage(),
capacity(),
blockFileCacheStats.usage(),
blockFileCacheStats.pinnedUsage(),

Check warning on line 283 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L283

Added line #L283 was not covered by tests
blockFileCacheStats.evictionWeight(),
blockFileCacheStats.hitCount(),
blockFileCacheStats.missCount(),
FileCacheStatsType.BLOCK_FILE_STATS
),
new FileCacheStats(
pinnedFileCacheStats.activeUsage(),
capacity(),
pinnedFileCacheStats.usage(),
pinnedFileCacheStats.pinnedUsage(),
pinnedFileCacheStats.evictionWeight(),
pinnedFileCacheStats.hitCount(),
pinnedFileCacheStats.missCount(),

Check warning on line 296 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java#L290-L296

Added lines #L290 - L296 were not covered by tests
FileCacheStatsType.PINNED_FILE_STATS
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class FileCacheStats implements Writeable, ToXContentFragment {
private final long active;
private final long total;
private final long used;
private final long pinned;
private final long evicted;
private final long hits;
private final long misses;
Expand All @@ -47,6 +48,7 @@ public FileCacheStats(
final long active,
long total,
final long used,
final long pinned,
final long evicted,
final long hits,
long misses,
Expand All @@ -55,6 +57,7 @@ public FileCacheStats(
this.active = active;
this.total = total;
this.used = used;
this.pinned = pinned;
this.evicted = evicted;
this.hits = hits;
this.misses = misses;
Expand All @@ -66,6 +69,7 @@ public FileCacheStats(final StreamInput in) throws IOException {
this.active = in.readLong();
this.total = in.readLong();
this.used = in.readLong();
this.pinned = in.readLong();
this.evicted = in.readLong();
this.hits = in.readLong();
this.misses = in.readLong();
Expand All @@ -77,6 +81,7 @@ public void writeTo(final StreamOutput out) throws IOException {
out.writeLong(active);
out.writeLong(total);
out.writeLong(used);
out.writeLong(pinned);
out.writeLong(evicted);
out.writeLong(hits);
out.writeLong(misses);
Expand Down Expand Up @@ -106,6 +111,10 @@ public long getTotal() {
return total;
}

public long getPinnedUsage() {
return pinned;
}

public short getUsedPercent() {
return calculatePercentage(getUsed(), total);
}
Expand All @@ -122,6 +131,7 @@ static final class Fields {
static final String ACTIVE = "active";
static final String ACTIVE_IN_BYTES = "active_in_bytes";
static final String USED = "used";
static final String PINNED = "pinned";
static final String USED_IN_BYTES = "used_in_bytes";
static final String EVICTIONS = "evictions";
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
Expand All @@ -134,6 +144,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject(statsType.toString());
builder.humanReadableField(FileCacheStats.Fields.ACTIVE_IN_BYTES, FileCacheStats.Fields.ACTIVE, new ByteSizeValue(getActive()));
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, FileCacheStats.Fields.USED, new ByteSizeValue(getUsed()));
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, Fields.PINNED, new ByteSizeValue(getPinnedUsage()));
builder.humanReadableField(
FileCacheStats.Fields.EVICTIONS_IN_BYTES,
FileCacheStats.Fields.EVICTIONS,
Expand Down
Loading
Loading