|
17 | 17 | from kiara.exceptions import KiaraException
|
18 | 18 | from kiara.models.module.jobs import JobRecord
|
19 | 19 | from kiara.models.values.value import (
|
20 |
| - SERIALIZE_TYPES, |
21 | 20 | PersistedData,
|
22 |
| - SerializedChunkIDs, |
23 |
| - SerializedData, |
24 | 21 | Value,
|
25 | 22 | )
|
26 | 23 | from kiara.registries import ArchiveDetails, FileSystemArchiveConfig
|
@@ -398,57 +395,65 @@ def _persist_destiny_backlinks(self, value: Value):
|
398 | 395 |
|
399 | 396 | fix_windows_symlink(value_file, destiny_file)
|
400 | 397 |
|
401 |
| - def _persist_value_data(self, value: Value) -> PersistedData: |
| 398 | + def _persist_chunk(self, chunk_id: str, chunk: Union[str, BytesIO]): |
402 | 399 |
|
403 |
| - serialized_value: SerializedData = value.serialized_data |
| 400 | + addr: HashAddress = self.hashfs.put_with_precomputed_hash(chunk, chunk_id) |
404 | 401 |
|
405 |
| - chunk_id_map = {} |
406 |
| - for key in serialized_value.get_keys(): |
| 402 | + assert addr.id == chunk_id |
| 403 | + # return addr |
| 404 | + # chunk_ids.append(addr.id) |
407 | 405 |
|
408 |
| - data_model = serialized_value.get_serialized_data(key) |
409 |
| - |
410 |
| - if data_model.type == "chunk": # type: ignore |
411 |
| - chunks: Iterable[Union[str, BytesIO]] = [BytesIO(data_model.chunk)] # type: ignore |
412 |
| - elif data_model.type == "chunks": # type: ignore |
413 |
| - chunks = (BytesIO(c) for c in data_model.chunks) # type: ignore |
414 |
| - elif data_model.type == "file": # type: ignore |
415 |
| - chunks = [data_model.file] # type: ignore |
416 |
| - elif data_model.type == "files": # type: ignore |
417 |
| - chunks = data_model.files # type: ignore |
418 |
| - elif data_model.type == "inline-json": # type: ignore |
419 |
| - chunks = [BytesIO(data_model.as_json())] # type: ignore |
420 |
| - else: |
421 |
| - raise Exception( |
422 |
| - f"Invalid serialized data type: {type(data_model)}. Available types: {', '.join(SERIALIZE_TYPES)}" |
423 |
| - ) |
424 |
| - |
425 |
| - chunk_ids = [] |
426 |
| - for item in zip(serialized_value.get_cids_for_key(key), chunks): |
427 |
| - cid = item[0] |
428 |
| - _chunk = item[1] |
429 |
| - addr: HashAddress = self.hashfs.put_with_precomputed_hash( |
430 |
| - _chunk, str(cid) |
431 |
| - ) |
432 |
| - chunk_ids.append(addr.id) |
433 |
| - |
434 |
| - scids = SerializedChunkIDs( |
435 |
| - chunk_id_list=chunk_ids, |
436 |
| - archive_id=self.archive_id, |
437 |
| - size=data_model.get_size(), |
438 |
| - ) |
439 |
| - scids._data_registry = self.kiara_context.data_registry |
440 |
| - chunk_id_map[key] = scids |
441 |
| - |
442 |
| - pers_value = PersistedData( |
443 |
| - archive_id=self.archive_id, |
444 |
| - chunk_id_map=chunk_id_map, |
445 |
| - data_type=serialized_value.data_type, |
446 |
| - data_type_config=serialized_value.data_type_config, |
447 |
| - serialization_profile=serialized_value.serialization_profile, |
448 |
| - metadata=serialized_value.metadata, |
449 |
| - ) |
450 |
| - |
451 |
| - return pers_value |
| 406 | + # def _persist_value_data(self, value: Value) -> PersistedData: |
| 407 | + # |
| 408 | + # serialized_value: SerializedData = value.serialized_data |
| 409 | + # |
| 410 | + # chunk_id_map = {} |
| 411 | + # for key in serialized_value.get_keys(): |
| 412 | + # |
| 413 | + # data_model = serialized_value.get_serialized_data(key) |
| 414 | + # |
| 415 | + # if data_model.type == "chunk": # type: ignore |
| 416 | + # chunks: Iterable[Union[str, BytesIO]] = [BytesIO(data_model.chunk)] # type: ignore |
| 417 | + # elif data_model.type == "chunks": # type: ignore |
| 418 | + # chunks = (BytesIO(c) for c in data_model.chunks) # type: ignore |
| 419 | + # elif data_model.type == "file": # type: ignore |
| 420 | + # chunks = [data_model.file] # type: ignore |
| 421 | + # elif data_model.type == "files": # type: ignore |
| 422 | + # chunks = data_model.files # type: ignore |
| 423 | + # elif data_model.type == "inline-json": # type: ignore |
| 424 | + # chunks = [BytesIO(data_model.as_json())] # type: ignore |
| 425 | + # else: |
| 426 | + # raise Exception( |
| 427 | + # f"Invalid serialized data type: {type(data_model)}. Available types: {', '.join(SERIALIZE_TYPES)}" |
| 428 | + # ) |
| 429 | + # |
| 430 | + # chunk_ids = [] |
| 431 | + # for item in zip(serialized_value.get_cids_for_key(key), chunks): |
| 432 | + # cid = item[0] |
| 433 | + # _chunk = item[1] |
| 434 | + # addr: HashAddress = self.hashfs.put_with_precomputed_hash( |
| 435 | + # _chunk, str(cid) |
| 436 | + # ) |
| 437 | + # chunk_ids.append(addr.id) |
| 438 | + # |
| 439 | + # scids = SerializedChunkIDs( |
| 440 | + # chunk_id_list=chunk_ids, |
| 441 | + # archive_id=self.archive_id, |
| 442 | + # size=data_model.get_size(), |
| 443 | + # ) |
| 444 | + # scids._data_registry = self.kiara_context.data_registry |
| 445 | + # chunk_id_map[key] = scids |
| 446 | + # |
| 447 | + # pers_value = PersistedData( |
| 448 | + # archive_id=self.archive_id, |
| 449 | + # chunk_id_map=chunk_id_map, |
| 450 | + # data_type=serialized_value.data_type, |
| 451 | + # data_type_config=serialized_value.data_type_config, |
| 452 | + # serialization_profile=serialized_value.serialization_profile, |
| 453 | + # metadata=serialized_value.metadata, |
| 454 | + # ) |
| 455 | + # |
| 456 | + # return pers_value |
452 | 457 |
|
453 | 458 | def _persist_value_pedigree(self, value: Value):
|
454 | 459 |
|
|
0 commit comments