Skip to content

Commit 9be3889

Browse files
committed
[8.18] Allow a tsdb data stream to rolled over to a logsdb data stream
and the other way around. Backporting elastic#126640 to 8.18 branch. This doesn't make much sense. However, if a data stream's index mode differs from the index mode of most recent backing index, then this can cause confusion. Typically, misconfiguration is a reason this can happen. Related to elastic#126637
1 parent d04357b commit 9be3889

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package org.elasticsearch.cluster.metadata;
1010

11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
1113
import org.apache.lucene.document.LongPoint;
1214
import org.apache.lucene.index.LeafReader;
1315
import org.apache.lucene.index.PointValues;
@@ -68,6 +70,8 @@
6870

6971
public final class DataStream implements SimpleDiffable<DataStream>, ToXContentObject, IndexAbstraction {
7072

73+
private static final Logger LOGGER = LogManager.getLogger(DataStream.class);
74+
7175
public static final FeatureFlag FAILURE_STORE_FEATURE_FLAG = new FeatureFlag("failure_store");
7276
public static final TransportVersion ADDED_FAILURE_STORE_TRANSPORT_VERSION = TransportVersions.V_8_12_0;
7377
public static final TransportVersion ADDED_AUTO_SHARDING_EVENT_VERSION = TransportVersions.V_8_14_0;
@@ -577,6 +581,12 @@ public DataStream unsafeRollover(
577581
} else if (dsIndexMode == IndexMode.LOGSDB && (indexModeFromTemplate == null || indexModeFromTemplate == IndexMode.STANDARD)) {
578582
// Allow downgrading a time series data stream to a regular data stream
579583
dsIndexMode = null;
584+
} else if (dsIndexMode == IndexMode.TIME_SERIES && indexModeFromTemplate == IndexMode.LOGSDB) {
585+
dsIndexMode = IndexMode.LOGSDB;
586+
LOGGER.warn("Changing [{}] index mode from [{}] to [{}]", name, indexModeFromTemplate, dsIndexMode);
587+
} else if (dsIndexMode == IndexMode.LOGSDB && indexModeFromTemplate == IndexMode.TIME_SERIES) {
588+
dsIndexMode = IndexMode.TIME_SERIES;
589+
LOGGER.warn("Changing [{}] index mode from [{}] to [{}]", name, indexModeFromTemplate, dsIndexMode);
580590
}
581591

582592
List<Index> backingIndices = new ArrayList<>(this.backingIndices.indices);

server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,39 @@ public void testRolloverUpgradeToLogsdbDataStream() {
277277
assertThat(rolledDs.getIndexMode(), equalTo(IndexMode.LOGSDB));
278278
}
279279

280+
public void testRolloverFromTSdbToLogsdb() {
281+
DataStream ds = DataStreamTestHelper.randomInstance().copy().setReplicated(false).setIndexMode(IndexMode.TIME_SERIES).build();
282+
final var project = ProjectMetadata.builder(randomProjectIdOrDefault()).build();
283+
var newCoordinates = ds.nextWriteIndexAndGeneration(project, ds.getDataComponent());
284+
285+
var rolledDs = ds.rollover(new Index(newCoordinates.v1(), UUIDs.randomBase64UUID()), newCoordinates.v2(), IndexMode.LOGSDB, null);
286+
assertThat(rolledDs.getName(), equalTo(ds.getName()));
287+
assertThat(rolledDs.getGeneration(), equalTo(ds.getGeneration() + 1));
288+
assertThat(rolledDs.getIndices().size(), equalTo(ds.getIndices().size() + 1));
289+
assertTrue(rolledDs.getIndices().containsAll(ds.getIndices()));
290+
assertTrue(rolledDs.getIndices().contains(rolledDs.getWriteIndex()));
291+
assertThat(rolledDs.getIndexMode(), equalTo(IndexMode.LOGSDB));
292+
}
293+
294+
public void testRolloverFromLogsdbToTsdb() {
295+
DataStream ds = DataStreamTestHelper.randomInstance().copy().setReplicated(false).setIndexMode(IndexMode.LOGSDB).build();
296+
final var project = ProjectMetadata.builder(randomProjectIdOrDefault()).build();
297+
var newCoordinates = ds.nextWriteIndexAndGeneration(project, ds.getDataComponent());
298+
299+
var rolledDs = ds.rollover(
300+
new Index(newCoordinates.v1(), UUIDs.randomBase64UUID()),
301+
newCoordinates.v2(),
302+
IndexMode.TIME_SERIES,
303+
null
304+
);
305+
assertThat(rolledDs.getName(), equalTo(ds.getName()));
306+
assertThat(rolledDs.getGeneration(), equalTo(ds.getGeneration() + 1));
307+
assertThat(rolledDs.getIndices().size(), equalTo(ds.getIndices().size() + 1));
308+
assertTrue(rolledDs.getIndices().containsAll(ds.getIndices()));
309+
assertTrue(rolledDs.getIndices().contains(rolledDs.getWriteIndex()));
310+
assertThat(rolledDs.getIndexMode(), equalTo(IndexMode.TIME_SERIES));
311+
}
312+
280313
public void testRolloverDowngradeFromTsdbToRegularDataStream() {
281314
DataStream ds = DataStreamTestHelper.randomInstance().copy().setReplicated(false).setIndexMode(IndexMode.TIME_SERIES).build();
282315
var newCoordinates = ds.nextWriteIndexAndGeneration(Metadata.EMPTY_METADATA, ds.getDataComponent());

0 commit comments

Comments
 (0)