Skip to content

Commit c3433c6

Browse files
author
sukriti sinha
committed
Fix: Gradle Checks
Signed-off-by: sukriti sinha <[email protected]>
1 parent 2e31b7f commit c3433c6

File tree

10 files changed

+194
-171
lines changed

10 files changed

+194
-171
lines changed

gradle/run.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
/*
1313
* Licensed to Elasticsearch under one or more contributor
14-
* license agreements. See the NOTICE file distributed with
14+
* license agreements. See the
15+
NOTICE file distributed with
1516
* this work for additional information regarding copyright
1617
* ownership. Elasticsearch licenses this file to you under
1718
* the Apache License, Version 2.0 (the "License"); you may

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/RemoteStoreMetadata.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.io.IOException;
1212
import java.util.Map;
13+
1314
/**
1415
* Response model that holds the remote store metadata (segment and translog) for a shard.
1516
*
@@ -21,11 +22,7 @@ public class RemoteStoreMetadata implements Writeable, ToXContentFragment {
2122
private final Map<String, Object> translog;
2223
private final ShardRouting shardRouting;
2324

24-
public RemoteStoreMetadata(
25-
Map<String, Object> segments,
26-
Map<String, Object> translog,
27-
ShardRouting shardRouting
28-
) {
25+
public RemoteStoreMetadata(Map<String, Object> segments, Map<String, Object> translog, ShardRouting shardRouting) {
2926
this.segments = segments;
3027
this.translog = translog;
3128
this.shardRouting = shardRouting;
@@ -47,7 +44,7 @@ public void writeTo(StreamOutput out) throws IOException {
4744
@Override
4845
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
4946
builder.startObject();
50-
47+
5148
builder.startObject("segments");
5249
for (Map.Entry<String, Object> entry : segments.entrySet()) {
5350
builder.field(entry.getKey(), entry.getValue());
@@ -66,4 +63,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
6663
public ShardRouting getShardRouting() {
6764
return shardRouting;
6865
}
69-
}
66+
}

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/RemoteStoreMetadataAction.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.action.admin.cluster.remotestore.metadata;
9+
package org.opensearch.action.admin.cluster.remotestore.metadata;
1010

11-
import org.opensearch.action.ActionType;
12-
13-
/**
14-
* Action to fetch metadata from remote store
15-
*
16-
* @opensearch.internal
17-
*/
11+
import org.opensearch.action.ActionType;
12+
13+
/**
14+
* Action to fetch metadata from remote store
15+
*
16+
* @opensearch.internal
17+
*/
1818
public class RemoteStoreMetadataAction extends ActionType<RemoteStoreMetadataResponse> {
1919
public static final RemoteStoreMetadataAction INSTANCE = new RemoteStoreMetadataAction();
2020
public static final String NAME = "cluster:admin/remote_store/metadata";
2121

2222
private RemoteStoreMetadataAction() {
2323
super(NAME, RemoteStoreMetadataResponse::new);
2424
}
25-
}
25+
}

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/RemoteStoreMetadataRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.opensearch.core.common.io.stream.StreamOutput;
77

