8
8
9
9
package org .elasticsearch .cluster .routing ;
10
10
11
+ import org .elasticsearch .TransportVersions ;
11
12
import org .elasticsearch .cluster .Diff ;
12
13
import org .elasticsearch .cluster .Diffable ;
13
14
import org .elasticsearch .cluster .DiffableUtils ;
45
46
*/
46
47
public class RoutingTable implements Iterable <IndexRoutingTable >, Diffable <RoutingTable > {
47
48
48
- public static final RoutingTable EMPTY_ROUTING_TABLE = new RoutingTable (0 , ImmutableOpenMap .of ());
49
-
50
- private final long version ;
49
+ public static final RoutingTable EMPTY_ROUTING_TABLE = new RoutingTable (ImmutableOpenMap .of ());
51
50
52
51
// index to IndexRoutingTable map
53
52
private final ImmutableOpenMap <String , IndexRoutingTable > indicesRouting ;
54
53
55
- private RoutingTable (long version , ImmutableOpenMap <String , IndexRoutingTable > indicesRouting ) {
56
- this .version = version ;
54
+ private RoutingTable (ImmutableOpenMap <String , IndexRoutingTable > indicesRouting ) {
57
55
this .indicesRouting = indicesRouting ;
58
56
}
59
57
60
- public RoutingTable withIncrementedVersion () {
61
- return new RoutingTable (version + 1 , indicesRouting );
62
- }
63
-
64
58
/**
65
59
* Get's the {@link IndexShardRoutingTable} for the given shard id from the given {@link IndexRoutingTable}
66
60
* or throws a {@link ShardNotFoundException} if no shard by the given id is found in the IndexRoutingTable.
@@ -77,15 +71,6 @@ public static IndexShardRoutingTable shardRoutingTable(IndexRoutingTable indexRo
77
71
return indexShard ;
78
72
}
79
73
80
- /**
81
- * Returns the version of the {@link RoutingTable}.
82
- *
83
- * @return version of the {@link RoutingTable}
84
- */
85
- public long version () {
86
- return this .version ;
87
- }
88
-
89
74
@ Override
90
75
public Iterator <IndexRoutingTable > iterator () {
91
76
return indicesRouting .values ().iterator ();
@@ -331,7 +316,9 @@ public static Diff<RoutingTable> readDiffFrom(StreamInput in) throws IOException
331
316
332
317
public static RoutingTable readFrom (StreamInput in ) throws IOException {
333
318
Builder builder = new Builder ();
334
- builder .version = in .readLong ();
319
+ if (in .getTransportVersion ().before (TransportVersions .ROUTING_TABLE_VERSION_REMOVED )) {
320
+ in .readLong (); // previously 'version', unused in all applicable versions so any number will do
321
+ }
335
322
int size = in .readVInt ();
336
323
for (int i = 0 ; i < size ; i ++) {
337
324
IndexRoutingTable index = IndexRoutingTable .readFrom (in );
@@ -343,46 +330,49 @@ public static RoutingTable readFrom(StreamInput in) throws IOException {
343
330
344
331
@ Override
345
332
public void writeTo (StreamOutput out ) throws IOException {
346
- out .writeLong (version );
333
+ if (out .getTransportVersion ().before (TransportVersions .ROUTING_TABLE_VERSION_REMOVED )) {
334
+ out .writeLong (0 ); // previously 'version', unused in all applicable versions so any number will do
335
+ }
347
336
out .writeCollection (indicesRouting .values ());
348
337
}
349
338
350
339
private static class RoutingTableDiff implements Diff <RoutingTable > {
351
340
352
- private final long version ;
353
-
354
341
private final Diff <ImmutableOpenMap <String , IndexRoutingTable >> indicesRouting ;
355
342
356
343
RoutingTableDiff (RoutingTable before , RoutingTable after ) {
357
- version = after .version ;
358
344
indicesRouting = DiffableUtils .diff (before .indicesRouting , after .indicesRouting , DiffableUtils .getStringKeySerializer ());
359
345
}
360
346
361
347
private static final DiffableUtils .DiffableValueReader <String , IndexRoutingTable > DIFF_VALUE_READER =
362
348
new DiffableUtils .DiffableValueReader <>(IndexRoutingTable ::readFrom , IndexRoutingTable ::readDiffFrom );
363
349
364
350
RoutingTableDiff (StreamInput in ) throws IOException {
365
- version = in .readLong ();
351
+ if (in .getTransportVersion ().before (TransportVersions .ROUTING_TABLE_VERSION_REMOVED )) {
352
+ in .readLong (); // previously 'version', unused in all applicable versions so any number will do
353
+ }
366
354
indicesRouting = DiffableUtils .readImmutableOpenMapDiff (in , DiffableUtils .getStringKeySerializer (), DIFF_VALUE_READER );
367
355
}
368
356
369
357
@ Override
370
358
public RoutingTable apply (RoutingTable part ) {
371
359
final ImmutableOpenMap <String , IndexRoutingTable > updatedRouting = indicesRouting .apply (part .indicesRouting );
372
- if (part . version == version && updatedRouting == part .indicesRouting ) {
360
+ if (updatedRouting == part .indicesRouting ) {
373
361
return part ;
374
362
}
375
- return new RoutingTable (version , updatedRouting );
363
+ return new RoutingTable (updatedRouting );
376
364
}
377
365
378
366
@ Override
379
367
public void writeTo (StreamOutput out ) throws IOException {
380
- out .writeLong (version );
368
+ if (out .getTransportVersion ().before (TransportVersions .ROUTING_TABLE_VERSION_REMOVED )) {
369
+ out .writeLong (0 ); // previously 'version', unused in all applicable versions so any number will do
370
+ }
381
371
indicesRouting .writeTo (out );
382
372
}
383
373
}
384
374
385
- public static RoutingTable of (long version , RoutingNodes routingNodes ) {
375
+ public static RoutingTable of (RoutingNodes routingNodes ) {
386
376
Map <String , IndexRoutingTable .Builder > indexRoutingTableBuilders = new HashMap <>();
387
377
for (RoutingNode routingNode : routingNodes ) {
388
378
for (ShardRouting shardRoutingEntry : routingNode ) {
@@ -404,7 +394,7 @@ public static RoutingTable of(long version, RoutingNodes routingNodes) {
404
394
IndexRoutingTable indexRoutingTable = indexBuilder .build ();
405
395
indicesRouting .put (indexRoutingTable .getIndex ().getName (), indexRoutingTable );
406
396
}
407
- return new RoutingTable (version , indicesRouting .build ());
397
+ return new RoutingTable (indicesRouting .build ());
408
398
}
409
399
410
400
public static Builder builder () {
@@ -429,7 +419,6 @@ public static Builder builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy,
429
419
public static class Builder {
430
420
431
421
private final ShardRoutingRoleStrategy shardRoutingRoleStrategy ;
432
- private long version ;
433
422
private ImmutableOpenMap .Builder <String , IndexRoutingTable > indicesRouting ;
434
423
435
424
public Builder () {
@@ -447,7 +436,6 @@ public Builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy) {
447
436
448
437
public Builder (ShardRoutingRoleStrategy shardRoutingRoleStrategy , RoutingTable routingTable ) {
449
438
this .shardRoutingRoleStrategy = shardRoutingRoleStrategy ;
450
- this .version = routingTable .version ;
451
439
this .indicesRouting = ImmutableOpenMap .builder (routingTable .indicesRouting );
452
440
}
453
441
@@ -591,16 +579,6 @@ public Builder remove(String index) {
591
579
return this ;
592
580
}
593
581
594
- public Builder version (long version ) {
595
- this .version = version ;
596
- return this ;
597
- }
598
-
599
- public Builder incrementVersion () {
600
- this .version ++;
601
- return this ;
602
- }
603
-
604
582
/**
605
583
* Builds the routing table. Note that once this is called the builder
606
584
* must be thrown away. If you need to build a new RoutingTable as a
@@ -610,15 +588,15 @@ public RoutingTable build() {
610
588
if (indicesRouting == null ) {
611
589
throw new IllegalStateException ("once build is called the builder cannot be reused" );
612
590
}
613
- RoutingTable table = new RoutingTable (version , indicesRouting .build ());
591
+ RoutingTable table = new RoutingTable (indicesRouting .build ());
614
592
indicesRouting = null ;
615
593
return table ;
616
594
}
617
595
}
618
596
619
597
@ Override
620
598
public String toString () {
621
- StringBuilder sb = new StringBuilder ("routing_table (version " ). append ( version ). append ( ") :\n " );
599
+ StringBuilder sb = new StringBuilder ("routing_table:\n " );
622
600
for (IndexRoutingTable entry : indicesRouting .values ()) {
623
601
sb .append (entry .prettyPrint ()).append ('\n' );
624
602
}
0 commit comments