@@ -42,6 +42,40 @@ note is that when the query returns there is **no guarantee** of a change. It is
42
42
possible that the timeout was reached, or that there was an idempotent write that
43
43
does not affect the result.
44
44
45
+ ## Consistency Modes
46
+
47
+ Most of the read query endpoints support multiple levels of consistency.
48
+ These are to provide a tuning knob that clients can be used to find a happy
49
+ medium that best matches their needs.
50
+
51
+ The three read modes are:
52
+
53
+ * default - If not specified, this mode is used. It is strongly consistent
54
+ in almost all cases. However, there is a small window in which an new
55
+ leader may be elected, and the old leader may service stale values. The
56
+ trade off is fast reads, but potentially stale values. This condition is
57
+ hard to trigger, and most clients should not need to worry about the stale read.
58
+ This only applies to reads, and a split-brain is not possible on writes.
59
+
60
+ * consistent - This mode is strongly consistent without caveats. It requires
61
+ that a leader verify with a quorum of peers that it is still leader. This
62
+ introduces an additional round-trip to all server nodes. The trade off is
63
+ always consistent reads, but increased latency due to an extra round trip.
64
+ Most clients should not use this unless they cannot tolerate a stale read.
65
+
66
+ * stale - This mode allows any server to service the read, regardless of if
67
+ it is the leader. This means reads can be arbitrarily stale, but are generally
68
+ within 50 milliseconds of the leader. The trade off is very fast and scalable
69
+ reads but values will be stale. This mode allows reads without a leader, meaning
70
+ a cluster that is unavailable will still be able to respond.
71
+
72
+ To switch these modes, either the "?stale" or "?consistent" query parameters
73
+ are provided. It is an error to provide both.
74
+
75
+ To support bounding how stale data is, there is an "X-Consul-LastContact"
76
+ which is the last time a server was contacted by the leader node in
77
+ milliseconds. The "X-Consul-KnownLeader" also indicates if there is a known
78
+ leader. These can be used to gauage if a stale read should be used.
45
79
46
80
## KV
47
81
@@ -81,7 +115,8 @@ that modified this key. This index corresponds to the `X-Consul-Index`
81
115
header value that is returned. A blocking query can be used to wait for
82
116
a value to change. If "?recurse" is used, the ` X-Consul-Index ` corresponds
83
117
to the latest ` ModifyIndex ` and so a blocking query waits until any of the
84
- listed keys are updated.
118
+ listed keys are updated. The multiple consistency modes can be used for
119
+ ` GET ` requests as well.
85
120
86
121
The ` Key ` is simply the full path of the entry. ` Flags ` are an opaque
87
122
unsigned integer that can be attached to each entry. The use of this is
@@ -347,7 +382,8 @@ The following endpoints are supported:
347
382
* /v1/catalog/service/\< service\> : Lists the nodes in a given service
348
383
* /v1/catalog/node/\< node\> : Lists the services provided by a node
349
384
350
- The last 4 endpoints of the catalog support blocking queries.
385
+ The last 4 endpoints of the catalog support blocking queries and
386
+ consistency modes.
351
387
352
388
### /v1/catalog/register
353
389
@@ -473,7 +509,7 @@ It returns a JSON body like this:
473
509
}
474
510
]
475
511
476
- This endpoint supports blocking queries.
512
+ This endpoint supports blocking queries and all consistency modes .
477
513
478
514
### /v1/catalog/services
479
515
@@ -492,7 +528,7 @@ It returns a JSON body like this:
492
528
The main object keys are the service names, while the array
493
529
provides all the known tags for a given service.
494
530
495
- This endpoint supports blocking queries.
531
+ This endpoint supports blocking queries and all consistency modes .
496
532
497
533
### /v1/catalog/service/\< service\>
498
534
@@ -517,7 +553,7 @@ It returns a JSON body like this:
517
553
}
518
554
]
519
555
520
- This endpoint supports blocking queries.
556
+ This endpoint supports blocking queries and all consistency modes .
521
557
522
558
### /v1/catalog/node/\< node\>
523
559
@@ -549,7 +585,7 @@ It returns a JSON body like this:
549
585
}
550
586
}
551
587
552
- This endpoint supports blocking queries.
588
+ This endpoint supports blocking queries and all consistency modes .
553
589
554
590
## Health
555
591
@@ -564,7 +600,7 @@ The following endpoints are supported:
564
600
* /v1/health/service/\< service\> : Returns the nodes and health info of a service
565
601
* /v1/health/state/\< state\> : Returns the checks in a given state
566
602
567
- All of the health endpoints supports blocking queries.
603
+ All of the health endpoints supports blocking queries and all consistency modes .
568
604
569
605
### /v1/health/node/\< node\>
570
606
@@ -603,7 +639,7 @@ joins the Consul cluster, it is part of a distributed failure detection
603
639
provided by Serf. If a node fails, it is detected and the status is automatically
604
640
changed to "critical".
605
641
606
- This endpoint supports blocking queries.
642
+ This endpoint supports blocking queries and all consistency modes .
607
643
608
644
### /v1/health/checks/\< service\>
609
645
@@ -627,7 +663,7 @@ It returns a JSON body like this:
627
663
}
628
664
]
629
665
630
- This endpoint supports blocking queries.
666
+ This endpoint supports blocking queries and all consistency modes .
631
667
632
668
### /v1/health/service/\< service\>
633
669
@@ -684,7 +720,7 @@ It returns a JSON body like this:
684
720
}
685
721
]
686
722
687
- This endpoint supports blocking queries.
723
+ This endpoint supports blocking queries and all consistency modes .
688
724
689
725
### /v1/health/state/\< state\>
690
726
@@ -718,7 +754,7 @@ It returns a JSON body like this:
718
754
}
719
755
]
720
756
721
- This endpoint supports blocking queries.
757
+ This endpoint supports blocking queries and all consistency modes .
722
758
723
759
## Status
724
760
0 commit comments