1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

Improve attr/index lifecycle with status stuck when deletion fails

This commit is contained in:
kodumbeats 2021-10-04 20:23:15 -04:00
parent 5cdc330cab
commit 2aa94e7897
4 changed files with 18 additions and 10 deletions

View file

@ -81,7 +81,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
'key' => $attributeId,
'collectionId' => $collectionId,
'type' => $type,
'status' => 'processing', // processing, available, failed, deleting
'status' => 'processing', // processing, available, failed, deleting, stuck
'size' => $size,
'required' => $required,
'signed' => $signed,
@ -1136,7 +1136,11 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId')
throw new Exception('Attribute not found', 404);
}
$attribute = $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting'));
// Only update status if removing available attribute
if ($attribute->getAttribute('status' === 'available')) {
$attribute = $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting'));
}
$dbForInternal->purgeDocument('collections', $collectionId);
$database
@ -1233,7 +1237,7 @@ App::post('/v1/database/collections/:collectionId/indexes')
$index = $dbForInternal->createDocument('indexes', new Document([
'$id' => $collectionId.'_'.$indexId,
'key' => $indexId,
'status' => 'processing', // processing, available, failed, deleting
'status' => 'processing', // processing, available, failed, deleting, stuck
'collectionId' => $collectionId,
'type' => $type,
'attributes' => $attributes,
@ -1388,7 +1392,11 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
throw new Exception('Index not found', 404);
}
$index = $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting'));
// Only update status if removing available index
if ($index->getAttribute('status') === 'available') {
$index = $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting'));
}
$dbForInternal->purgeDocument('collections', $collectionId);
$database

View file

@ -110,14 +110,14 @@ class DatabaseV1 extends Worker
$key = $attribute->getAttribute('key', '');
try {
if(!$dbForExternal->deleteAttribute($collectionId, $key)) {
if(!$dbForExternal->deleteAttribute($collectionId, $key) && $attribute->getAttribute('status') !== 'failed') {
throw new Exception('Failed to delete Attribute');
}
$dbForInternal->deleteDocument('attributes', $attribute->getId());
} catch (\Throwable $th) {
Console::error($th->getMessage());
$dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed'));
$dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck'));
}
$dbForInternal->purgeDocument('collections', $collectionId);
@ -167,14 +167,14 @@ class DatabaseV1 extends Worker
$key = $index->getAttribute('key');
try {
if(!$dbForExternal->deleteIndex($collectionId, $key)) {
if(!$dbForExternal->deleteIndex($collectionId, $key) && $index->getAttribute('status') !== 'failed') {
throw new Exception('Failed to delete Attribute');
}
$dbForInternal->deleteDocument('indexes', $index->getId());
} catch (\Throwable $th) {
Console::error($th->getMessage());
$dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed'));
$dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck'));
}
$dbForInternal->purgeDocument('collections', $collectionId);

View file

@ -24,7 +24,7 @@ class Attribute extends Model
])
->addRule('status', [
'type' => self::TYPE_STRING,
'description' => 'Attribute status. Possible values: `available`, `processing`, `deleting`, or `failed`',
'description' => 'Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed`',
'default' => '',
'example' => 'available',
])

View file

@ -24,7 +24,7 @@ class Index extends Model
])
->addRule('status', [
'type' => self::TYPE_STRING,
'description' => 'Index status. Possible values: `available`, `processing`, `deleting`, or `failed`',
'description' => 'Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed`',
'default' => '',
'example' => 'available',
])