mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-30 02:13:33 -04:00
Version types EXTERNAL
& EXTERNAL_GTE
test for version equality in read operation & disallow them in the Update API
Separate version check logic for reads and writes for all version types, which allows different behavior in these cases. Change `VersionType.EXTERNAL` & `VersionType.EXTERNAL_GTE` to behave the same as `VersionType.INTERNAL` for read operations. The previous behavior was fit for writes but is useless in reads. This commit also makes the usage of `EXTERNAL` & `EXTERNAL_GTE` in the update api raise a validation error as it make cause data to be lost. Closes #5663 , Closes #5661, Closes #5929
This commit is contained in:
parent
080c4ade25
commit
051beb51a3
22 changed files with 458 additions and 221 deletions
|
@ -7,85 +7,85 @@
|
|||
"paths": ["/{index}/{type}/{id}/_update"],
|
||||
"parts": {
|
||||
"id": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"description" : "Document ID"
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Document ID"
|
||||
},
|
||||
"index": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"description" : "The name of the index"
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The name of the index"
|
||||
},
|
||||
"type": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"description" : "The type of the document"
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The type of the document"
|
||||
}
|
||||
},
|
||||
"params": {
|
||||
"consistency": {
|
||||
"type" : "enum",
|
||||
"options" : ["one", "quorum", "all"],
|
||||
"description" : "Explicit write consistency setting for the operation"
|
||||
"type": "enum",
|
||||
"options": ["one", "quorum", "all"],
|
||||
"description": "Explicit write consistency setting for the operation"
|
||||
},
|
||||
"fields": {
|
||||
"type": "list",
|
||||
"description" : "A comma-separated list of fields to return in the response"
|
||||
"description": "A comma-separated list of fields to return in the response"
|
||||
},
|
||||
"lang": {
|
||||
"type" : "string",
|
||||
"description" : "The script language (default: mvel)"
|
||||
"type": "string",
|
||||
"description": "The script language (default: mvel)"
|
||||
},
|
||||
"parent": {
|
||||
"type" : "string",
|
||||
"description" : "ID of the parent document"
|
||||
"type": "string",
|
||||
"description": "ID of the parent document"
|
||||
},
|
||||
"refresh": {
|
||||
"type" : "boolean",
|
||||
"description" : "Refresh the index after performing the operation"
|
||||
"type": "boolean",
|
||||
"description": "Refresh the index after performing the operation"
|
||||
},
|
||||
"replication": {
|
||||
"type" : "enum",
|
||||
"options" : ["sync","async"],
|
||||
"default" : "sync",
|
||||
"description" : "Specific replication type"
|
||||
"type": "enum",
|
||||
"options": ["sync", "async"],
|
||||
"default": "sync",
|
||||
"description": "Specific replication type"
|
||||
},
|
||||
"retry_on_conflict": {
|
||||
"type" : "number",
|
||||
"description" : "Specify how many times should the operation be retried when a conflict occurs (default: 0)"
|
||||
"type": "number",
|
||||
"description": "Specify how many times should the operation be retried when a conflict occurs (default: 0)"
|
||||
},
|
||||
"routing": {
|
||||
"type" : "string",
|
||||
"description" : "Specific routing value"
|
||||
"type": "string",
|
||||
"description": "Specific routing value"
|
||||
},
|
||||
"script": {
|
||||
"description" : "The URL-encoded script definition (instead of using request body)"
|
||||
"description": "The URL-encoded script definition (instead of using request body)"
|
||||
},
|
||||
"timeout": {
|
||||
"type" : "time",
|
||||
"description" : "Explicit operation timeout"
|
||||
"type": "time",
|
||||
"description": "Explicit operation timeout"
|
||||
},
|
||||
"timestamp": {
|
||||
"type" : "time",
|
||||
"description" : "Explicit timestamp for the document"
|
||||
"type": "time",
|
||||
"description": "Explicit timestamp for the document"
|
||||
},
|
||||
"ttl": {
|
||||
"type" : "duration",
|
||||
"description" : "Expiration time for the document"
|
||||
"type": "duration",
|
||||
"description": "Expiration time for the document"
|
||||
},
|
||||
"version" : {
|
||||
"type" : "number",
|
||||
"description" : "Explicit version number for concurrency control"
|
||||
"version": {
|
||||
"type": "number",
|
||||
"description": "Explicit version number for concurrency control"
|
||||
},
|
||||
"version_type": {
|
||||
"type" : "enum",
|
||||
"options" : ["internal", "external", "external_gte", "force"],
|
||||
"description" : "Specific version type"
|
||||
"type": "enum",
|
||||
"options": ["internal", "force"],
|
||||
"description": "Specific version type"
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": {
|
||||
"description" : "The request definition using either `script` or partial `doc`"
|
||||
"description": "The request definition using either `script` or partial `doc`"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
115
rest-api-spec/test/get/90_versions.yaml
Normal file
115
rest-api-spec/test/get/90_versions.yaml
Normal file
|
@ -0,0 +1,115 @@
|
|||
---
|
||||
"Versions":
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
body: { foo: bar }
|
||||
- match: { _version: 1}
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
body: { foo: bar }
|
||||
- match: { _version: 2}
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
- match: { _id: "1" }
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 1
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
version_type: external
|
||||
- match: { _id: "1" }
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 10
|
||||
version_type: external
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 1
|
||||
version_type: external
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
version_type: external_gte
|
||||
- match: { _id: "1" }
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 10
|
||||
version_type: external_gte
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 1
|
||||
version_type: external_gte
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
version_type: force
|
||||
- match: { _id: "1" }
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 10
|
||||
version_type: force
|
||||
- match: { _id: "1" }
|
||||
|
||||
- do:
|
||||
get:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 1
|
||||
version_type: force
|
||||
- match: { _id: "1" }
|
|
@ -12,29 +12,8 @@
|
|||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- do:
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
body:
|
||||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- match: { _version: 1}
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
body:
|
||||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- do:
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
|
@ -43,5 +22,3 @@
|
|||
body:
|
||||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- match: { _version: 2}
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
---
|
||||
"External version":
|
||||
"Not supported versions":
|
||||
|
||||
- do:
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 2
|
||||
version_type: external
|
||||
body:
|
||||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- match: { _version: 2 }
|
||||
|
||||
- do:
|
||||
catch: conflict
|
||||
catch: /Validation/
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
|
@ -27,14 +14,14 @@
|
|||
upsert: { foo: bar }
|
||||
|
||||
- do:
|
||||
catch: /Validation/
|
||||
update:
|
||||
index: test_1
|
||||
type: test
|
||||
id: 1
|
||||
version: 3
|
||||
version_type: external
|
||||
version: 2
|
||||
version_type: external_gte
|
||||
body:
|
||||
doc: { foo: baz }
|
||||
upsert: { foo: bar }
|
||||
|
||||
- match: { _version: 3 }
|
Loading…
Add table
Add a link
Reference in a new issue