forked from apache/solr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportTool.java.original
More file actions
738 lines (672 loc) · 24.3 KB
/
ExportTool.java.original
File metadata and controls
738 lines (672 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.cli;
import static org.apache.solr.common.params.CommonParams.FL;
import static org.apache.solr.common.params.CommonParams.JAVABIN;
import static org.apache.solr.common.params.CommonParams.JSON;
import static org.apache.solr.common.params.CommonParams.Q;
import static org.apache.solr.common.params.CommonParams.SORT;
import static org.apache.solr.common.util.JavaBinCodec.SOLRINPUTDOC;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.lucene.util.SuppressForbidden;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.StreamingResponseCallback;
import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.ClusterStateProvider;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.impl.StreamingJavaBinResponseParser;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CursorMarkParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.CollectionUtil;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.StrUtils;
import org.noggit.CharArr;
import org.noggit.JSONWriter;
/** Supports export command in the bin/solr script. */
public class ExportTool extends ToolBase {
private static final Option COLLECTION_NAME_OPTION =
Option.builder("c")
.longOpt("name")
.hasArg()
.argName("NAME")
.desc("Name of the collection.")
.build();
private static final Option OUTPUT_OPTION =
Option.builder()
.longOpt("output")
.hasArg()
.argName("PATH")
.desc(
"Path to output the exported data, and optionally the file name, defaults to 'collection-name'.")
.build();
private static final Option FORMAT_OPTION =
Option.builder()
.longOpt("format")
.hasArg()
.argName("FORMAT")
.desc("Output format for exported docs (json, jsonl or javabin), defaulting to json.")
.build();
private static final Option COMPRESS_OPTION =
Option.builder().longOpt("compress").desc("Compress the output. Defaults to false.").build();
private static final Option LIMIT_OPTION =
Option.builder()
.longOpt("limit")
.hasArg()
.argName("#")
.desc("Maximum number of docs to download. Default is 100, use -1 for all docs.")
.build();
private static final Option QUERY_OPTION =
Option.builder()
.longOpt("query")
.hasArg()
.argName("QUERY")
.desc("A custom query, default is '*:*'.")
.build();
private static final Option FIELDS_OPTION =
Option.builder()
.longOpt("fields")
.hasArg()
.argName("FIELDA,FIELDB")
.desc("Comma separated list of fields to export. By default all fields are fetched.")
.build();
public ExportTool(ToolRuntime runtime) {
super(runtime);
}
@Override
public String getName() {
return "export";
}
@Override
public Options getOptions() {
return super.getOptions()
.addOption(COLLECTION_NAME_OPTION)
.addOption(OUTPUT_OPTION)
.addOption(FORMAT_OPTION)
.addOption(COMPRESS_OPTION)
.addOption(LIMIT_OPTION)
.addOption(QUERY_OPTION)
.addOption(FIELDS_OPTION)
.addOption(CommonCLIOptions.SOLR_URL_OPTION)
.addOption(CommonCLIOptions.CREDENTIALS_OPTION);
}
public abstract static class Info {
final ToolRuntime runtime;
String baseurl;
String credentials;
String format;
boolean compress;
String query;
String coll;
String out;
String fields;
long limit = 100;
AtomicLong docsWritten = new AtomicLong(0);
int bufferSize = 1024 * 1024;
String uniqueKey;
CloudSolrClient solrClient;
DocsSink sink;
public Info(ToolRuntime runtime, String url, String credentials) {
this.runtime = runtime;
setUrl(url);
setCredentials(credentials);
setOutFormat(null, "jsonl", false);
}
public void setUrl(String url) {
int idx = url.lastIndexOf('/');
baseurl = url.substring(0, idx);
coll = url.substring(idx + 1);
query = "*:*";
}
public void setCredentials(String credentials) {
this.credentials = credentials;
}
public void setLimit(String maxDocsStr) {
limit = Long.parseLong(maxDocsStr);
if (limit == -1) limit = Long.MAX_VALUE;
}
public void setOutFormat(String out, String format, boolean compress) {
this.compress = compress;
this.format = format;
this.out = out;
if (this.format == null) {
this.format = JSON;
}
if (!formats.contains(this.format)) {
throw new IllegalArgumentException("format must be one of: " + formats);
}
if (this.out == null) {
this.out = coll;
} else if (Files.isDirectory(Path.of(this.out))) {
this.out = this.out + "/" + coll;
}
this.out = this.out + '.' + this.format;
if (compress) {
this.out = this.out + ".gz";
}
}
DocsSink getSink() {
DocsSink docSink = null;
switch (format) {
case JAVABIN:
docSink = new JavabinSink(this);
break;
case JSON:
docSink = new JsonSink(this);
break;
case "jsonl":
docSink = new JsonWithLinesSink(this);
break;
}
return docSink;
}
abstract void exportDocs() throws Exception;
void fetchUniqueKey() throws SolrServerException, IOException {
Http2SolrClient.Builder builder =
new Http2SolrClient.Builder().withOptionalBasicAuthCredentials(credentials);
solrClient =
new CloudHttp2SolrClient.Builder(Collections.singletonList(baseurl))
.withInternalClientBuilder(builder)
.build();
NamedList<Object> response =
solrClient.request(
new GenericSolrRequest(
SolrRequest.METHOD.GET,
"/schema/uniquekey",
SolrParams.of("collection", coll))
.setRequiresCollection(true));
uniqueKey = (String) response.get("uniqueKey");
}
public static StreamingResponseCallback getStreamer(Consumer<SolrDocument> sink) {
return new StreamingResponseCallback() {
@Override
public void streamSolrDocument(SolrDocument doc) {
try {
sink.accept(doc);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void streamDocListInfo(long numFound, long start, Float maxScore) {}
};
}
}
static Set<String> formats = Set.of(JAVABIN, JSON, "jsonl");
@Override
public void runImpl(CommandLine cli) throws Exception {
String url = null;
if (cli.hasOption(CommonCLIOptions.SOLR_URL_OPTION)) {
if (!cli.hasOption(COLLECTION_NAME_OPTION)) {
throw new IllegalArgumentException(
"Must specify -c / --name parameter with --solr-url to post documents.");
}
url = CLIUtils.normalizeSolrUrl(cli) + "/solr/" + cli.getOptionValue(COLLECTION_NAME_OPTION);
} else {
// think about support --zk-host someday.
throw new IllegalArgumentException("Must specify --solr-url.");
}
String credentials = cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
Info info = new MultiThreadedRunner(runtime, url, credentials);
info.query = cli.getOptionValue(QUERY_OPTION, "*:*");
info.setOutFormat(
cli.getOptionValue(OUTPUT_OPTION),
cli.getOptionValue(FORMAT_OPTION),
cli.hasOption(COMPRESS_OPTION));
info.fields = cli.getOptionValue(FIELDS_OPTION);
info.setLimit(cli.getOptionValue(LIMIT_OPTION, "100"));
info.exportDocs();
}
abstract static class DocsSink {
Info info;
OutputStream fos;
abstract void start() throws IOException;
@SuppressForbidden(reason = "Command line tool prints out to console")
void accept(SolrDocument document) throws IOException {
long count = info.docsWritten.incrementAndGet();
if (count % 100000 == 0) {
System.out.println("\nDOCS: " + count);
}
}
void end() throws IOException {}
}
static class JsonWithLinesSink extends DocsSink {
private final CharArr charArr = new CharArr(1024 * 2);
JSONWriter jsonWriter = new JSONWriter(charArr, -1);
private Writer writer;
public JsonWithLinesSink(Info info) {
this.info = info;
}
@Override
public void start() throws IOException {
fos = new FileOutputStream(info.out);
if (info.compress) {
fos = new GZIPOutputStream(fos);
}
if (info.bufferSize > 0) {
fos = new BufferedOutputStream(fos, info.bufferSize);
}
writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
}
@Override
public void end() throws IOException {
writer.flush();
fos.flush();
fos.close();
}
@Override
public synchronized void accept(SolrDocument doc) throws IOException {
charArr.reset();
Map<String, Object> m = CollectionUtil.newLinkedHashMap(doc.size());
doc.forEach(
(s, field) -> {
if (s.equals("_version_") || s.equals("_roor_")) return;
if (field instanceof List) {
if (((List<?>) field).size() == 1) {
field = ((List<?>) field).get(0);
}
}
field = constructDateStr(field);
if (field instanceof List<?> list) {
if (hasdate(list)) {
ArrayList<Object> listCopy = new ArrayList<>(list.size());
for (Object o : list) listCopy.add(constructDateStr(o));
field = listCopy;
}
}
m.put(s, field);
});
jsonWriter.write(m);
writer.write(charArr.getArray(), charArr.getStart(), charArr.getEnd());
writer.append('\n');
super.accept(doc);
}
private boolean hasdate(List<?> list) {
boolean hasDate = false;
for (Object o : list) {
if (o instanceof Date) {
hasDate = true;
break;
}
}
return hasDate;
}
private Object constructDateStr(Object field) {
if (field instanceof Date) {
field =
DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(((Date) field).getTime()));
}
return field;
}
}
static class JsonSink extends DocsSink {
private final CharArr charArr = new CharArr(1024 * 2);
JSONWriter jsonWriter = new JSONWriter(charArr, -1);
private Writer writer;
private boolean firstDoc = true;
public JsonSink(Info info) {
this.info = info;
}
@Override
public void start() throws IOException {
fos = new FileOutputStream(info.out);
if (info.compress) {
fos = new GZIPOutputStream(fos);
}
if (info.bufferSize > 0) {
fos = new BufferedOutputStream(fos, info.bufferSize);
}
writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
writer.append('[');
}
@Override
public void end() throws IOException {
writer.append(']');
writer.flush();
fos.flush();
fos.close();
}
@Override
public synchronized void accept(SolrDocument doc) throws IOException {
charArr.reset();
Map<String, Object> m = CollectionUtil.newLinkedHashMap(doc.size());
doc.forEach(
(s, field) -> {
if (s.equals("_version_") || s.equals("_roor_")) return;
if (field instanceof List) {
if (((List<?>) field).size() == 1) {
field = ((List<?>) field).get(0);
}
}
field = constructDateStr(field);
if (field instanceof List<?> list) {
if (hasdate(list)) {
ArrayList<Object> listCopy = new ArrayList<>(list.size());
for (Object o : list) listCopy.add(constructDateStr(o));
field = listCopy;
}
}
m.put(s, field);
});
if (firstDoc) {
firstDoc = false;
} else {
writer.append(',');
}
jsonWriter.write(m);
writer.write(charArr.getArray(), charArr.getStart(), charArr.getEnd());
writer.append('\n');
super.accept(doc);
}
private boolean hasdate(List<?> list) {
boolean hasDate = false;
for (Object o : list) {
if (o instanceof Date) {
hasDate = true;
break;
}
}
return hasDate;
}
private Object constructDateStr(Object field) {
if (field instanceof Date) {
field =
DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(((Date) field).getTime()));
}
return field;
}
}
static class JavabinSink extends DocsSink {
JavaBinCodec codec;
public JavabinSink(Info info) {
this.info = info;
}
@Override
public void start() throws IOException {
fos = new FileOutputStream(info.out);
if (info.compress) {
fos = new GZIPOutputStream(fos);
}
if (info.bufferSize > 0) {
fos = new BufferedOutputStream(fos, info.bufferSize);
}
codec = new JavaBinCodec(fos, null);
codec.writeTag(JavaBinCodec.NAMED_LST, 2);
codec.writeStr("params");
codec.writeNamedList(new NamedList<>());
codec.writeStr("docs");
codec.writeTag(JavaBinCodec.ITERATOR);
}
@Override
public void end() throws IOException {
codec.writeTag(JavaBinCodec.END);
codec.close();
fos.flush();
fos.close();
}
private final BiConsumer<String, Object> bic =
new BiConsumer<>() {
@Override
public void accept(String s, Object o) {
try {
if (s.equals("_version_") || s.equals("_root_")) return;
codec.writeExternString(s);
codec.writeVal(o);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
@Override
public synchronized void accept(SolrDocument doc) throws IOException {
int sz = doc.size();
if (doc.containsKey("_version_")) sz--;
if (doc.containsKey("_root_")) sz--;
codec.writeTag(SOLRINPUTDOC, sz);
codec.writeFloat(1f); // document boost
doc.forEach(bic);
super.accept(doc);
}
}
static class MultiThreadedRunner extends Info {
ExecutorService producerThreadpool, consumerThreadpool;
ArrayBlockingQueue<SolrDocument> queue = new ArrayBlockingQueue<>(1000);
SolrDocument EOFDOC = new SolrDocument();
volatile boolean failed = false;
Map<String, CoreHandler> corehandlers = new HashMap<>();
private final long startTime;
@SuppressForbidden(reason = "Need to print out time")
public MultiThreadedRunner(ToolRuntime runtime, String url, String credentials) {
super(runtime, url, credentials);
startTime = System.currentTimeMillis();
}
@Override
@SuppressForbidden(reason = "Need to print out time")
void exportDocs() throws Exception {
sink = getSink();
fetchUniqueKey();
ClusterStateProvider stateProvider = solrClient.getClusterStateProvider();
DocCollection coll = stateProvider.getCollection(this.coll);
Map<String, Slice> m = coll.getSlicesMap();
producerThreadpool =
ExecutorUtil.newMDCAwareFixedThreadPool(
m.size(), new SolrNamedThreadFactory("solrcli-exporter-producers"));
consumerThreadpool =
ExecutorUtil.newMDCAwareFixedThreadPool(
1, new SolrNamedThreadFactory("solrcli-exporter-consumer"));
sink.start();
CountDownLatch consumerlatch = new CountDownLatch(1);
try {
addConsumer(consumerlatch);
addProducers(m);
runtime.println("Number of shards : " + corehandlers.size());
CountDownLatch producerLatch = new CountDownLatch(corehandlers.size());
corehandlers.forEach(
(s, coreHandler) ->
producerThreadpool.execute(
() -> {
try {
coreHandler.exportDocsFromCore();
} catch (Exception e) {
runtime.println("Error exporting docs from : " + s);
}
producerLatch.countDown();
}));
producerLatch.await();
queue.offer(EOFDOC, 10, TimeUnit.SECONDS);
consumerlatch.await();
} finally {
sink.end();
solrClient.close();
producerThreadpool.shutdownNow();
consumerThreadpool.shutdownNow();
if (failed) {
try {
Files.delete(Path.of(out));
} catch (IOException e) {
// ignore
}
}
System.out.println(
"\nTotal Docs exported: "
+ docsWritten.get()
+ ". Time elapsed: "
+ ((System.currentTimeMillis() - startTime) / 1000)
+ "seconds");
}
}
private void addProducers(Map<String, Slice> m) {
for (Map.Entry<String, Slice> entry : m.entrySet()) {
Slice slice = entry.getValue();
Replica replica = slice.getLeader();
if (replica == null)
replica = slice.getReplicas().iterator().next(); // get a random replica
CoreHandler coreHandler = new CoreHandler(replica);
corehandlers.put(replica.getCoreName(), coreHandler);
}
}
private void addConsumer(CountDownLatch consumerlatch) {
consumerThreadpool.execute(
() -> {
while (true) {
SolrDocument doc;
try {
doc = queue.poll(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
runtime.println("Consumer interrupted");
failed = true;
break;
}
if (doc == EOFDOC) break;
try {
if (docsWritten.get() >= limit) {
continue;
}
sink.accept(doc);
} catch (Exception e) {
runtime.println("Failed to write to file " + e.getMessage());
failed = true;
}
}
consumerlatch.countDown();
});
}
class CoreHandler {
final Replica replica;
long expectedDocs;
AtomicLong receivedDocs = new AtomicLong();
CoreHandler(Replica replica) {
this.replica = replica;
}
boolean exportDocsFromCore() throws IOException, SolrServerException {
// reference the replica's node URL, not the baseUrl in scope, which could be anywhere
try (SolrClient client = CLIUtils.getSolrClient(replica.getBaseUrl(), credentials)) {
expectedDocs = getDocCount(replica.getCoreName(), client, query);
QueryRequest request;
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(Q, query);
if (fields != null) params.add(FL, fields);
params.add(SORT, uniqueKey + " asc");
params.add(CommonParams.DISTRIB, "false");
params.add(CommonParams.ROWS, "1000");
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
Consumer<SolrDocument> wrapper =
doc -> {
try {
queue.offer(doc, 10, TimeUnit.SECONDS);
receivedDocs.incrementAndGet();
} catch (InterruptedException e) {
failed = true;
runtime.println("Failed to write docs from" + e.getMessage());
}
};
StreamingJavaBinResponseParser responseParser =
new StreamingJavaBinResponseParser(getStreamer(wrapper));
while (true) {
if (failed) return false;
if (docsWritten.get() > limit) return true;
params.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
request = new QueryRequest(params);
request.setResponseParser(responseParser);
try {
NamedList<Object> rsp = client.request(request, replica.getCoreName());
String nextCursorMark = (String) rsp.get(CursorMarkParams.CURSOR_MARK_NEXT);
if (nextCursorMark == null || Objects.equals(cursorMark, nextCursorMark)) {
runtime.println(
StrUtils.formatString(
"\nExport complete from shard {0}, core {1}, docs received: {2}",
replica.getShard(), replica.getCoreName(), receivedDocs.get()));
if (expectedDocs != receivedDocs.get()) {
runtime.println(
StrUtils.formatString(
"Could not download all docs from core {0}, docs expected: {1}, received: {2}",
replica.getCoreName(), expectedDocs, receivedDocs.get()));
return false;
}
return true;
}
cursorMark = nextCursorMark;
runtime.print(".");
} catch (SolrServerException e) {
runtime.println(
"Error reading from server "
+ replica.getBaseUrl()
+ "/"
+ replica.getCoreName());
failed = true;
return false;
}
}
}
}
}
}
static long getDocCount(String coreName, SolrClient client, String query)
throws SolrServerException, IOException {
SolrQuery q = new SolrQuery(query);
q.setRows(0);
q.add("distrib", "false");
final var request = new QueryRequest(q);
NamedList<Object> res = client.request(request, coreName);
SolrDocumentList sdl = (SolrDocumentList) res.get("response");
return sdl.getNumFound();
}
}