1176: fix race condition in  document addition r=Kerollmops a=MarinPostma

As described in #1160, there was a race condition when updating settings and adding documents simultaneously. This was due to the schema being updated and document addition being processed in two different transactions. This PR moves the schema update logic for the primary key in the same transaction as the document addition, while maintaining the input checks for the validity of the primary key in the http route, in order not to break the error reporting for the document addition route.

close #1160.

Co-authored-by: mpostma <postma.marin@protonmail.com>
Co-authored-by: marin <postma.marin@protonmail.com>
This commit is contained in:
bors[bot]
2021-02-02 09:26:32 +00:00
committed by GitHub
5 changed files with 98 additions and 63 deletions

View File

@ -94,13 +94,21 @@ async fn return_update_status_of_pushed_documents() {
];
let mut update_ids = Vec::new();
let mut bodies = bodies.into_iter();
let url = "/indexes/test/documents?primaryKey=title";
let (response, status_code) = server.post_request(&url, bodies.next().unwrap()).await;
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
update_ids.push(update_id);
server.wait_update_id(update_id).await;
let url = "/indexes/test/documents";
for body in bodies {
let (response, status_code) = server.post_request(&url, body).await;
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
update_ids.push(update_id);
let (response, status_code) = server.post_request(&url, body).await;
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
update_ids.push(update_id);
}
// 2. Fetch the status of index.
@ -173,7 +181,7 @@ async fn should_return_existing_update() {
let (response, status_code) = server.create_index(body).await;
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
let body = json!([{
"title": "Test",
"comment": "comment test"