Guest User

Untitled

a guest
May 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. SYNOPSIS
  2. Consul Key/Value Storage Notes
  3.  
  4.  
  5. DESCRIPTION
  6. Structure and function of consul key-value storage. Easier to find and slightly less verbose
  7. than the resources on the Consul documentation and sources
  8.  
  9.  
  10. WIRE FORMAT
  11. Annotated json encoding (raw format differs)
  12.  
  13. ```
  14. [
  15. {
  16. // Key is the key
  17. "Key": "some/path/to/somewhere",
  18.  
  19. // Value is the key's value
  20. "Value": "dGVzdA==",
  21.  
  22. // CreateIndex is a number that represents key creation
  23. "CreateIndex": 100,
  24.  
  25. // ModifyIndex counts upward from CreateIndex every time key is modified
  26. "ModifyIndex": 200,
  27.  
  28. // LockIndex counts the total n.o. times the key was acquired by a session
  29. "LockIndex": 200,
  30.  
  31. // Flags are user-defined uint64 bit vectors
  32. "Flags": 0,
  33.  
  34. // Session is a unique bitstring that identifies the resource currently holding
  35. // the lock on this key
  36. "Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
  37. }
  38. ]
  39. ```
  40.  
  41. OPERATIONS
  42.  
  43. 1.) Create & Update
  44. - PUT
  45. - Non-blocking
  46. - No consistency guarantees
  47.  
  48. // This is not a real go struct; they're actually URL-encoded query parameters
  49. type Param struct{
  50. // key is the path to the key, which looks like a file-system path on UNIX
  51. // without the leading '/'. This value can be cleaned and operated on from
  52. // Go's "path" package
  53. key string
  54.  
  55. // Dc (datacenter) is where the key is updated. Key-value stores aren't
  56. // replicated across datacenters.
  57. dc string // datacenter (optional)
  58.  
  59. // Flags are user-defined flags; nothing special
  60. flags uint64
  61.  
  62. // cas (Compare and Set)
  63. // If cas is zero, consul won't update an existing key
  64. // Otherwise, cas only updates the key if cas == ModifiedIndex
  65. // at the time of the request
  66. cas uint64
  67.  
  68. // Acquire carries a session ID, a random bitstring generated by
  69. // consul. If set, consul will update the value if the key doesn't
  70. // exist, the key isn't locked, or the key is locked by the session
  71. // represented by the acquire bitstring. (likewise, consul will create
  72. // and acquire a key-value pair that doesn't exist yet)
  73. //
  74. // Acquire uses the locking "honor system". Writers that
  75. // set acquire respect the locking semantics, but other writers do not
  76. // meaning if you set it for one writer you have to set it for all of them
  77. // (unless you want them writing over your value for a specific reason)
  78. //
  79. // A counter in the key-value pair, known as LockIndex, is incremented
  80. // every time the lock is acquired by a session.
  81. acquire string
  82. }
  83.  
  84. 2.) Read
  85. - GET
  86. - Blocking
  87. - Supports consistency
  88.  
  89. type Param struct{
  90. key string
  91. dc string
  92.  
  93. // Recurse reads a tree of keys by prefix. What this actually does depends
  94. // on the value of 'keys', see below for 'keys'
  95. recurse bool
  96.  
  97. // Keys, if true, tells consul to return a list of keys matching a prefix but
  98. // not those keys' values. If false, a recursive read returns the values too.
  99. keys bool
  100.  
  101. // Raw tells consul to return the key-value's raw data instead of encoding
  102. // it in a web-safe transport format "application/json". Metadata is not
  103. // included if this is set
  104. raw bool
  105.  
  106. // Separator is the character to use as a seperator. Changing this is probably
  107. // not a good idea
  108. seperator string
  109. }
  110.  
  111. 3.) Delete
  112. - DELETE
  113. - Non-blocking
  114. - No consistency guarantees
  115.  
  116. type Param struct{
  117. key string
  118.  
  119. // Recurse deletes a tree of keys by prefix, it assumes that key is a prefix
  120. recurse bool
  121.  
  122. // cas has the same semantics as in Create/Update.
  123. cas uint64
  124. }
Add Comment
Please, Sign In to add comment