Skip to content
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

Force DOCUMENT replication on lock index #417

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -24,6 +24,7 @@
import org.opensearch.action.update.UpdateRequest;
import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
Expand All @@ -42,6 +43,9 @@
import java.nio.charset.StandardCharsets;
import java.time.Instant;

import static org.opensearch.indices.replication.common.ReplicationType.DOCUMENT;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;

public final class LockService {
private static final Logger logger = LogManager.getLogger(LockService.class);
private static final String LOCK_INDEX_NAME = ".opendistro-job-scheduler-lock";
Expand Down Expand Up @@ -80,7 +84,10 @@ void createLockIndex(ActionListener<Boolean> listener) {
if (lockIndexExist()) {
listener.onResponse(true);
} else {
final CreateIndexRequest request = new CreateIndexRequest(LOCK_INDEX_NAME).mapping(lockMapping());
// Temporarily force DOCUMENT replication until SEGMENT supports GET by id
// https://github.com/opensearch-project/OpenSearch/issues/8536
Settings replicationSettings = Settings.builder().put(SETTING_REPLICATION_TYPE, DOCUMENT.name()).build();
final CreateIndexRequest request = new CreateIndexRequest(LOCK_INDEX_NAME, replicationSettings).mapping(lockMapping());
client.admin()
.indices()
.create(request, ActionListener.wrap(response -> listener.onResponse(response.isAcknowledged()), exception -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package org.opensearch.jobscheduler.multinode;

import com.google.common.collect.ImmutableMap;

import java.io.IOException;

import org.junit.Before;
Expand All @@ -23,13 +21,16 @@
import org.opensearch.jobscheduler.transport.AcquireLockResponse;
import org.opensearch.test.OpenSearchIntegTestCase;

import com.google.common.collect.ImmutableMap;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2)
public class GetLockMultiNodeRestIT extends ODFERestTestCase {

private String initialJobId;
private String initialJobIndexName;
private Response initialGetLockResponse;

@Override
@Before
public void setUp() throws Exception {
super.setUp();
Expand All @@ -53,6 +54,7 @@ public void testGetLockRestAPI() throws Exception {

// Submit 10 requests to generate new lock models for different job indexes
for (int i = 0; i < 10; i++) {
String expectedLockId = TestHelpers.generateExpectedLockId(String.valueOf(i), String.valueOf(i));
Response getLockResponse = TestHelpers.makeRequest(
client(),
"GET",
Expand All @@ -61,10 +63,20 @@ public void testGetLockRestAPI() throws Exception {
TestHelpers.toHttpEntity(TestHelpers.generateAcquireLockRequestBody(String.valueOf(i), String.valueOf(i))),
null
);
// Releasing lock will test that it exists (Get by ID)
Response releaseLockResponse = TestHelpers.makeRequest(
client(),
"PUT",
TestHelpers.RELEASE_LOCK_BASE_URI + "/" + expectedLockId,
ImmutableMap.of(),
null,
null
);
assertEquals("success", entityAsMap(releaseLockResponse).get("release-lock"));

String lockId = validateResponseAndGetLockId(getLockResponse);

assertEquals(TestHelpers.generateExpectedLockId(String.valueOf(i), String.valueOf(i)), lockId);
assertEquals(expectedLockId, lockId);
}
}

Expand Down