88
import java.io.IOException;
9+
910
/**
1011
* Request object for fetching remote store metadata of shards for a given index.
1112
*
@@ -50,4 +51,4 @@ public void local(boolean local) {
5051
public boolean local() {
5152
return local;
5253
}
53-
}
54+
}

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/RemoteStoreMetadataRequestBuilder.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.action.admin.cluster.remotestore.metadata;
9+
package org.opensearch.action.admin.cluster.remotestore.metadata;
1010

11-
import org.opensearch.action.support.broadcast.BroadcastOperationRequestBuilder;
12-
import org.opensearch.common.annotation.PublicApi;
13-
import org.opensearch.common.unit.TimeValue;
14-
import org.opensearch.transport.client.OpenSearchClient;
15-
16-
/**
17-
* Builder for RemoteStoreMetadataRequest
18-
*
19-
* @opensearch.api
20-
*/
21-
@PublicApi(since = "3.0.0")
22-
public class RemoteStoreMetadataRequestBuilder extends BroadcastOperationRequestBuilder<
23-
RemoteStoreMetadataRequest,
24-
RemoteStoreMetadataResponse,
25-
RemoteStoreMetadataRequestBuilder> {
26-
27-
public RemoteStoreMetadataRequestBuilder(OpenSearchClient client, RemoteStoreMetadataAction action) {
28-
super(client, action, new RemoteStoreMetadataRequest());
29-
}
30-
31-
/**
32-
* Sets timeout of request.
33-
*/
34-
public final RemoteStoreMetadataRequestBuilder setTimeout(TimeValue timeout) {
35-
request.timeout(timeout);
36-
return this;
37-
}
38-
39-
/**
40-
* Sets shards preference of request.
41-
*/
42-
public final RemoteStoreMetadataRequestBuilder setShards(String... shards) {
43-
request.shards(shards);
44-
return this;
45-
}
46-
47-
/**
48-
* Sets local shards preference of request.
49-
*/
50-
public final RemoteStoreMetadataRequestBuilder setLocal(boolean local) {
51-
request.local(local);
52-
return this;
53-
}
54-
}
11+
import org.opensearch.action.support.broadcast.BroadcastOperationRequestBuilder;
12+
import org.opensearch.common.annotation.PublicApi;
13+
import org.opensearch.common.unit.TimeValue;
14+
import org.opensearch.transport.client.OpenSearchClient;
15+
16+
/**
17+
* Builder for RemoteStoreMetadataRequest
18+
*
19+
* @opensearch.api
20+
*/
21+
@PublicApi(since = "3.0.0")
22+
public class RemoteStoreMetadataRequestBuilder extends BroadcastOperationRequestBuilder<
23+
RemoteStoreMetadataRequest,
24+
RemoteStoreMetadataResponse,
25+
RemoteStoreMetadataRequestBuilder> {
26+
27+
public RemoteStoreMetadataRequestBuilder(OpenSearchClient client, RemoteStoreMetadataAction action) {
28+
super(client, action, new RemoteStoreMetadataRequest());
29+
}
30+
31+
/**
32+
* Sets timeout of request.
33+
*/
34+
public final RemoteStoreMetadataRequestBuilder setTimeout(TimeValue timeout) {
35+
request.timeout(timeout);
36+
return this;
37+
}
38+
39+
/**
40+
* Sets shards preference of request.
41+
*/
42+
public final RemoteStoreMetadataRequestBuilder setShards(String... shards) {
43+
request.shards(shards);
44+
return this;
45+
}
46+
47+
/**
48+
* Sets local shards preference of request.
49+
*/
50+
public final RemoteStoreMetadataRequestBuilder setLocal(boolean local) {
51+
request.local(local);
52+
return this;
53+
}
54+
}

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/RemoteStoreMetadataResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ static final class Fields {
9898
static final String SHARDS = "shards";
9999
static final String INDICES = "indices";
100100
}
101-
}
101+
}

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/metadata/TransportRemoteStoreMetadataAction.java

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
import java.nio.file.DirectoryStream;
3636
import java.nio.file.Files;
3737
import java.nio.file.Path;
38-
import java.util.*;
38+
import java.util.ArrayList;
39+
import java.util.Collections;
40+
import java.util.HashMap;
41+
import java.util.List;
42+
import java.util.Map;
43+
import java.util.Objects;
44+
import java.util.Arrays;
3945
import java.util.concurrent.atomic.AtomicInteger;
4046
import java.util.stream.Collectors;
4147

