@@ -25,7 +25,7 @@ import { type S3Bucket } from '../s3'
25
25
export class DatalakeImpl implements Datalake {
26
26
constructor (
27
27
private readonly db : BlobDB ,
28
- private readonly buckets : Partial < Record < Location , S3Bucket > > ,
28
+ private readonly buckets : Array < { location : Location , bucket : S3Bucket } > ,
29
29
private readonly options : {
30
30
cacheControl : string
31
31
}
@@ -44,13 +44,12 @@ export class DatalakeImpl implements Datalake {
44
44
}
45
45
46
46
async head ( ctx : MeasureContext , workspace : string , name : string ) : Promise < BlobHead | null > {
47
- const { bucket } = await this . selectStorage ( ctx , workspace )
48
-
49
47
const blob = await this . db . getBlob ( ctx , { workspace, name } )
50
48
if ( blob === null ) {
51
49
return null
52
50
}
53
51
52
+ const { bucket } = await this . selectStorage ( ctx , workspace , blob . location )
54
53
const head = await bucket . head ( ctx , blob . filename )
55
54
if ( head == null ) {
56
55
return null
@@ -72,13 +71,13 @@ export class DatalakeImpl implements Datalake {
72
71
name : string ,
73
72
options : { range ?: string }
74
73
) : Promise < BlobBody | null > {
75
- const { bucket } = await this . selectStorage ( ctx , workspace )
76
-
77
74
const blob = await this . db . getBlob ( ctx , { workspace, name } )
78
75
if ( blob === null ) {
79
76
return null
80
77
}
81
78
79
+ const { bucket } = await this . selectStorage ( ctx , workspace , blob . location )
80
+
82
81
const range = options . range
83
82
const object = await bucket . get ( ctx , blob . filename , { range } )
84
83
if ( object == null ) {
@@ -176,17 +175,17 @@ export class DatalakeImpl implements Datalake {
176
175
await this . db . setParent ( ctx , { workspace, name } , parent !== null ? { workspace, name : parent } : null )
177
176
}
178
177
179
- async selectStorage ( ctx : MeasureContext , workspace : string ) : Promise < BlobStorage > {
180
- const location = this . selectLocation ( workspace )
181
- const bucket = this . buckets [ location ]
178
+ async selectStorage ( ctx : MeasureContext , workspace : string , location ?: Location ) : Promise < BlobStorage > {
179
+ location ??= this . selectLocation ( workspace )
180
+
181
+ const bucket = this . buckets . find ( ( b ) => b . location === location ) ?. bucket
182
182
if ( bucket == null ) {
183
183
throw new Error ( `Unsupported location: ${ location } ` )
184
184
}
185
185
return { location, bucket }
186
186
}
187
187
188
188
selectLocation ( workspace : string ) : Location {
189
- // TODO select location based on workspace
190
- return 'weur'
189
+ return this . buckets [ 0 ] . location
191
190
}
192
191
}
0 commit comments