Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
b8d424c
TSDB: Support GET and DELETE and doc versioning
nik9000 Dec 17, 2021
0158d17
Update delete and update by query tests
nik9000 Jan 14, 2022
ceee396
Merge branch 'master' into tsdb_id
nik9000 Jan 18, 2022
d1e0166
Merge branch 'master' into tsdb_id
nik9000 Jan 20, 2022
fba41e7
Checkstyle
nik9000 Jan 20, 2022
61949d1
Rename
nik9000 Jan 20, 2022
c6f7fc0
Checkstyle
nik9000 Jan 20, 2022
30020e8
64 bit hash
nik9000 Jan 20, 2022
de74543
No hash if not used
nik9000 Jan 20, 2022
4bbbb68
Javadoc
nik9000 Jan 20, 2022
8495be2
WIP
nik9000 Jan 20, 2022
2194ccb
OOOOOF
nik9000 Jan 24, 2022
b5a0e98
Merge branch 'master' into tsdb_id
nik9000 Jan 24, 2022
181db11
OK
nik9000 Jan 24, 2022
53ebad2
Merge branch 'master' into tsdb_id
nik9000 Jan 26, 2022
ecb3410
It's ok
nik9000 Jan 26, 2022
1dce50c
Update docs/changelog/82633.yaml
nik9000 Jan 26, 2022
f9085d9
Add changelog area
nik9000 Jan 26, 2022
5f1b3ab
Merge branch 'master' into tsdb_id
nik9000 Jan 26, 2022
20371c3
Spotless
nik9000 Jan 26, 2022
429b34d
Merge branch 'master' into tsdb_id
nik9000 Jan 26, 2022
5a89bb5
Merge branch 'master' into tsdb_id
nik9000 Jan 26, 2022
edcf8ab
Update
nik9000 Jan 26, 2022
7329d35
Merge branch 'master' into tsdb_id
nik9000 Jan 27, 2022
fe21154
Zap
nik9000 Jan 27, 2022
6578b4b
GET
nik9000 Jan 27, 2022
83bf7ed
Nope
nik9000 Jan 27, 2022
0e5996b
Don't need id
nik9000 Jan 27, 2022
b50a8b9
Moar
nik9000 Jan 27, 2022
5e703ca
Disabled source
nik9000 Jan 27, 2022
aa9b850
Matching routing is ok
nik9000 Jan 28, 2022
ddeef8c
You can specify the routing now
nik9000 Jan 28, 2022
c6cd5f9
spotless
nik9000 Jan 28, 2022
b691265
Tricky tricky!
nik9000 Jan 28, 2022
abfe686
Ewwww
nik9000 Jan 28, 2022
0d013d9
Merge branch 'master' into tsdb_id
nik9000 Jan 28, 2022
bf5fee1
Remove interface for transport client
nik9000 Jan 31, 2022
f24f1b3
Merge branch 'master' into tsdb_id
nik9000 Jan 31, 2022
eedb357
Merge branch 'master' into tsdb_id
nik9000 Feb 3, 2022
8e95ae8
Compile plz
nik9000 Feb 3, 2022
808212c
Merge branch 'master' into tsdb_id
nik9000 Feb 7, 2022
ed71783
Back to the old way
nik9000 Feb 8, 2022
f78727d
Merge branch 'master' into tsdb_id
nik9000 Feb 8, 2022
83acf4b
Cleanup
nik9000 Feb 8, 2022
897f1a0
update another skip
nik9000 Feb 8, 2022
f0e9b75
Merge branch 'master' into tsdb_id
nik9000 Feb 9, 2022
f826185
Merge branch 'master' into tsdb_id
nik9000 Feb 14, 2022
1f4fa00
Merge branch 'master' into tsdb_id
nik9000 Feb 15, 2022
3580bf9
Tests
nik9000 Feb 15, 2022
8191f5c
Assert
nik9000 Feb 15, 2022
86f7bbe
Moar tests
nik9000 Feb 16, 2022
3658674
Merge branch 'master' into tsdb_id
nik9000 Feb 17, 2022
61ab876
Update error message on fielddata _id in tsdb
nik9000 Feb 22, 2022
f6be24e
Comment
nik9000 Feb 22, 2022
d63d1b1
Remove thingy
nik9000 Feb 22, 2022
2e68bde
Merge branch 'master' into tsdb_id
nik9000 Feb 22, 2022
a71c63f
Revert "Remove thingy"
nik9000 Feb 22, 2022
5361137
More
nik9000 Feb 22, 2022
351c1af
More
nik9000 Feb 22, 2022
b75de4e
Allow _id to be set if it matches
nik9000 Feb 23, 2022
e82e88c
More reindex tests
nik9000 Feb 23, 2022
e1cdbc5
Versions
nik9000 Feb 23, 2022
68807cd
Merge branch 'master' into tsdb_id
nik9000 Feb 23, 2022
602c57d
Merge branch 'master' into tsdb_id
nik9000 Feb 23, 2022
5bea91f
spotless
nik9000 Feb 23, 2022
9c717a2
Sneaky
nik9000 Feb 23, 2022
4ae6687
Merge branch 'master' into tsdb_id
nik9000 Feb 24, 2022
813bda1
Assert
nik9000 Feb 24, 2022
7e3c979
Allow _id in all the places
nik9000 Feb 24, 2022
c5f2200
Spotless
nik9000 Feb 24, 2022
0f4d601
Merge branch 'master' into tsdb_id
nik9000 Feb 24, 2022
46fe6c1
Stop being silly
nik9000 Feb 24, 2022
b8c0e19
Merge branch 'master' into tsdb_id
nik9000 Feb 28, 2022
14645e2
Fix cluster test
nik9000 Feb 28, 2022
6cf7c30
Merge branch 'master' into tsdb_id
nik9000 Mar 1, 2022
1ff6f4f
Explain
nik9000 Mar 1, 2022
a0a5359
Merge branch 'master' into tsdb_id
nik9000 Mar 3, 2022
4fda972
Fix ccr
nik9000 Mar 3, 2022
260acdd
Mostly skip
nik9000 Mar 3, 2022
f2b5c5d
Merge branch 'master' into tsdb_id
nik9000 Mar 4, 2022
1f146c5
Mostly skip
nik9000 Mar 3, 2022
ffa2ec8
Not this either
nik9000 Mar 4, 2022
f708ec2
Merge branch 'master' into tsdb_id
nik9000 Mar 4, 2022
122df24
Or this one
nik9000 Mar 4, 2022
064cbc5
Merge branch 'master' into tsdb_id
elasticmachine Mar 7, 2022
3037fad
Merge branch 'master' into tsdb_id
nik9000 Mar 9, 2022
15455a2
Rename
nik9000 Mar 9, 2022
12842e3
One more rename. And a test
nik9000 Mar 9, 2022
6031b08
Spotless
nik9000 Mar 9, 2022
af14f3a
Sneaky tests
nik9000 Mar 9, 2022
ce7a765
Spotless
nik9000 Mar 9, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.ProvidedIdFieldMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.search.QueryParserHelper;
Expand Down Expand Up @@ -184,7 +184,7 @@ protected final MapperService createMapperService(String mappings) {
similarityService,
mapperRegistry,
() -> { throw new UnsupportedOperationException(); },
new IdFieldMapper(() -> true),
new ProvidedIdFieldMapper(() -> true),
new ScriptCompiler() {
@Override
public <T> T compile(Script script, ScriptContext<T> scriptContext) {
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/82633.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 82633
summary: "TSDB: Support GET and DELETE and doc versioning"
area: TSDB
type: feature
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.backingIndexEqualTo;
import static org.hamcrest.Matchers.aMapWithSize;
Expand Down Expand Up @@ -301,10 +303,15 @@ public void testMigrateRegularDataStreamToTsdbDataStream() throws Exception {
int numDocs = 32;
var currentTime = Instant.now();
var currentMinus30Days = currentTime.minus(30, ChronoUnit.DAYS);
Set<Instant> times = new HashSet<>();
for (int i = 0; i < numRollovers; i++) {
for (int j = 0; j < numDocs; j++) {
var indexRequest = new Request("POST", "/k8s/_doc");
var time = Instant.ofEpochMilli(randomLongBetween(currentMinus30Days.toEpochMilli(), currentTime.toEpochMilli()));
var time = randomValueOtherThanMany(
times::contains,
() -> Instant.ofEpochMilli(randomLongBetween(currentMinus30Days.toEpochMilli(), currentTime.toEpochMilli()))
);
times.add(time);
indexRequest.setJsonEntity(DOC.replace("$time", formatInstant(time)));
var response = client().performRequest(indexRequest);
assertOK(response);
Expand Down Expand Up @@ -350,13 +357,15 @@ public void testMigrateRegularDataStreamToTsdbDataStream() throws Exception {
assertThat(newIndex, backingIndexEqualTo("k8s", 6));

// Ingest documents that will land in the new tsdb backing index:
var t = currentTime;
for (int i = 0; i < numDocs; i++) {
var indexRequest = new Request("POST", "/k8s/_doc");
indexRequest.setJsonEntity(DOC.replace("$time", formatInstant(currentTime)));
indexRequest.setJsonEntity(DOC.replace("$time", formatInstant(t)));
var response = client().performRequest(indexRequest);
assertOK(response);
var responseBody = entityAsMap(response);
assertThat((String) responseBody.get("_index"), backingIndexEqualTo("k8s", 6));
t = t.plusMillis(1000);
}

// Fail if documents target older non tsdb backing index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.DocumentParser;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.query.AbstractQueryBuilder;
Expand Down Expand Up @@ -701,22 +700,22 @@ private static Response prepareRamIndex(
CheckedBiFunction<SearchExecutionContext, LeafReaderContext, Response, IOException> handler,
IndexService indexService
) throws IOException {

Analyzer defaultAnalyzer = indexService.getIndexAnalyzers().getDefaultIndexAnalyzer();

try (Directory directory = new ByteBuffersDirectory()) {
try (IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(defaultAnalyzer))) {
String index = indexService.index().getName();
BytesReference document = request.contextSetup.document;
XContentType xContentType = request.contextSetup.xContentType;
SourceToParse sourceToParse = new SourceToParse("_id", document, xContentType);
MappingLookup mappingLookup = indexService.mapperService().mappingLookup();
DocumentParser documentParser = indexService.mapperService().documentParser();
DocumentMapper documentMapper = indexService.mapperService().documentMapper();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why this change is needed? I wonder if using documentParser is no longer legal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's legal, but without the createEmpty call here we won't set the _id if the index doesn't have any mappings.This createEmpty dance is what we do before indexing into an empty shard.

I think it'd be pretty reasonable to make documentParser work in these cases rather than make this change though.

if (documentMapper == null) {
documentMapper = DocumentMapper.createEmpty(indexService.mapperService());
}
// Note that we are not doing anything with dynamic mapping updates, hence fields that are not mapped but are present
// in the sample doc are not accessible from the script through doc['field'].
// This is a problem especially for indices that have no mappings, as no fields will be accessible, neither through doc
// nor _source (if there are no mappings there are no metadata fields).
ParsedDocument parsedDocument = documentParser.parseDocument(sourceToParse, mappingLookup);
ParsedDocument parsedDocument = documentMapper.parse(sourceToParse);
indexWriter.addDocuments(parsedDocument.docs());
try (IndexReader indexReader = DirectoryReader.open(indexWriter)) {
final IndexSearcher searcher = new IndexSearcher(indexReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ public static class Defaults {
}

private static void checkIndexCompatibility(IndexSettings settings, String name) {
String indexName = settings.getIndex().getName();
if (settings.getIndexMetadata().isRoutingPartitionedIndex()) {
throw new IllegalStateException(
"cannot create join field [" + name + "] " + "for the partitioned index " + "[" + settings.getIndex().getName() + "]"
);
throw new IllegalStateException("cannot create join field [" + name + "] for the partitioned index [" + indexName + "]");
}
if (settings.getIndexMetadata().getRoutingPaths().isEmpty() == false) {
throw new IllegalStateException("cannot create join field [" + name + "] for the index [" + indexName + "] with routing_path");
}
}

Expand Down Expand Up @@ -141,7 +143,7 @@ public ParentJoinFieldMapper build(MapperBuilderContext context) {
}
}

public static TypeParser PARSER = new TypeParser((n, c) -> {
public static final TypeParser PARSER = new TypeParser((n, c) -> {
checkIndexCompatibility(c.getIndexSettings(), n);
return new Builder(n);
});
Expand Down Expand Up @@ -293,7 +295,7 @@ public void parse(DocumentParserContext context) throws IOException {
if (fieldType().joiner.parentTypeExists(name)) {
// Index the document as a parent
String fieldName = fieldType().joiner.childJoinField(name);
parentIdFields.get(fieldName).indexValue(context, context.sourceToParse().id());
parentIdFields.get(fieldName).indexValue(context, context.id());
}

BytesRef binaryValue = new BytesRef(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,9 @@ tsdb:
- '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "cow", "uid":"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39", "ip": "10.10.55.4", "network": {"tx": 1434521831, "rx": 530575198}}}}'

- do:
catch: bad_request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will need some bwc-dance here with skip versions to ensure that the old version runs against an 8.1 cluster and the new version against 8.2? I think it could be ok to only have the new version against 8.2, since the old version is still tested via the old version test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll bet we never run these against a mixed version cluster. This should totally have failed....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started a discussion with some other folks about this one. We'll see where that goes.

delete_by_query:
index: tsdb
body:
query:
match_all: {}

- match: {failures.0.status: 400}
- match: {failures.0.cause.reason: "delete is not supported because the destination index [tsdb] is in time series mode"}
- match: {deleted: 1}
Loading