@@ -77,7 +83,7 @@ public TransportRemoteStoreMetadataAction(
7783
protected void doExecute(Task task, RemoteStoreMetadataRequest request, ActionListener<RemoteStoreMetadataResponse> listener) {
7884
try {
7985
ClusterState state = clusterService.state();
80-
86+
8187
// Check blocks
8288
ClusterBlockException blockException = checkBlocks(state, request);
8389
if (blockException != null) {
@@ -88,14 +94,13 @@ protected void doExecute(Task task, RemoteStoreMetadataRequest request, ActionLi
8894
// Resolve concrete indices
8995
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
9096
if (concreteIndices.length == 0) {
91-
listener.onResponse(new RemoteStoreMetadataResponse(
92-
new RemoteStoreMetadata[0], 0, 0, 0, Collections.emptyList()));
97+
listener.onResponse(new RemoteStoreMetadataResponse(new RemoteStoreMetadata[0], 0, 0, 0, Collections.emptyList()));
9398
return;
9499
}
95100

96101
// Get relevant shards
97102
List<ShardRouting> selectedShards = getSelectedShards(state, request, concreteIndices);
98-
103+
99104
// Process each shard
100105
List<RemoteStoreMetadata> responses = new ArrayList<>();
101106
AtomicInteger successfulShards = new AtomicInteger(0);
@@ -109,10 +114,9 @@ protected void doExecute(Task task, RemoteStoreMetadataRequest request, ActionLi
109114
successfulShards.incrementAndGet();
110115
} catch (Exception e) {
111116
failedShards.incrementAndGet();
112-
shardFailures.add(new DefaultShardOperationFailedException(
113-
shardRouting.shardId().getIndexName(),
114-
shardRouting.shardId().getId(),
115-
e));
117+
shardFailures.add(
118+
new DefaultShardOperationFailedException(shardRouting.shardId().getIndexName(), shardRouting.shardId().getId(), e)
119+
);
116120
}
117121
}
118122

@@ -123,7 +127,7 @@ protected void doExecute(Task task, RemoteStoreMetadataRequest request, ActionLi
123127
failedShards.get(),
124128
shardFailures
125129
);
126-
130+
127131
listener.onResponse(response);
128132

129133
} catch (Exception e) {
@@ -141,22 +145,23 @@ private ClusterBlockException checkBlocks(ClusterState state, RemoteStoreMetadat
141145
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, concreteIndices);
142146
}
143147

144-
private List<ShardRouting> getSelectedShards(
145-
ClusterState clusterState,
146-
RemoteStoreMetadataRequest request,
147-
String[] concreteIndices
148-
) {
148+
private List<ShardRouting> getSelectedShards(ClusterState clusterState, RemoteStoreMetadataRequest request, String[] concreteIndices) {
149149
return clusterState.routingTable()
150150
.allShards(concreteIndices)
151151
.getShardRoutings()
152152
.stream()
153-
.filter(shardRouting -> request.shards().length == 0 ||
154-
Arrays.asList(request.shards()).contains(Integer.toString(shardRouting.shardId().id())))
155-
.filter(shardRouting -> !request.local() ||
156-
Objects.equals(shardRouting.currentNodeId(), clusterState.getNodes().getLocalNodeId()))
157-
.filter(shardRouting -> Boolean.parseBoolean(
158-
clusterState.getMetadata().index(shardRouting.index())
159-
.getSettings().get(IndexMetadata.SETTING_REMOTE_STORE_ENABLED)))
153+
.filter(
154+
shardRouting -> request.shards().length == 0
155+
|| Arrays.asList(request.shards()).contains(Integer.toString(shardRouting.shardId().id()))
156+
)
157+
.filter(
158+
shardRouting -> !request.local() || Objects.equals(shardRouting.currentNodeId(), clusterState.getNodes().getLocalNodeId())
159+
)
160+
.filter(
161+
shardRouting -> Boolean.parseBoolean(
162+
clusterState.getMetadata().index(shardRouting.index()).getSettings().get(IndexMetadata.SETTING_REMOTE_STORE_ENABLED)
163+
)
164+
)
160165
.collect(Collectors.toList());
161166
}
162167

@@ -168,9 +173,7 @@ private RemoteStoreMetadata getShardMetadata(ShardRouting shardRouting) throws I
168173
throw new ShardNotFoundException(indexShard.shardId());
169174
}
170175

171-
String repoLocation = clusterService.localNode()
172-
.getAttributes()
173-
.get("remote_store.repository.my-repository.settings.location");
176+
String repoLocation = clusterService.localNode().getAttributes().get("remote_store.repository.my-repository.settings.location");
174177

175178
String indexUUID = shardRouting.index().getUUID();
176179
int shardId = shardRouting.shardId().id();
@@ -191,8 +194,10 @@ private Map<String, Object> readSegmentMetadata(String metadataPath) throws IOEx
191194

192195
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "metadata__*")) {
193196
for (Path metadataFile : stream) {
194-
try (InputStream in = Files.newInputStream(metadataFile);
195-
IndexInput idxIn = new ByteArrayIndexInput(metadataFile.getFileName().toString(), in.readAllBytes())) {
197+
try (
198+
InputStream in = Files.newInputStream(metadataFile);
199+
IndexInput idxIn = new ByteArrayIndexInput(metadataFile.getFileName().toString(), in.readAllBytes())
200+
) {
196201

197202
RemoteSegmentMetadata segMetadata = metadataStreamWrapper.readStream(idxIn);
198203
Map<String, Object> fileMetadata = new HashMap<>();
@@ -212,15 +217,25 @@ private Map<String, Object> readSegmentMetadata(String metadataPath) throws IOEx
212217

213218
if (segMetadata.getReplicationCheckpoint() != null) {
214219
var cp = segMetadata.getReplicationCheckpoint();
215-
fileMetadata.put("replication_checkpoint", Map.of(
216-
"shard_id", cp.getShardId().toString(),
217-
"primary_term", cp.getPrimaryTerm(),
218-
"generation", cp.getSegmentsGen(),
219-
"version", cp.getSegmentInfosVersion(),
220-
"length", cp.getLength(),
221-
"codec", cp.getCodec(),
222-
"created_timestamp", cp.getCreatedTimeStamp()
223-
));
220+
fileMetadata.put(
221+
"replication_checkpoint",
222+
Map.of(
223+
"shard_id",
224+
cp.getShardId().toString(),
225+
"primary_term",
226+
cp.getPrimaryTerm(),
227+
"generation",
228+
cp.getSegmentsGen(),
229+
"version",
230+
cp.getSegmentInfosVersion(),
231+
"length",
232+
cp.getLength(),
233+
"codec",
234+
cp.getCodec(),
235+
"created_timestamp",
236+
cp.getCreatedTimeStamp()
237+
)
238+
);
224239
}
225240

226241
fileMetadata.put("generation", segMetadata.getGeneration());
@@ -239,8 +254,10 @@ private Map<String, Object> readTranslogMetadata(String metadataPath) throws IOE
239254

240255
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "metadata__*")) {
241256
for (Path metadataFile : stream) {
242-
try (InputStream inputStream = Files.newInputStream(metadataFile);
243-
BytesStreamInput input = new BytesStreamInput(inputStream.readAllBytes())) {
257+
try (
258+
InputStream inputStream = Files.newInputStream(metadataFile);
259+
BytesStreamInput input = new BytesStreamInput(inputStream.readAllBytes())
260+
) {
244261

245262
Map<String, Object> fileMetadata = new HashMap<>();
246263
String[] parts = metadataFile.getFileName().toString().split(TranslogTransferMetadata.METADATA_SEPARATOR);
@@ -256,16 +273,23 @@ private Map<String, Object> readTranslogMetadata(String metadataPath) throws IOE
256273
long generation = input.readLong();
257274
long minTranslogGen = input.readLong();
258275
Map<String, String> genToTermMap = input.readMap(StreamInput::readString, StreamInput::readString);
259-
fileMetadata.put("content", Map.of(
260-
"primary_term", primaryTerm,
261-
"generation", generation,
262-
"min_translog_generation", minTranslogGen,
263-
"generation_to_term_mapping", genToTermMap
264-
));
276+
fileMetadata.put(
277+
"content",
278+
Map.of(
279+
"primary_term",
280+
primaryTerm,
281+
"generation",
282+
generation,
283+
"min_translog_generation",
284+
minTranslogGen,
285+
"generation_to_term_mapping",
286+
genToTermMap
287+
)
288+
);
265289
metadata.put(metadataFile.getFileName().toString(), fileMetadata);
266290
}
267291
}
268292
}
269293
return metadata;
270294
}
271-
}
295+
}

0 commit comments

Comments
 (0)