Skip to content

Commit

Permalink
Dirty hack to dynamically enable mget sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Jan 16, 2024
1 parent 74131f6 commit 14418fd
Showing 1 changed file with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package org.elasticsearch.index.shard;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.document.DocumentField;
Expand Down Expand Up @@ -359,17 +361,24 @@ private static StoredFieldLoader buildStoredFieldLoader(String[] fields, FetchSo
* This session must be created and used by a single thread.
*/
public static final class MGetSession implements Releasable {
private static final Logger logger = LogManager.getLogger(MGetSession.class);
private final ShardGetService shardGetService;
private final MultiEngineGet multiEngineGet;

private final boolean enabled;

public MGetSession(ShardGetService shardGetService) {
this.shardGetService = shardGetService;
this.multiEngineGet = shardGetService.indexShard.newMultiEngineGet();
this.enabled = shardGetService.indexSettings().getSettings().getAsInt("index.max_script_fields", 32) == 32;
logger.trace("MGetSession enabled=[{}].", enabled);
}

@Override
public void close() {
multiEngineGet.close();
if (enabled) {
multiEngineGet.close();
}
}

public ShardId shardId() {
Expand All @@ -385,19 +394,25 @@ public GetResult get(
FetchSourceContext fetchSourceContext,
boolean forceSyntheticSource
) throws IOException {
return shardGetService.get(
id,
multiEngineGet::engineGet,
gFields,
realtime,
version,
versionType,
UNASSIGNED_SEQ_NO,
UNASSIGNED_PRIMARY_TERM,
fetchSourceContext,
forceSyntheticSource,
false
);
try {
return shardGetService.get(
id,
multiEngineGet::engineGet,
gFields,
realtime,
version,
versionType,
UNASSIGNED_SEQ_NO,
UNASSIGNED_PRIMARY_TERM,
fetchSourceContext,
forceSyntheticSource,
false
);
} finally {
if (enabled == false) {
close();
}
}
}
}
}

0 comments on commit 14418fd

Please sign in to comment.