Skip to content

Commit 3e8e82c

Browse files
authored
Merge pull request #1211 from alliance-genome/SCRUM-4496
Added code to pull shard count into a configuration variable
2 parents 25a503b + 2dcab59 commit 3e8e82c

5 files changed

Lines changed: 24 additions & 6 deletions

File tree

agr_java_core/src/main/java/org/alliancegenome/core/config/ConfigHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.alliancegenome.core.config.Constants.ES_INDEX_PREFIX;
2020
import static org.alliancegenome.core.config.Constants.ES_INDEX_SUFFIX;
2121
import static org.alliancegenome.core.config.Constants.ES_PORT;
22+
import static org.alliancegenome.core.config.Constants.ES_SHARD_COUNT;
2223
import static org.alliancegenome.core.config.Constants.EXTRACTOR_OUTPUTDIR;
2324
import static org.alliancegenome.core.config.Constants.FMS_URL;
2425
import static org.alliancegenome.core.config.Constants.GO_TERM_LIST;
@@ -80,6 +81,7 @@ public static void init() {
8081
// If both are used then the resulting index name is: {ES_INDEX_PREFIX}_{ES_INDEX}_{ES_INDEX_SUFFIX}_{TIMESTAMP}"
8182
defaults.put(ES_HOST, "localhost");
8283
defaults.put(ES_PORT, "9200");
84+
defaults.put(ES_SHARD_COUNT, "4");
8385

8486
// ES Bulk Processing defaults
8587
defaults.put(ES_BULK_ACTION_SIZE, "400");
@@ -239,6 +241,17 @@ public static String getEsHost() {
239241
}
240242
return config.get(ES_HOST);
241243
}
244+
245+
public static int getEsShardCount() {
246+
if (!init) {
247+
init();
248+
}
249+
try {
250+
return Integer.parseInt(config.get(ES_SHARD_COUNT));
251+
} catch (NumberFormatException e) {
252+
return 0;
253+
}
254+
}
242255

243256
public static Multimap<String, Integer> getEsHostMap() {
244257

agr_java_core/src/main/java/org/alliancegenome/core/config/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private Constants() { }
1313
public static final String ES_INDEX_SUFFIX = "ES_INDEX_SUFFIX";
1414
public static final String ES_HOST = "ES_HOST";
1515
public static final String ES_PORT = "ES_PORT";
16+
public static final String ES_SHARD_COUNT = "ES_SHARD_COUNT";
1617

1718
public static final String ES_BULK_ACTION_SIZE = "ES_BULK_ACTION_SIZE";
1819
public static final String ES_BULK_REQUEST_SIZE = "ES_BULK_REQUEST_SIZE";

agr_java_core/src/main/java/org/alliancegenome/es/index/site/schema/settings/SiteIndexSettings.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66

77
public class SiteIndexSettings extends Settings {
88

9-
public SiteIndexSettings(Boolean pretty) {
9+
private Integer shardCount;
10+
11+
public SiteIndexSettings(Boolean pretty, Integer shardCount) {
1012
super(pretty);
13+
this.shardCount = shardCount;
1114
}
1215

1316
// Used for the settings for site_index
17+
@Override
1418
public void buildSettings() throws IOException {
1519
builder.startObject();
1620
builder.startObject("index")
1721
.field("max_result_window", "250000")
1822
.field("mapping.total_fields.limit", "25000")
1923
.field("number_of_replicas", "0")
20-
.field("number_of_shards", "16");
24+
.field("number_of_shards", shardCount);
2125
buildAnalysis(false);
2226
builder.endObject();
2327
builder.endObject();

agr_java_core/src/main/java/org/alliancegenome/es/util/IndexManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public IndexManager(Settings settings) {
6767
}
6868

6969
public IndexManager() {
70-
this(new SiteIndexSettings(true), new Mapping(true));
70+
this(new SiteIndexSettings(true, ConfigHelper.getEsShardCount()), new Mapping(true));
7171
}
7272

7373
public void createAlias(String alias, String index) { // ES Util
@@ -325,7 +325,7 @@ private String createRepo(String repoName) {
325325
if (repoName != null && repoName.length() > 0) {
326326
try {
327327

328-
SiteIndexSettings settings = new SiteIndexSettings(true);
328+
SiteIndexSettings settings = new SiteIndexSettings(true, 1);
329329
settings.buildRepositorySettings("agr-es-backup-" + repoName);
330330

331331
PutRepositoryRequest request = new PutRepositoryRequest();

agr_java_core/src/main/java/org/alliancegenome/neo4j/repository/DataExtractorRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public Result getAllGenes() {
1515
query += " OPTIONAL MATCH p2=(g:Gene)-[:ANNOTATED_TO]-(so:SOTerm)";
1616
query += " OPTIONAL MATCH p3=(g:Gene)-[:ALSO_KNOWN_AS]-(syn:Synonym)";
1717
query += " OPTIONAL MATCH p4=(g:Gene)-[:CROSS_REFERENCE]-(cr:CrossReference)";
18-
query += " RETURN g.primaryKey, g.modLocalId, collect(distinct replace(syn.name, ',', '')) as synonyms, collect(distinct cr.name) as crossrefs, g.name, g.symbol, g.geneSynopsis, g.automatedGeneSynopsis, s.primaryKey, gl.chromosome, gl.start, gl.end, gl.strand, so.name";
19-
//query += " RETURN g.primaryKey, g.modLocalId, collect(distinct replace(syn.name, ',', '')) as synonyms, collect(distinct cr.name) as crossrefs, g.name, g.symbol, replace(g.geneSynopsis, '\n', ''), replace(g.automatedGeneSynopsis, '\n', ''), s.primaryKey, gl.chromosome, gl.start, gl.end, gl.strand, so.name";
18+
query += " RETURN g.primaryKey, g.modLocalId, collect(distinct replace(syn.name, ',', '')) as synonyms, collect(distinct cr.name) as crossrefs, g.name, g.symbol, g.geneSynopsis, g.automatedGeneSynopsis, s.primaryKey, gl.chromosome, gl.start, gl.end, gl.strand, so.name";
19+
//query += " RETURN g.primaryKey, g.modLocalId, collect(distinct replace(syn.name, ',', '')) as synonyms, collect(distinct cr.name) as crossrefs, g.name, g.symbol, replace(g.geneSynopsis, '\n', ''), replace(g.automatedGeneSynopsis, '\n', ''), s.primaryKey, gl.chromosome, gl.start, gl.end, gl.strand, so.name";
2020

2121
return queryForResult(query);
2222

0 commit comments

Comments
 (0)