-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose translog stats in ReadOnlyEngine #43752
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,51 @@ setup: | |
indices.stats: | ||
metric: [ translog ] | ||
- gte: { indices.test.primaries.translog.earliest_last_modified_age: 0 } | ||
|
||
--- | ||
"Translog stats on closed indices": | ||
- skip: | ||
version: " - 7.2.99" | ||
reason: "closed indices have translog stats starting version 7.3.0" | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 2 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 3 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ translog ] | ||
- match: { indices.test.primaries.translog.operations: 3 } | ||
- match: { indices.test.primaries.translog.uncommitted_operations: 3 } | ||
|
||
- do: | ||
indices.close: | ||
index: test | ||
- is_true: acknowledged | ||
|
||
- do: | ||
cluster.health: | ||
expand_wildcards: all | ||
wait_for_no_initializing_shards: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only needed for the backport. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right |
||
|
||
- do: | ||
indices.stats: | ||
metric: [ translog ] | ||
expand_wildcards: all | ||
forbid_closed_indices: false | ||
- match: { indices.test.primaries.translog.operations: 3 } | ||
- match: { indices.test.primaries.translog.uncommitted_operations: 0 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ | |
import org.elasticsearch.index.shard.DocsStats; | ||
import org.elasticsearch.index.store.Store; | ||
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.index.translog.TranslogConfig; | ||
import org.elasticsearch.index.translog.TranslogDeletionPolicy; | ||
import org.elasticsearch.index.translog.TranslogStats; | ||
|
||
import java.io.Closeable; | ||
|
@@ -80,6 +82,7 @@ public class ReadOnlyEngine extends Engine { | |
private final DocsStats docsStats; | ||
private final RamAccountingSearcherFactory searcherFactory; | ||
|
||
|
||
tlrx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened | ||
* read-write engine. It allows to optionally obtain the writer locks for the shard which would time-out if another | ||
|
@@ -108,7 +111,6 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats | |
// yet this makes sure nobody else does. including some testing tools that try to be messy | ||
indexWriterLock = obtainLock ? directory.obtainLock(IndexWriter.WRITE_LOCK_NAME) : null; | ||
this.lastCommittedSegmentInfos = Lucene.readSegmentInfos(directory); | ||
this.translogStats = translogStats == null ? new TranslogStats(0, 0, 0, 0, 0) : translogStats; | ||
if (seqNoStats == null) { | ||
seqNoStats = buildSeqNoStats(config, lastCommittedSegmentInfos); | ||
ensureMaxSeqNoEqualsToGlobalCheckpoint(seqNoStats); | ||
|
@@ -119,6 +121,7 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats | |
reader = wrapReader(reader, readerWrapperFunction); | ||
searcherManager = new SearcherManager(reader, searcherFactory); | ||
this.docsStats = docsStats(lastCommittedSegmentInfos); | ||
this.translogStats = translogStats != null ? translogStats : translogStats(config, lastCommittedSegmentInfos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ especially as opening the translog here writes a new checkpoint file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very good suggestion, thanks |
||
this.indexWriterLock = indexWriterLock; | ||
success = true; | ||
} finally { | ||
|
@@ -216,6 +219,26 @@ private static SeqNoStats buildSeqNoStats(EngineConfig config, SegmentInfos info | |
return new SeqNoStats(maxSeqNo, localCheckpoint, config.getGlobalCheckpointSupplier().getAsLong()); | ||
} | ||
|
||
private static TranslogStats translogStats(final EngineConfig config, final SegmentInfos infos) throws IOException { | ||
final String translogUuid = infos.getUserData().get(Translog.TRANSLOG_UUID_KEY); | ||
if (translogUuid == null) { | ||
throw new IllegalStateException("commit doesn't contain translog unique id"); | ||
} | ||
final long translogGenOfLastCommit = Long.parseLong(infos.getUserData().get(Translog.TRANSLOG_GENERATION_KEY)); | ||
final TranslogConfig translogConfig = config.getTranslogConfig(); | ||
final TranslogDeletionPolicy translogDeletionPolicy = new TranslogDeletionPolicy( | ||
config.getIndexSettings().getTranslogRetentionSize().getBytes(), | ||
config.getIndexSettings().getTranslogRetentionAge().getMillis() | ||
); | ||
translogDeletionPolicy.setTranslogGenerationOfLastCommit(translogGenOfLastCommit); | ||
|
||
try (Translog translog = new Translog(translogConfig, translogUuid, translogDeletionPolicy, config.getGlobalCheckpointSupplier(), | ||
config.getPrimaryTermSupplier(), seqNo -> {}) | ||
) { | ||
return translog.stats(); | ||
} | ||
} | ||
|
||
@Override | ||
public GetResult get(Get get, BiFunction<String, SearcherScope, Searcher> searcherFactory) throws EngineException { | ||
return getFromSearcher(get, searcherFactory, SearcherScope.EXTERNAL); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test | ||
- do: | ||
cluster.health: | ||
wait_for_no_initializing_shards: true | ||
|
||
--- | ||
"Translog stats on frozen indices": | ||
- skip: | ||
version: " - 7.2.99" | ||
reason: "frozen indices have translog stats starting version 7.3.0" | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 2 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 3 | ||
body: { "foo": "bar" } | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ translog ] | ||
- match: { indices.test.primaries.translog.operations: 3 } | ||
- match: { indices.test.primaries.translog.uncommitted_operations: 3 } | ||
|
||
# freeze index | ||
- do: | ||
indices.freeze: | ||
index: test | ||
- is_true: acknowledged | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_no_initializing_shards: true | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ translog ] | ||
- match: { indices.test.primaries.translog.operations: 3 } | ||
- match: { indices.test.primaries.translog.uncommitted_operations: 0 } | ||
|
||
# unfreeze index | ||
- do: | ||
indices.freeze: | ||
index: test | ||
- is_true: acknowledged | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_no_initializing_shards: true | ||
|
||
- do: | ||
indices.stats: | ||
metric: [ translog ] | ||
- match: { indices.test.primaries.translog.operations: 3 } | ||
- match: { indices.test.primaries.translog.uncommitted_operations: 0 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should skip this test until 7.9.99 then adjust to this value after backporting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird that this did not fail the tests? Perhaps BWC is disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pfff... I should have seen this. And yes, bwc tests were disabled at that time. I merged master and bwc are enabled again.