Skip to content

Commit 569954e

Browse files
committed
[server] Some cleanup around WorkspaceGarbageCollector
1 parent 12bb47c commit 569954e

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

components/server/src/config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,23 @@ export interface WorkspaceDefaults {
4343
export interface WorkspaceGarbageCollection {
4444
disabled: boolean;
4545
startDate: number;
46+
47+
/** The number of seconds between a run and the next */
48+
intervalSeconds: number;
49+
50+
/** The maximum amount of workspaces that are marked as 'softDeleted' in one go */
4651
chunkLimit: number;
52+
53+
/** The minimal age of a workspace before it is marked as 'softDeleted' (= hidden for the user) */
4754
minAgeDays: number;
55+
56+
/** The minimal age of a prebuild (incl. workspace) before it's content is deleted (+ marked as 'softDeleted') */
4857
minAgePrebuildDays: number;
58+
59+
/** The minimal number of days a workspace has to stay in 'softDeleted' before it's content is deleted */
4960
contentRetentionPeriodDays: number;
61+
62+
/** The maximum amount of workspaces whose content is deleted in one go */
5063
contentChunkLimit: number;
5164
}
5265

components/server/src/workspace/garbage-collector.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export class WorkspaceGarbageCollector {
3434
dispose: () => {},
3535
};
3636
}
37-
return repeat(async () => this.garbageCollectWorkspacesIfLeader(), 30 * 60 * 1000);
37+
return repeat(
38+
async () => this.garbageCollectWorkspacesIfLeader(),
39+
this.config.workspaceGarbageCollection.intervalSeconds * 1000,
40+
);
3841
}
3942

4043
public async garbageCollectWorkspacesIfLeader() {
@@ -128,7 +131,7 @@ export class WorkspaceGarbageCollector {
128131
}
129132
}
130133

131-
// finds volume snapshots that have been superceded by newer volume snapshot and removes them
134+
// finds volume snapshots that have been superseded by newer volume snapshot and removes them
132135
protected async deleteOutdatedVolumeSnapshots() {
133136
const span = opentracing.globalTracer().startSpan("deleteOutdatedVolumeSnapshots");
134137
try {

components/server/src/workspace/gitpod-server-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
11661166
try {
11671167
await this.guardAccess({ kind: "workspace", subject: workspace }, "create");
11681168
} catch (err) {
1169-
await this.workspaceDb.trace(ctx).hardDeleteWorkspace(workspace.id);
1169+
await this.workspaceDeletionService.hardDeleteWorkspace(ctx, workspace.id);
11701170
throw err;
11711171
}
11721172

components/server/src/workspace/workspace-deletion-service.ts

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export class WorkspaceDeletionService {
4646
});
4747
}
4848

49+
/**
50+
* This *hard deletes* the workspace entry and all corresponding workspace-instances, by triggering a db-sync mechanism that purges it from the DB.
51+
* Note: when this function returns that doesn't mean that the entries are actually gone yet, that might still take a short while until db-sync comes
52+
* around to deleting them.
53+
* @param ctx
54+
* @param workspaceId
55+
*/
56+
public async hardDeleteWorkspace(ctx: TraceContext, workspaceId: string): Promise<void> {
57+
await this.db.trace(ctx).hardDeleteWorkspace(workspaceId);
58+
}
59+
4960
/**
5061
* This method garbageCollects a workspace. It deletes its contents and sets the workspaces 'contentDeletedTime'
5162
* @param ctx

install/installer/pkg/components/server/configmap.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
185185
DefinitelyGpDisabled: ctx.Config.DisableDefinitelyGP,
186186
GitHubApp: githubApp,
187187
WorkspaceGarbageCollection: WorkspaceGarbageCollection{
188-
ChunkLimit: 1000,
189-
ContentChunkLimit: 1000,
190-
ContentRetentionPeriodDays: 21,
191188
Disabled: disableWsGarbageCollection,
189+
IntervalSeconds: 1800,
192190
MinAgeDays: 14,
193191
MinAgePrebuildDays: 7,
192+
ChunkLimit: 1000,
193+
ContentRetentionPeriodDays: 21,
194+
ContentChunkLimit: 1000,
194195
},
195196
EnableLocalApp: enableLocalApp,
196197
AuthProviderConfigFiles: func() []string {

install/installer/pkg/components/server/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type IncrementalPrebuilds struct {
9191
type WorkspaceGarbageCollection struct {
9292
Disabled bool `json:"disabled"`
9393
StartDate int32 `json:"startDate"`
94+
IntervalSeconds int32 `json:"intervalSeconds"`
9495
ChunkLimit int32 `json:"chunkLimit"`
9596
MinAgeDays int32 `json:"minAgeDays"`
9697
MinAgePrebuildDays int32 `json:"minAgePrebuildDays"`

0 commit comments

Comments
 (0)