From a20a8b5b73fa46e914fe7ad8aaf1064baf4d7d2d Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 20:45:04 +0000 Subject: [PATCH 1/6] [db] Add stateVersion to prebuilds to track status version --- .../gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts | 7 +++++++ components/gitpod-protocol/src/protocol.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts index 780147a36ffd27..0c9238aea56209 100644 --- a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts @@ -68,4 +68,11 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace { transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, }) error?: string; + + // stateVersion defines the last observed stateVersion from a WorkspaceStatus. See ws-manager-api/core.proto. + // stateVersion must only be set by controller/observer. + @Column({ + default: 0, + }) + stateVersion: number; } diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 7d81090cd934b1..78d95e1cf0ed85 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -634,6 +634,7 @@ export interface PrebuiltWorkspace { buildWorkspaceId: string; creationTime: string; state: PrebuiltWorkspaceState; + stateVersion: number; error?: string; snapshot?: string; } From c2972b9031d5bb09dcb4fbfa1a84bb70666c3685 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 20:46:32 +0000 Subject: [PATCH 2/6] fix --- .../gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts | 6 +++--- components/gitpod-protocol/src/protocol.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts index 0c9238aea56209..22f3c5c6bfc795 100644 --- a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts @@ -69,10 +69,10 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace { }) error?: string; - // stateVersion defines the last observed stateVersion from a WorkspaceStatus. See ws-manager-api/core.proto. - // stateVersion must only be set by controller/observer. + // statusVersion defines the last observed stateVersion from a WorkspaceStatus. See ws-manager-api/core.proto. + // statusVersion must only be set by controller/observer. @Column({ default: 0, }) - stateVersion: number; + statusVersion: number; } diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 78d95e1cf0ed85..161a3ad0f1077b 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -634,7 +634,7 @@ export interface PrebuiltWorkspace { buildWorkspaceId: string; creationTime: string; state: PrebuiltWorkspaceState; - stateVersion: number; + statusVersion: number; error?: string; snapshot?: string; } From 733d2b3ea48f785ad3abd9bc5805a006f4942018 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 21:20:39 +0000 Subject: [PATCH 3/6] fix tests --- components/gitpod-db/src/workspace-db.spec.db.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/gitpod-db/src/workspace-db.spec.db.ts b/components/gitpod-db/src/workspace-db.spec.db.ts index 68d571aa00479a..5cb2dec8d02e05 100644 --- a/components/gitpod-db/src/workspace-db.spec.db.ts +++ b/components/gitpod-db/src/workspace-db.spec.db.ts @@ -247,6 +247,7 @@ class WorkspaceDBSpec { cloneURL: "", commit: "", state: "available", + statusVersion: 0, }); if (usageDaysAgo !== undefined) { const now = new Date(); @@ -509,6 +510,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "queued", + statusVersion: 0, }), // now and aborted this.storePrebuiltWorkspace({ @@ -518,6 +520,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "aborted", + statusVersion: 0, }), // completed over a minute ago this.storePrebuiltWorkspace({ @@ -527,6 +530,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "available", + statusVersion: 0, }), ]); From 306c84b14a6db9f32f50a67c4d427e40cf740865 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 21:39:08 +0000 Subject: [PATCH 4/6] add migrations --- ...49107789640-PrebuildStatusVersionColumn.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts diff --git a/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts new file mode 100644 index 00000000000000..9f82d133fb9b92 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2022 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License-AGPL.txt in the project root for license information. + */ + +import { MigrationInterface, QueryRunner } from "typeorm"; +import { columnExists } from "./helper/helper"; + +export class PrebuildStatusVersionColumn1649107789640 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) { + await queryRunner.query( + `ALTER TABLE ${TABLE_NAME} ADD COLUMN \`${COLUMN_NAME}\` BIGINT(20) NOT NULL DEFAULT '0'`, + ); + } + } + + public async down(queryRunner: QueryRunner): Promise {} +} From e596ef7dfe27bb8feaf2a53b8b39bb797203c8c7 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 21:41:40 +0000 Subject: [PATCH 5/6] fix --- .../migration/1649107789640-PrebuildStatusVersionColumn.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts index 9f82d133fb9b92..dbfe445d2d8cb1 100644 --- a/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts +++ b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts @@ -7,6 +7,9 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import { columnExists } from "./helper/helper"; +const TABLE_NAME = "d_b_prebuilt_workspace"; +const COLUMN_NAME = "statusVersion"; + export class PrebuildStatusVersionColumn1649107789640 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) { From 4e02038bc73bce2e83ff8f05dd2053726c41b88b Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 4 Apr 2022 21:48:37 +0000 Subject: [PATCH 6/6] fix --- components/server/ee/src/workspace/workspace-factory.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/components/server/ee/src/workspace/workspace-factory.ts b/components/server/ee/src/workspace/workspace-factory.ts index 602a3cc500397f..f37c1d921d2bad 100644 --- a/components/server/ee/src/workspace/workspace-factory.ts +++ b/components/server/ee/src/workspace/workspace-factory.ts @@ -172,6 +172,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { creationTime: new Date().toISOString(), projectId: ws.projectId, branch, + statusVersion: 0, }); log.debug(