| The recommendations here are under development and may change before implementation. |
Overview
The intent of the REPLICA READ operation is to allow a client to perform retrieval operations only against one or more replicas. This would be an inconsistent read. While it could be used for nearly any purpose, the only common use case is expected to be in the event of failures when a known inconsistent read is okay.
Byte/ 0 | 1 | 2 | 3 |
/ | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+---------------+---------------+---------------+---------------+
0| 80 | 83 ('S') | 00 | 05 |
+---------------+---------------+---------------+---------------+
4| 04 | 00 | 00 | 00 |
+---------------+---------------+---------------+---------------+
8| 00 | 00 | 00 | 09 |
+---------------+---------------+---------------+---------------+
12| 00 | 00 | 00 | 00 |
+---------------+---------------+---------------+---------------+
16| 00 | 00 | 00 | 00 |
+---------------+---------------+---------------+---------------+
20| 00 | 00 | 00 | 00 |
+---------------+---------------+---------------+---------------+
24| 66 ('f') | 6f ('o') | 6f ('o') |
+---------------+---------------+---------------+
Header breakdown
tap connect command
Field (offset) (value)
Magic (0) : 0x80 (PROTOCOL_BINARY_REQ)
Opcode (1) : 0x83
Key length (2,3) : 0x0003 (3)
Extra length (0) : 0x00
Data type (5) : 0x00
vbucket (6,7) : 0x0000 (0)
Total body (8-11) : 0x00000003 (3)
Opaque (12-15): 0x00000000
CAS (16-23): 0x0000000000000000
Key (24-26): [foo]
Client API
Java
Note: not sure if we like this yet...
GetFuture resf; boolean isReplicaRead; try { resf = cbc.asyncGet("foo"); isReplicaRead = false; } catch (TimeoutException ex) { // uhoh, something went wrong, server isn't there! resf = cbc.asyncReplicaGet("foo"); isReplicaRead = true; } finally { // do something useful }
.NET
PHP
Ruby
res = nil
is_replica_read = false
begin
res = cbc.get("foo")
rescue Couchbase::Error::Timeout => ex
res = cbc.get("foo", :replica => true)
is_replica_read = true
ensure
# do something useful
end
Recommended Implementation
| These recommendations are preliminary, and have not been reviewed. |
The replica read command is intentionally simple. It would attempt to iterate through all of the replicas as designated by the configuration supplied by the cluster in order, trying to get the specified key.
Implementation Constraints
REPLICA READ is a binary protocol only operation. It could be implemented in ASCII, but that would require changes in moxi and additional clients.