Skip to content

Commit

Permalink
Add rocksdb as a storage engine...
Browse files Browse the repository at this point in the history
  • Loading branch information
fcofdez committed May 28, 2024
1 parent 1cff3b4 commit 58236bd
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 3 deletions.
5 changes: 5 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,11 @@
<sha256 value="31cef12ddec979d1f86d7cf708c41a17da523d05c685fd6642e9d0b2addb7240" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.rocksdb" name="rocksdbjni" version="9.2.1">
<artifact name="rocksdbjni-9.2.1.jar">
<sha256 value="24b34e0f76c913a7b4750528e37ddc14397fa2e00c0ad373e1d1e1ae3a6f2b52" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.skyscreamer" name="jsonassert" version="1.5.0">
<artifact name="jsonassert-1.5.0.jar">
<sha256 value="a310bc79c3f4744e2b2e993702fcebaf3696fec0063643ffdc6b49a8fb03ef39" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public CommitStats(SegmentInfos segmentInfos) {
numDocs = Lucene.getNumDocs(segmentInfos);
}

public CommitStats(Map<String, String> userData, long generation, String id, int numDocs) {
this.userData = userData;
this.generation = generation;
this.id = id;
this.numDocs = numDocs;
}

CommitStats(StreamInput in) throws IOException {
userData = in.readImmutableMap(StreamInput::readString);
generation = in.readLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public String getId() {
return id;
}

void setTranslogLocation(Translog.Location translogLocation) {
public void setTranslogLocation(Translog.Location translogLocation) {
if (freeze.get() == null) {
this.translogLocation = translogLocation;
} else {
Expand Down Expand Up @@ -911,7 +911,7 @@ protected final void ensureOpen() {
}

/** get commits stats for the last commit */
public final CommitStats commitStats() {
public CommitStats commitStats() {
return new CommitStats(getLastCommittedSegmentInfos());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier) t
// time elapses after the engine is created above (pulling the config settings) until we set the engine reference, during
// which settings changes could possibly have happened, so here we forcefully push any config changes to the new engine.
onSettingsChanged();
assert assertSequenceNumbersInCommit();
// assert assertSequenceNumbersInCommit();
recoveryState.validateCurrentStage(RecoveryState.Stage.TRANSLOG);
checkAndCallWaitForEngineOrClosedShardListeners();
}
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugin/kv-indices/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
esplugin {
name 'kv-indices'
description 'A plugin for the kv indices functionality'
classname 'org.elasticsearch.xpack.kv.KVIndices'
extendedPlugins = ['x-pack-core']
}
base {
archivesName = 'x-pack-kv-indices'
}

dependencies {
compileOnly project(path: xpackModule('core'))
testImplementation(testArtifact(project(xpackModule('core'))))
api 'org.rocksdb:rocksdbjni:9.2.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.index.engine.kv;

import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
import org.elasticsearch.xpack.kv.KVIndices;
import org.elasticsearch.xpack.kv.RocksEngine;

import java.util.Collection;
import java.util.List;

import static org.hamcrest.Matchers.notNullValue;

@ESIntegTestCase.ClusterScope(numDataNodes = 0)
@ESTestCase.WithoutSecurityManager
public class KVIndexIT extends ESIntegTestCase {

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return List.of(KVIndices.class, LocalStateCompositeXPackPlugin.class);
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

public void testBasic() throws Exception {
internalCluster().startNodes(1);
var indexName = randomIdentifier();
createIndex(indexName, indexSettings(1, 0).put(RocksEngine.INDEX_KV.getKey(), true).build());
indexDoc(indexName, "test", "asd", "asd1");
indexDoc(indexName, "test2", "asd", "asd1");
RocksEngine engine = (RocksEngine) internalCluster().getInstance(IndicesService.class)
.indexService(resolveIndex(indexName))
.getShard(0)
.getEngineOrNull();

assertThat(engine.getBytes("test".getBytes()), notNullValue());
assertThat(engine.getBytes("test2".getBytes()), notNullValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.kv;

import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.EnginePlugin;
import org.elasticsearch.plugins.Plugin;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class KVIndices extends Plugin implements ActionPlugin, EnginePlugin {

@Override
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
if (indexSettings.getValue(RocksEngine.INDEX_KV)) {
return Optional.of(RocksEngine::new);
} else {
return Optional.empty();
}
}

@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(RocksEngine.INDEX_KV);
}
}
Loading

0 comments on commit 58236bd

Please sign in to comment.