Skip to content

Commit 8d9c84b

Browse files
authored
UBERF-11178 Migrate datalake workspace id (#9092)
Signed-off-by: Alexander Onnikov <[email protected]>
1 parent 880c302 commit 8d9c84b

File tree

8 files changed

+105
-35
lines changed

8 files changed

+105
-35
lines changed

services/datalake/pod-datalake/src/datalake/db.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ export function escape (value: any): string {
572572
}
573573

574574
function getMigrations (): [string, string][] {
575-
return [migrationV1()]
575+
return [migrationV1(), migrationV2()]
576576
}
577577

578578
function migrationV1 (): [string, string] {
@@ -611,3 +611,22 @@ function migrationV1 (): [string, string] {
611611
`
612612
return ['init_tables_01', sql]
613613
}
614+
615+
function migrationV2 (): [string, string] {
616+
const sql = `
617+
ALTER TABLE blob.meta DROP CONSTRAINT IF EXISTS fk_blob;
618+
619+
UPDATE blob.blob
620+
SET workspace = w.uuid
621+
FROM global_account.workspace w
622+
WHERE workspace = w.data_id;
623+
624+
UPDATE blob.meta
625+
SET workspace = w.uuid
626+
FROM global_account.workspace w
627+
WHERE workspace = w.data_id;
628+
629+
ALTER TABLE blob.meta ADD CONSTRAINT fk_blob_meta FOREIGN KEY (workspace, name) REFERENCES blob.blob (workspace, name);
630+
`
631+
return ['migrate_workspaces_02', sql]
632+
}

services/datalake/pod-datalake/src/server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515

1616
import { Analytics } from '@hcengineering/analytics'
17+
import { getClient } from '@hcengineering/account-client'
1718
import { MeasureContext, Tx, metricsAggregate } from '@hcengineering/core'
1819
import { PlatformQueue, QueueTopic, getCPUInfo, getMemoryInfo } from '@hcengineering/server-core'
1920
import { decodeToken, TokenError } from '@hcengineering/server-token'
@@ -115,6 +116,8 @@ export async function createServer (
115116
queue: PlatformQueue,
116117
config: Config
117118
): Promise<{ app: Express, close: () => void }> {
119+
await ensureAccountReady(ctx, config)
120+
118121
const buckets: Array<{ location: Location, bucket: S3Bucket }> = []
119122
for (const bucket of config.Buckets) {
120123
const location = bucket.location as Location
@@ -348,3 +351,13 @@ export function listen (e: Express, port: number, host?: string): Server {
348351

349352
return server
350353
}
354+
355+
async function ensureAccountReady (ctx: MeasureContext, config: Config): Promise<void> {
356+
const client = getClient(config.AccountsUrl)
357+
try {
358+
await client.getRegionInfo()
359+
} catch (err: any) {
360+
ctx.error('Accounts service not ready', { err })
361+
throw new Error('Accounts service not ready')
362+
}
363+
}

tests/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
STORAGE_CONFIG="datalake|http://datalake:4031"
1+
STORAGE_CONFIG="minio|minio?accessKey=minioadmin&secretKey=minioadmin"
2+
DATALAKE_STORAGE_CONFIG="datalake|http://datalake:4031"
23
BACKUP_STORAGE_CONFIG="minio|minio?accessKey=minioadmin&secretKey=minioadmin"
34
BACKUP_BUCKET_NAME=dev-backups
45

tests/docker-compose.override.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,49 @@ services:
22
account:
33
environment:
44
- DB_URL=${DB_PG_URL}
5+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
56
- PROCEED_V7_MONGO=false
67
transactor:
78
environment:
89
- DB_URL=${DB_PG_URL}
10+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
911
workspace:
1012
environment:
1113
- DB_URL=${DB_PG_URL}
14+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
1215
fulltext:
1316
environment:
1417
- DB_URL=${DB_PG_URL}
18+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
19+
front:
20+
environment:
21+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
22+
- FILES_URL=http://localhost:4031/blob/:workspace/:blobId/:filename
23+
- UPLOAD_URL=http://localhost:4031/upload/form-data/:workspace
24+
- PREVIEW_CONFIG=http://localhost:4031/image/fit=cover,width=:width,height=:height,dpr=:dpr/:workspace/:blobId
25+
collaborator:
26+
environment:
27+
- STORAGE_CONFIG=${DATALAKE_STORAGE_CONFIG}
28+
datalake:
29+
image: hardcoreeng/datalake
30+
depends_on:
31+
minio:
32+
condition: service_healthy
33+
cockroach:
34+
condition: service_started
35+
stats:
36+
condition: service_started
37+
account:
38+
condition: service_started
39+
ports:
40+
- 4031:4031
41+
environment:
42+
- PORT=4031
43+
- SECRET=secret
44+
- ACCOUNTS_URL=http://account:3003
45+
- STATS_URL=http://stats:4901
46+
- STREAM_URL=http://localhost:1081/recording
47+
- DB_URL=${DB_PG_URL}
48+
- BUCKETS=blobs,eu|http://minio:9000?accessKey=minioadmin&secretKey=minioadmin
49+
- QUEUE_CONFIG=${QUEUE_CONFIG}
50+
restart: unless-stopped

tests/docker-compose.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ services:
174174
- SERVER_SECRET=secret
175175
- ACCOUNTS_URL_INTERNAL=http://account:3003
176176
- ACCOUNTS_URL=http://localhost:3003
177-
- FILES_URL=http://localhost:4031/blob/:workspace/:blobId/:filename
178-
- UPLOAD_URL=http://localhost:4031/upload/form-data/:workspace
179-
- PREVIEW_CONFIG=http://localhost:4031/image/fit=cover,width=:width,height=:height,dpr=:dpr/:workspace/:blobId
177+
- UPLOAD_URL=/files
180178
- ELASTIC_URL=http://elastic:9200
181179
- GMAIL_URL=http://localhost:8088
182180
- CALENDAR_URL=http://localhost:8095
@@ -278,28 +276,6 @@ services:
278276
- REKONI_URL=http://rekoni:4007
279277
- ACCOUNTS_URL=http://account:3003
280278
- STATS_URL=http://stats:4901
281-
datalake:
282-
image: hardcoreeng/datalake
283-
depends_on:
284-
minio:
285-
condition: service_healthy
286-
cockroach:
287-
condition: service_started
288-
stats:
289-
condition: service_started
290-
account:
291-
condition: service_started
292-
ports:
293-
- 4031:4031
294-
environment:
295-
- PORT=4031
296-
- SECRET=secret
297-
- ACCOUNTS_URL=http://account:3003
298-
- STATS_URL=http://stats:4901
299-
- STREAM_URL=http://localhost:1081/recording
300-
- DB_URL=${DB_PG_URL}
301-
- BUCKETS=blobs,eu|http://minio:9000?accessKey=minioadmin&secretKey=minioadmin
302-
restart: unless-stopped
303279
stats:
304280
image: hardcoreeng/stats
305281
ports:

tests/tool.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
export MODEL_VERSION=$(node ../common/scripts/show_version.js)
4-
export STORAGE_CONFIG="datalake|http://localhost:4031"
4+
export STORAGE_CONFIG="minio|localhost:9002?accessKey=minioadmin&secretKey=minioadmin"
55
export ACCOUNTS_URL=http://localhost:3003
66
export TRANSACTOR_URL=ws://localhost:3334
77
export ACCOUNT_DB_URL=mongodb://localhost:27018

ws-tests/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
STORAGE_CONFIG="minio|minio?accessKey=minioadmin&secretKey=minioadmin"
1+
STORAGE_CONFIG="datalake|http://huly.local:4031"
22
BACKUP_STORAGE_CONFIG="minio|minio?accessKey=minioadmin&secretKey=minioadmin"
33
BACKUP_BUCKET_NAME=ws-dev-backups
44
DB_URL=mongodb://huly.local:27018
55
MONGO_URL=mongodb://huly.local:27018
6-
DB_EU_URL=postgresql://root@huly.local:26258/defaultdb?sslmode=disable
6+
DB_EU_URL=postgresql://root@cockroach:26257/defaultdb?sslmode=disable
77
QUEUE_CONFIG=redpanda:9093

ws-tests/docker-compose.yaml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ services:
55
extra_hosts:
66
- 'huly.local:host-gateway'
77
environment:
8-
- STREAM_ENDPOINT_URL=s3://huly.local:9000
8+
- STREAM_ENDPOINT_URL=datalake://huly.local:4031
99
- STREAM_INSECURE=true
1010
- STREAM_SERVER_SECRET=secret
11-
- AWS_ACCESS_KEY_ID=minioadmin
12-
- AWS_SECRET_ACCESS_KEY=minioadmin
1311
ports:
1412
- 1081:1080
1513
restart: unless-stopped
@@ -95,11 +93,38 @@ services:
9593
extra_hosts:
9694
- 'huly.local:host-gateway'
9795
expose:
98-
- 9002
99-
- 9003
96+
- 9000
97+
- 9001
10098
ports:
10199
- 9002:9000
102100
- 9003:9001
101+
healthcheck:
102+
test: ['CMD', 'mc', 'ready', 'local']
103+
interval: 5s
104+
retries: 10
105+
datalake:
106+
image: hardcoreeng/datalake
107+
depends_on:
108+
minio:
109+
condition: service_healthy
110+
cockroach:
111+
condition: service_started
112+
stats:
113+
condition: service_started
114+
account:
115+
condition: service_started
116+
ports:
117+
- 4031:4031
118+
environment:
119+
- PORT=4031
120+
- SECRET=secret
121+
- ACCOUNTS_URL=http://account:3003
122+
- STATS_URL=http://stats:4901
123+
- STREAM_URL=http://localhost:1081/recording
124+
- DB_URL=${DB_EU_URL}
125+
- BUCKETS=blobs,eu|http://minio:9000?accessKey=minioadmin&secretKey=minioadmin
126+
- QUEUE_CONFIG=${QUEUE_CONFIG}
127+
restart: unless-stopped
103128
elastic:
104129
image: 'elasticsearch:7.14.2'
105130
expose:

0 commit comments

Comments
 (0)