-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for append only indices
Signed-off-by: RS146BIJAY <[email protected]>
- Loading branch information
1 parent
1935650
commit 38061f7
Showing
8 changed files
with
334 additions
and
29 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
libs/common/src/main/java/org/opensearch/common/IndexingRetryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common; | ||
|
||
/** | ||
* This exception indicates that retry has been made during indexing for AppendOnly index. If the response of any | ||
* indexing request contains this Exception in the response, we do not need to add a translog entry for this request. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class IndexingRetryException extends RuntimeException { | ||
public IndexingRetryException(String message) { | ||
super(message); | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
server/src/internalClusterTest/java/org/opensearch/action/bulk/AppendOnlyIndicesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.bulk; | ||
|
||
import org.opensearch.action.admin.cluster.node.stats.NodeStats; | ||
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.ingest.IngestTestPlugin; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.transport.MockTransportService; | ||
import org.opensearch.transport.ConnectTransportException; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class AppendOnlyIndicesIT extends OpenSearchIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(IngestTestPlugin.class, MockTransportService.TestPlugin.class); | ||
} | ||
|
||
public void testIndexDocumentWithACustomDocIdForAppendOnlyIndices() throws Exception { | ||
Client client = internalCluster().coordOnlyNodeClient(); | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareCreate("index") | ||
.setSettings( | ||
Settings.builder() | ||
.put("index.number_of_replicas", 0) | ||
.put("index.number_of_shards", 1) | ||
.put("index.append_only.enabled", true) | ||
) | ||
); | ||
ensureGreen("index"); | ||
|
||
BulkRequestBuilder bulkBuilder = client.prepareBulk(); | ||
|
||
XContentBuilder doc = null; | ||
doc = jsonBuilder().startObject().field("foo", "bar").endObject(); | ||
bulkBuilder.add(client.prepareIndex("index").setId(Integer.toString(0)).setSource(doc)); | ||
|
||
BulkResponse response = bulkBuilder.get(); | ||
assertThat(response.getItems()[0].getFailureMessage(), containsString("Operation [INDEX] is not allowed with a custom doc id 0")); | ||
} | ||
|
||
public void testUpdateDeleteDocumentForAppendOnlyIndices() throws Exception { | ||
Client client = internalCluster().coordOnlyNodeClient(); | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareCreate("index") | ||
.setSettings( | ||
Settings.builder() | ||
.put("index.number_of_replicas", 0) | ||
.put("index.number_of_shards", 1) | ||
.put("index.append_only.enabled", true) | ||
) | ||
); | ||
ensureGreen("index"); | ||
|
||
BulkRequestBuilder bulkBuilder = client.prepareBulk(); | ||
|
||
XContentBuilder doc = null; | ||
doc = jsonBuilder().startObject().field("foo", "bar").endObject(); | ||
bulkBuilder.add(client.prepareIndex("index").setSource(doc)); | ||
|
||
bulkBuilder.get(); | ||
BulkResponse response = client().prepareBulk().add(client().prepareUpdate("index", "0").setDoc("foo", "updated")).get(); | ||
assertThat( | ||
response.getItems()[0].getFailureMessage(), | ||
containsString("Operation [UPDATE] is not allowed for append only index index;") | ||
); | ||
|
||
response = client().prepareBulk().add(client().prepareDelete("index", "0")).get(); | ||
assertThat( | ||
response.getItems()[0].getFailureMessage(), | ||
containsString("Operation [DELETE] is not allowed for append only index index;") | ||
); | ||
} | ||
|
||
public void testRetryForAppendOnlyIndices() throws Exception { | ||
final AtomicBoolean exceptionThrown = new AtomicBoolean(false); | ||
int numDocs = scaledRandomIntBetween(100, 1000); | ||
Client client = internalCluster().coordOnlyNodeClient(); | ||
NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); | ||
NodeStats unluckyNode = randomFrom( | ||
nodeStats.getNodes().stream().filter((s) -> s.getNode().isDataNode()).collect(Collectors.toList()) | ||
); | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareCreate("index") | ||
.setSettings( | ||
Settings.builder() | ||
.put("index.number_of_replicas", 0) | ||
.put("index.number_of_shards", 1) | ||
.put("index.append_only.enabled", true) | ||
) | ||
); | ||
ensureGreen("index"); | ||
logger.info("unlucky node: {}", unluckyNode.getNode()); | ||
// create a transport service that throws a ConnectTransportException for one bulk request and therefore triggers a retry. | ||
for (NodeStats dataNode : nodeStats.getNodes()) { | ||
if (exceptionThrown.get()) { | ||
break; | ||
} | ||
|
||
MockTransportService mockTransportService = ((MockTransportService) internalCluster().getInstance( | ||
TransportService.class, | ||
dataNode.getNode().getName() | ||
)); | ||
mockTransportService.addSendBehavior( | ||
internalCluster().getInstance(TransportService.class, unluckyNode.getNode().getName()), | ||
(connection, requestId, action, request, options) -> { | ||
connection.sendRequest(requestId, action, request, options); | ||
if (action.equals(TransportShardBulkAction.ACTION_NAME) && exceptionThrown.compareAndSet(false, true)) { | ||
logger.debug("Throw ConnectTransportException"); | ||
throw new ConnectTransportException(connection.getNode(), action); | ||
} | ||
} | ||
); | ||
} | ||
|
||
BulkRequestBuilder bulkBuilder = client.prepareBulk(); | ||
|
||
for (int i = 0; i < numDocs; i++) { | ||
XContentBuilder doc = null; | ||
doc = jsonBuilder().startObject().field("foo", "bar").endObject(); | ||
bulkBuilder.add(client.prepareIndex("index").setSource(doc)); | ||
} | ||
|
||
BulkResponse response = bulkBuilder.get(); | ||
for (BulkItemResponse singleIndexResponse : response.getItems()) { | ||
// Retry will not create a new version. | ||
assertThat(singleIndexResponse.getVersion(), equalTo(1L)); | ||
} | ||
|
||
response = client().prepareBulk().add(client().prepareUpdate("index", "0").setDoc("foo", "updated")).get(); | ||
assertThat( | ||
response.getItems()[0].getFailureMessage(), | ||
containsString("Operation [UPDATE] is not allowed for append only index index;") | ||
); | ||
|
||
response = client().prepareBulk().add(client().prepareDelete("index", "0")).get(); | ||
assertThat( | ||
response.getItems()[0].getFailureMessage(), | ||
containsString("Operation [DELETE] is not allowed for append only index index;") | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.