22
22
import org .elasticsearch .common .collect .Maps ;
23
23
import org .elasticsearch .common .logging .ESLogger ;
24
24
import org .elasticsearch .common .logging .Loggers ;
25
+ import org .elasticsearch .common .unit .ByteSizeUnit ;
26
+ import org .elasticsearch .common .unit .ByteSizeValue ;
25
27
import org .elasticsearch .common .unit .TimeValue ;
26
28
import org .elasticsearch .common .xcontent .support .XContentMapValues ;
27
29
import org .elasticsearch .river .RiverSettings ;
@@ -42,6 +44,10 @@ public class MongoDBRiverDefinition {
42
44
// defaults
43
45
public final static String DEFAULT_DB_HOST = "localhost" ;
44
46
public final static int DEFAULT_DB_PORT = 27017 ;
47
+ public final static int DEFAULT_CONCURRENT_REQUESTS = 50 ;
48
+ public final static int DEFAULT_BULK_ACTIONS = 500 ;
49
+ public final static TimeValue DEFAULT_FLUSH_INTERVAL = TimeValue .timeValueMillis (10 );
50
+ public final static ByteSizeValue DEFAULT_BULK_SIZE = new ByteSizeValue (5 , ByteSizeUnit .MB );
45
51
46
52
// fields
47
53
public final static String DB_FIELD = "db" ;
@@ -79,6 +85,13 @@ public class MongoDBRiverDefinition {
79
85
public final static String THROTTLE_SIZE_FIELD = "throttle_size" ;
80
86
public final static String BULK_SIZE_FIELD = "bulk_size" ;
81
87
public final static String BULK_TIMEOUT_FIELD = "bulk_timeout" ;
88
+ public final static String CONCURRENT_BULK_REQUESTS_FIELD = "concurrent_bulk_requests" ;
89
+
90
+ public final static String BULK_FIELD = "bulk" ;
91
+ public final static String ACTIONS_FIELD = "actions" ;
92
+ public final static String SIZE_FIELD = "size" ;
93
+ public final static String CONCURRENT_REQUESTS_FIELD = "concurrent_requests" ;
94
+ public final static String FLUSH_INTERVAL_FIELD = "flush_interval" ;
82
95
83
96
// river
84
97
private final String riverName ;
@@ -117,9 +130,10 @@ public class MongoDBRiverDefinition {
117
130
// index
118
131
private final String indexName ;
119
132
private final String typeName ;
120
- private final int bulkSize ;
121
- private final TimeValue bulkTimeout ;
122
133
private final int throttleSize ;
134
+
135
+ // bulk
136
+ private final Bulk bulk ;
123
137
124
138
public static class Builder {
125
139
// river
@@ -159,10 +173,10 @@ public static class Builder {
159
173
// index
160
174
private String indexName ;
161
175
private String typeName ;
162
- private int bulkSize ;
163
- private TimeValue bulkTimeout ;
164
176
private int throttleSize ;
165
-
177
+
178
+ private Bulk bulk ;
179
+
166
180
public Builder mongoServers (List <ServerAddress > mongoServers ) {
167
181
this .mongoServers = mongoServers ;
168
182
return this ;
@@ -308,18 +322,13 @@ public Builder typeName(String typeName) {
308
322
return this ;
309
323
}
310
324
311
- public Builder bulkSize (int bulkSize ) {
312
- this .bulkSize = bulkSize ;
313
- return this ;
314
- }
315
-
316
- public Builder bulkTimeout (TimeValue bulkTimeout ) {
317
- this .bulkTimeout = bulkTimeout ;
325
+ public Builder throttleSize (int throttleSize ) {
326
+ this .throttleSize = throttleSize ;
318
327
return this ;
319
328
}
320
329
321
- public Builder throttleSize ( int throttleSize ) {
322
- this .throttleSize = throttleSize ;
330
+ public Builder bulk ( Bulk bulk ) {
331
+ this .bulk = bulk ;
323
332
return this ;
324
333
}
325
334
@@ -328,6 +337,73 @@ public MongoDBRiverDefinition build() {
328
337
}
329
338
}
330
339
340
+ static class Bulk {
341
+
342
+ private final int concurrentRequests ;
343
+ private final int bulkActions ;
344
+ private final ByteSizeValue bulkSize ;
345
+ private final TimeValue flushInterval ;
346
+
347
+ static class Builder {
348
+
349
+ private int concurrentRequests = DEFAULT_CONCURRENT_REQUESTS ;
350
+ private int bulkActions = DEFAULT_BULK_ACTIONS ;
351
+ private ByteSizeValue bulkSize = DEFAULT_BULK_SIZE ;
352
+ private TimeValue flushInterval = DEFAULT_FLUSH_INTERVAL ;
353
+
354
+ public Builder concurrentRequests (int concurrentRequests ) {
355
+ this .concurrentRequests = concurrentRequests ;
356
+ return this ;
357
+ }
358
+
359
+ public Builder bulkActions (int bulkActions ) {
360
+ this .bulkActions = bulkActions ;
361
+ return this ;
362
+ }
363
+
364
+ public Builder bulkSize (ByteSizeValue bulkSize ) {
365
+ this .bulkSize = bulkSize ;
366
+ return this ;
367
+ }
368
+
369
+ public Builder flushInterval (TimeValue flushInterval ) {
370
+ this .flushInterval = flushInterval ;
371
+ return this ;
372
+ }
373
+
374
+ /**
375
+ * Builds a new bulk processor.
376
+ */
377
+ public Bulk build () {
378
+ return new Bulk (this );
379
+ }
380
+ }
381
+
382
+ public Bulk (final Builder builder ) {
383
+ this .bulkActions = builder .bulkActions ;
384
+ this .bulkSize = builder .bulkSize ;
385
+ this .concurrentRequests = builder .concurrentRequests ;
386
+ this .flushInterval = builder .flushInterval ;
387
+ }
388
+
389
+ public int getConcurrentRequests () {
390
+ return concurrentRequests ;
391
+ }
392
+
393
+ public int getBulkActions () {
394
+ return bulkActions ;
395
+ }
396
+
397
+ public ByteSizeValue getBulkSize () {
398
+ return bulkSize ;
399
+ }
400
+
401
+ public TimeValue getFlushInterval () {
402
+ return flushInterval ;
403
+ }
404
+
405
+ }
406
+
331
407
@ SuppressWarnings ("unchecked" )
332
408
public synchronized static MongoDBRiverDefinition parseSettings (String riverName , String riverIndexName , RiverSettings settings ,
333
409
ScriptService scriptService ) {
@@ -563,21 +639,30 @@ public synchronized static MongoDBRiverDefinition parseSettings(String riverName
563
639
Map <String , Object > indexSettings = (Map <String , Object >) settings .settings ().get (INDEX_OBJECT );
564
640
builder .indexName (XContentMapValues .nodeStringValue (indexSettings .get (NAME_FIELD ), builder .mongoDb ));
565
641
builder .typeName (XContentMapValues .nodeStringValue (indexSettings .get (TYPE_FIELD ), builder .mongoDb ));
566
- int bulkSize = XContentMapValues .nodeIntegerValue (indexSettings .get (BULK_SIZE_FIELD ), 100 );
567
- builder .bulkSize (bulkSize );
568
- if (indexSettings .containsKey (BULK_TIMEOUT_FIELD )) {
569
- builder .bulkTimeout (TimeValue .parseTimeValue (
570
- XContentMapValues .nodeStringValue (indexSettings .get (BULK_TIMEOUT_FIELD ), "10ms" ), TimeValue .timeValueMillis (10 )));
642
+
643
+ Bulk .Builder bulkBuilder = new Bulk .Builder ();
644
+ if (indexSettings .containsKey (BULK_FIELD )) {
645
+ Map <String , Object > bulkSettings = (Map <String , Object >) indexSettings .get (BULK_FIELD );
646
+ int bulkActions = XContentMapValues .nodeIntegerValue (bulkSettings .get (ACTIONS_FIELD ), DEFAULT_BULK_ACTIONS );
647
+ bulkBuilder .bulkActions (bulkActions );
648
+ String size = XContentMapValues .nodeStringValue (bulkSettings .get (SIZE_FIELD ), DEFAULT_BULK_SIZE .toString ());
649
+ bulkBuilder .bulkSize (ByteSizeValue .parseBytesSizeValue (size ));
650
+ bulkBuilder .concurrentRequests (XContentMapValues .nodeIntegerValue (bulkSettings .get (CONCURRENT_REQUESTS_FIELD ), DEFAULT_CONCURRENT_REQUESTS ));
651
+ bulkBuilder .flushInterval (XContentMapValues .nodeTimeValue (bulkSettings .get (FLUSH_INTERVAL_FIELD ), DEFAULT_FLUSH_INTERVAL ));
652
+ builder .throttleSize (XContentMapValues .nodeIntegerValue (indexSettings .get (THROTTLE_SIZE_FIELD ), bulkActions * 5 ));
571
653
} else {
572
- builder .bulkTimeout (TimeValue .timeValueMillis (10 ));
654
+ int bulkActions = XContentMapValues .nodeIntegerValue (indexSettings .get (BULK_SIZE_FIELD ), DEFAULT_BULK_ACTIONS );
655
+ bulkBuilder .bulkActions (bulkActions );
656
+ bulkBuilder .bulkSize (DEFAULT_BULK_SIZE );
657
+ bulkBuilder .flushInterval (XContentMapValues .nodeTimeValue (indexSettings .get (BULK_TIMEOUT_FIELD ), DEFAULT_FLUSH_INTERVAL ));
658
+ bulkBuilder .concurrentRequests (XContentMapValues .nodeIntegerValue (indexSettings .get (CONCURRENT_BULK_REQUESTS_FIELD ), DEFAULT_CONCURRENT_REQUESTS ));
659
+ builder .throttleSize (XContentMapValues .nodeIntegerValue (indexSettings .get (THROTTLE_SIZE_FIELD ), bulkActions * 5 ));
573
660
}
574
- builder .throttleSize ( XContentMapValues . nodeIntegerValue ( indexSettings . get ( THROTTLE_SIZE_FIELD ), bulkSize * 5 ));
661
+ builder .bulk ( bulkBuilder . build ( ));
575
662
} else {
576
663
builder .indexName (builder .mongoDb );
577
664
builder .typeName (builder .mongoDb );
578
- builder .bulkSize (100 );
579
- builder .bulkTimeout (TimeValue .timeValueMillis (10 ));
580
- builder .throttleSize (builder .bulkSize * 5 );
665
+ builder .bulk (new Bulk .Builder ().build ());
581
666
}
582
667
return builder .build ();
583
668
}
@@ -694,10 +779,10 @@ private MongoDBRiverDefinition(final Builder builder) {
694
779
// index
695
780
this .indexName = builder .indexName ;
696
781
this .typeName = builder .typeName ;
697
- this .bulkSize = builder .bulkSize ;
698
- this .bulkTimeout = builder .bulkTimeout ;
699
782
this .throttleSize = builder .throttleSize ;
700
783
784
+ // bulk
785
+ this .bulk = builder .bulk ;
701
786
}
702
787
703
788
public List <ServerAddress > getMongoServers () {
@@ -816,14 +901,6 @@ public String getTypeName() {
816
901
return typeName ;
817
902
}
818
903
819
- public int getBulkSize () {
820
- return bulkSize ;
821
- }
822
-
823
- public TimeValue getBulkTimeout () {
824
- return bulkTimeout ;
825
- }
826
-
827
904
public int getThrottleSize () {
828
905
return throttleSize ;
829
906
}
@@ -832,4 +909,7 @@ public String getMongoOplogNamespace() {
832
909
return getMongoDb () + "." + getMongoCollection ();
833
910
}
834
911
912
+ public Bulk getBulk () {
913
+ return bulk ;
914
+ }
835
915
}
0 commit comments