Datablocks
calculate_md5_checksum(filename, chunksize=2 ** 20)
Calculate an md5 hash of a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
Path
|
absolute or relative path to file |
required |
chunksize
|
int
|
default chunk size to calculate hash on. Defaults to 1024*1025. |
2 ** 20
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
hash as str |
Source code in backend/archiver/utils/datablocks.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
copy_file_to_folder(src_file, dst_folder)
Copies a file to a destination folder (does not need to exist)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_file
|
Path
|
Source file |
required |
dst_folder
|
Path
|
destination folder - needs to exist |
required |
Raises:
Type | Description |
---|---|
SystemError
|
raises if operation fails |
Source code in backend/archiver/utils/datablocks.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
create_datablock_entries(dataset_id, folder, origDataBlocks, tar_infos, progress_callback=None)
Create datablock entries compliant with schema provided by scicat
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_id
|
str
|
Dataset identifier |
required |
folder
|
Path
|
description |
required |
origDataBlocks
|
List[OrigDataBlock]
|
description |
required |
tarballs
|
List[Path]
|
description |
required |
Returns:
Type | Description |
---|---|
List[DataBlock]
|
List[DataBlock]: description |
Source code in backend/archiver/utils/datablocks.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
create_tarfiles(dataset_id, src_folder, dst_folder, target_size, progress_callback=None)
Create datablocks, i.e. .tar.gz files, from all files in a folder. Folder structures are kept and symlnks not resolved. The created tar files will be named according to the dataset they belong to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_id
|
str
|
dataset identifier |
required |
src_folder
|
Path
|
source folder to find files to create tars from |
required |
dst_folder
|
Path
|
destination folder to write the tar files to |
required |
target_size
|
int
|
Target size of the tar file. This is the unpacked size of the files. |
required |
Returns:
Type | Description |
---|---|
List[ArchiveInfo]
|
List[Path]: description |
Source code in backend/archiver/utils/datablocks.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
download_object_from_s3(client, bucket, folder, object_name, target_path)
Download an object from S3 storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket
|
Bucket
|
Bucket to look for file |
required |
folder
|
Path
|
s3 prefix for object |
required |
object_name
|
str
|
object name, no prefix |
required |
target_path
|
Path
|
absolute or relative path for the file to be created |
required |
Source code in backend/archiver/utils/datablocks.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
download_objects_from_s3(client, prefix, bucket, destination_folder, progress_callback)
Download objects form s3 storage to folder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
Path
|
S3 prefix |
required |
bucket
|
Bucket
|
s3 bucket |
required |
destination_folder
|
Path
|
Target folder. Will be created if it does not exist. |
required |
Returns:
Type | Description |
---|---|
List[Path]
|
List[Path]: List of paths of created files |
Source code in backend/archiver/utils/datablocks.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
list_datablocks(client, prefix, bucket)
List all objects in s3 bucket and path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
minio_prefix
|
Path
|
prefix for files to be listed |
required |
bucket
|
Bucket
|
s3 bucket |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
List[ListedObject]
|
Iterator to objects |
Source code in backend/archiver/utils/datablocks.py
200 201 202 203 204 205 206 207 208 209 210 211 |
|
partition_files_flat(folder, target_size_bytes)
Partitions files in folder into groups such that all the files in a group combined have a target_size_bytes size at maximum. Folders are not treated recursively
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder
|
Path
|
Folder to partition files in |
required |
target_size_bytes
|
int
|
maximum size of grouped files |
required |
Yields:
Type | Description |
---|---|
List[Path]
|
Generator[List[Path], None, None]: List of paths with maximum size |
Source code in backend/archiver/utils/datablocks.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
sufficient_free_space_on_lts()
Checks for free space on configured LTS storage with respect to configured free space percentage.
Returns:
Name | Type | Description |
---|---|---|
boolean |
condition of eneough free space satisfied |
Source code in backend/archiver/utils/datablocks.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
wait_for_file_accessible(file, timeout_s=360)
async
Returns:
Source code in backend/archiver/utils/datablocks.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
wait_for_free_space()
async
Asynchronous wait until there is enough free space. Waits in linear intervals to check for free space
TODO: add exponential backoff for waiting time
Returns:
Name | Type | Description |
---|---|---|
boolean |
Returns True once there is enough free space |
Source code in backend/archiver/utils/datablocks.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|