Skip to content

Commit 90cb917

Browse files
dkouba-atymkr-t
andauthored
Prevent slow-to-start containers from trying to run in the same slot (#114)
* Reserve slot for container once identified. Prevents race condition where containers start in the same slot if slow to start. --------- Signed-off-by: Dan Kouba <dan@atym.io> Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Co-authored-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent 533f2f5 commit 90cb917

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/ocre/components/container_supervisor/cs_sm_impl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ ocre_container_status_t CS_create_container(ocre_container_t *container)
354354
}
355355

356356
if (container->container_runtime_status != CONTAINER_STATUS_UNKNOWN &&
357-
container->container_runtime_status != CONTAINER_STATUS_DESTROYED) {
357+
container->container_runtime_status != CONTAINER_STATUS_DESTROYED &&
358+
container->container_runtime_status != CONTAINER_STATUS_RESERVED) {
358359
LOG_ERR("Cannot create container again container with ID: %d, already exists", curr_container_ID);
359360
return CONTAINER_STATUS_ERROR;
360361
}

src/ocre/ocre_container_runtime/ocre_container_runtime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ocre_container_status_t ocre_container_runtime_create_container(ocre_cs_ctx *ctx
5454
(ctx->containers[i].container_runtime_status == CONTAINER_STATUS_DESTROYED)) {
5555
*container_id = i;
5656
ctx->containers[i].container_ID = i;
57+
ctx->containers[i].container_runtime_status = CONTAINER_STATUS_RESERVED;
5758
validity_flag = true;
5859
break;
5960
}

src/ocre/ocre_container_runtime/ocre_container_runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef enum {
5656
*/
5757
typedef enum {
5858
CONTAINER_STATUS_UNKNOWN, ///< Status is unknown.
59+
CONTAINER_STATUS_RESERVED, ///< Container slot has been reserved.
5960
CONTAINER_STATUS_CREATED, ///< Container has been created.
6061
CONTAINER_STATUS_RUNNING, ///< Container is currently running.
6162
CONTAINER_STATUS_STOPPED, ///< Container has been stopped.

0 commit comments

Comments
 (0)